Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 5.56 KB | None | 0 0
  1. #
  2. # Copyright 2017, TOTVS S.A.
  3. # All rights reserved.
  4. #
  5.  
  6. #
  7. # Build Specification Reference for Makefile
  8. #
  9. # The main phases are defined by:
  10. #
  11. # "pre_build":
  12. #   In this phase we should execute commands that
  13. #   should precede "build" phase (ex. build some
  14. #   dependencies, install a missing package, ...).
  15. #
  16. # "build":
  17. #   In this phase we should execute commands that
  18. #   should build some package or generate some
  19. #   artifact (ex. mvn commands, npm commands, ...).
  20. #
  21. # "post_build":
  22. #   In this phase we should execute commands that
  23. #   should come after the "build" phase, like a
  24. #   deployment spec that CI/CD tool will execute.
  25. #
  26. # Our CI/CD tool will read/execute this file in the
  27. # stages below as the following order:
  28. #
  29. # "Build":
  30. #   $ make pre_build
  31. #   $ make build
  32. #   $ make post_build
  33. #
  34.  
  35. #
  36. # Default rules/targets (please don't change their names)
  37. # Environment variables are also defined here
  38. #
  39.  
  40. # defaul shell
  41. SHELL = /bin/bash
  42. # ensure that java path is configured
  43. JAVA_HOME ?= /usr/lib/jvm/java-8-oracle
  44. # repository storage
  45. REPOSITORY ?= repository.fluig.com
  46. # image name
  47. IMAGE = platform/lms
  48. # if version is not defined, use commit hash as version
  49. VERSION ?= $(shell git rev-parse --short=7 HEAD)
  50. # repository docker fluig
  51. GIT_IMAGE ?= docker.fluig.com/fluig/git
  52.  
  53. .PHONY: pre_build
  54. .SILENT: pre_build
  55. pre_build:
  56.     # produce a failure return code if any command return error \
  57.     set -eo pipefail; \
  58.  
  59. .PHONY: build-dev
  60. .SILENT: build-dev
  61. build-dev: maven.build-dev docker.artifacts docker.image docker.push
  62.  
  63. .PHONY: build
  64. .SILENT: build
  65. build: maven.build docker.artifacts docker.image docker.push
  66.  
  67. .PHONY: post_build
  68. .SILENT: post_build
  69. post_build:
  70.     # produce a failure return code if any command return error \
  71.     set -eo pipefail; \
  72.  
  73. #
  74. # Your custom rules/targets
  75. #
  76.  
  77. .PHONY: maven.build
  78. .SILENT: maven.build
  79. maven.build:
  80.     # produce a failure return code if any command return error \
  81.     set -eo pipefail; \
  82.  
  83.     # get current branch \
  84.     localBranch=$(shell git rev-parse --abbrev-ref HEAD); \
  85.    
  86.     # maven goals for custom branchs \
  87.     declare -a branchs=( \
  88.         "master:deploy" \
  89.     ); \
  90.     for b in $${branchs[@]}; do \
  91.         if [ $$localBranch = $${b%:*} ]; then \
  92.             mvnGoal=$${b#*:}; \
  93.             break; \
  94.         else \
  95.             mvnGoal="install"; fi; \
  96.     done; \
  97.     mvn clean $$mvnGoal -f pom.xml; \
  98.  
  99.  
  100. .PHONY: maven.build-dev
  101. .SILENT: maven.build-dev
  102. maven.build-dev:
  103.     # produce a failure return code if any command return error \
  104.     set -eo pipefail; \
  105.  
  106.     # get current branch \
  107.     localBranch=$(shell git rev-parse --abbrev-ref HEAD); \
  108.    
  109.     # maven goals for custom branchs \
  110.     declare -a branchs=( \
  111.         "master:deploy" \
  112.     ); \
  113.     for b in $${branchs[@]}; do \
  114.         if [ $$localBranch = $${b%:*} ]; then \
  115.             mvnGoal=$${b#*:}; \
  116.             break; \
  117.         else \
  118.             mvnGoal="install"; fi; \
  119.     done; \
  120.     mvn clean $$mvnGoal -f pom.xml -DskipTests; \
  121.  
  122. .PHONY: artifacts.generate
  123. .SILENT: artifacts.generate
  124. artifacts.generate:
  125.     # produce a failure return code if any command return error \
  126.     set -eo pipefail; \
  127.    
  128.     # root of git repository \
  129.     rootRepo=$(shell git rev-parse --show-toplevel); \
  130.    
  131.     # set and create version folder for sync with s3 \
  132.     artifactsFolder=$(shell git rev-parse --show-toplevel)/artifacts; \
  133.     $(MAKE) -s artifacts.clean; \
  134.    
  135.     # library artifacts variables \
  136.     declare -a libraries=( \
  137.         "$$rootRepo/elearning-web/target/elearning-web.war:standalone/deployments" \
  138.         "$$rootRepo/elearning-migration/target/lms-migration.jar:migration" \
  139.     ); \
  140.    
  141.     # configuration artifacts variables \
  142.     declare -a configurations=( \
  143.         "$$rootRepo/env/lms/standalone.xml:standalone/configuration" \
  144.         "$$rootRepo/env/mariadb/module.xml:modules/org/mariadb/jdbc/main" \
  145.     ); \
  146.    
  147.     # copy all library artifacts for lms \
  148.     for a in $${libraries[@]}; do \
  149.         mkdir -p $$artifactsFolder/$${a#*:}; \
  150.         echo "cp"; \
  151.         cp $${a%:*} $$artifactsFolder/$${a#*:}; \
  152.         echo "cp ok"; \
  153.     done;
  154.    
  155.     # copy all configuration artifacts for lms \
  156.     for c in $${configurations[@]}; do \
  157.         mkdir -p $$artifactsFolder/$${c#*:}; \
  158.         cp $${c%:*} $$artifactsFolder/$${c#*:}; \
  159.     done; \
  160.    
  161.     # generate sha256 only to configurations and libraries \
  162.     cd $$artifactsFolder; \
  163.     for f in $$(find $$artifactsFolder -type f); do \
  164.         sha256sum $$f | awk '{ print $$1 }' > $$f.sha256;
  165.     done; \
  166.  
  167. .PHONY: artifacts.clean
  168. .SILENT: artifacts.clean
  169. artifacts.clean:
  170.     # produce a failure return code if any command return error \
  171.     set -eo pipefail; \
  172.     # set and create artifacts folder \
  173.     artifactsFolder=$(shell git rev-parse --show-toplevel)/artifacts; \
  174.     # remove artifacts folder if exist \
  175.     if test -d $$artifactsFolder; then \
  176.         rm -rf $$artifactsFolder; \
  177.         mkdir -p $$artifactsFolder; \
  178.     fi;
  179.  
  180. .PHONY: docker.artifacts
  181. .SILENT: docker.artifacts
  182. docker.artifacts:
  183.     # produce a failure return code if any command return error \
  184.     set -eo pipefail; \
  185.  
  186.     # execute artifacts generate with docker \
  187.     docker run \
  188.         --rm \
  189.         --privileged \
  190.         -w="/app" \
  191.         -v ${rootRepo}:/app \
  192.         -it ${GIT_IMAGE} \
  193.         make artifacts.generate;\
  194.  
  195. .PHONY: docker.image
  196. .SILENT: docker.image
  197. docker.image:
  198.     # generate docker image \
  199.     make -C $$rootRepo/docker build \
  200.         -e REPOSITORY="repository.fluig.com" \
  201.         -e IMAGE="${IMAGE}"; \
  202.    
  203. .PHONY: docker.push
  204. .SILENT: docker.push
  205. docker.push:
  206.     # push docker image \
  207.     make -C $$rootRepo/docker push \
  208.         -e REPOSITORY="repository.fluig.com" \
  209.         -e IMAGE="${IMAGE}"; \
  210.  
  211.     echo -e "\nDocker images were successfully created!\n"; \
  212.     echo -e "Please use the commands below to pull them:\n"; \
  213.     echo -e "docker pull docker.fluig.com/${IMAGE}:${VERSION}"; \
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement