Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Copyright 2017, TOTVS S.A.
- # All rights reserved.
- #
- #
- # Build Specification Reference for Makefile
- #
- # The main phases are defined by:
- #
- # "pre_build":
- # In this phase we should execute commands that
- # should precede "build" phase (ex. build some
- # dependencies, install a missing package, ...).
- #
- # "build":
- # In this phase we should execute commands that
- # should build some package or generate some
- # artifact (ex. mvn commands, npm commands, ...).
- #
- # "post_build":
- # In this phase we should execute commands that
- # should come after the "build" phase, like a
- # deployment spec that CI/CD tool will execute.
- #
- # Our CI/CD tool will read/execute this file in the
- # stages below as the following order:
- #
- # "Build":
- # $ make pre_build
- # $ make build
- # $ make post_build
- #
- #
- # Default rules/targets (please don't change their names)
- # Environment variables are also defined here
- #
- # defaul shell
- SHELL = /bin/bash
- # ensure that java path is configured
- JAVA_HOME ?= /usr/lib/jvm/java-8-oracle
- # repository storage
- REPOSITORY ?= repository.fluig.com
- # image name
- IMAGE = platform/lms
- # if version is not defined, use commit hash as version
- VERSION ?= $(shell git rev-parse --short=7 HEAD)
- # repository docker fluig
- GIT_IMAGE ?= docker.fluig.com/fluig/git
- .PHONY: pre_build
- .SILENT: pre_build
- pre_build:
- # produce a failure return code if any command return error \
- set -eo pipefail; \
- .PHONY: build-dev
- .SILENT: build-dev
- build-dev: maven.build-dev docker.artifacts docker.image docker.push
- .PHONY: build
- .SILENT: build
- build: maven.build docker.artifacts docker.image docker.push
- .PHONY: post_build
- .SILENT: post_build
- post_build:
- # produce a failure return code if any command return error \
- set -eo pipefail; \
- #
- # Your custom rules/targets
- #
- .PHONY: maven.build
- .SILENT: maven.build
- maven.build:
- # produce a failure return code if any command return error \
- set -eo pipefail; \
- # get current branch \
- localBranch=$(shell git rev-parse --abbrev-ref HEAD); \
- # maven goals for custom branchs \
- declare -a branchs=( \
- "master:deploy" \
- ); \
- for b in $${branchs[@]}; do \
- if [ $$localBranch = $${b%:*} ]; then \
- mvnGoal=$${b#*:}; \
- break; \
- else \
- mvnGoal="install"; fi; \
- done; \
- mvn clean $$mvnGoal -f pom.xml; \
- .PHONY: maven.build-dev
- .SILENT: maven.build-dev
- maven.build-dev:
- # produce a failure return code if any command return error \
- set -eo pipefail; \
- # get current branch \
- localBranch=$(shell git rev-parse --abbrev-ref HEAD); \
- # maven goals for custom branchs \
- declare -a branchs=( \
- "master:deploy" \
- ); \
- for b in $${branchs[@]}; do \
- if [ $$localBranch = $${b%:*} ]; then \
- mvnGoal=$${b#*:}; \
- break; \
- else \
- mvnGoal="install"; fi; \
- done; \
- mvn clean $$mvnGoal -f pom.xml -DskipTests; \
- .PHONY: artifacts.generate
- .SILENT: artifacts.generate
- artifacts.generate:
- # produce a failure return code if any command return error \
- set -eo pipefail; \
- # root of git repository \
- rootRepo=$(shell git rev-parse --show-toplevel); \
- # set and create version folder for sync with s3 \
- artifactsFolder=$(shell git rev-parse --show-toplevel)/artifacts; \
- $(MAKE) -s artifacts.clean; \
- # library artifacts variables \
- declare -a libraries=( \
- "$$rootRepo/elearning-web/target/elearning-web.war:standalone/deployments" \
- "$$rootRepo/elearning-migration/target/lms-migration.jar:migration" \
- ); \
- # configuration artifacts variables \
- declare -a configurations=( \
- "$$rootRepo/env/lms/standalone.xml:standalone/configuration" \
- "$$rootRepo/env/mariadb/module.xml:modules/org/mariadb/jdbc/main" \
- ); \
- # copy all library artifacts for lms \
- for a in $${libraries[@]}; do \
- mkdir -p $$artifactsFolder/$${a#*:}; \
- echo "cp"; \
- cp $${a%:*} $$artifactsFolder/$${a#*:}; \
- echo "cp ok"; \
- done;
- # copy all configuration artifacts for lms \
- for c in $${configurations[@]}; do \
- mkdir -p $$artifactsFolder/$${c#*:}; \
- cp $${c%:*} $$artifactsFolder/$${c#*:}; \
- done; \
- # generate sha256 only to configurations and libraries \
- cd $$artifactsFolder; \
- for f in $$(find $$artifactsFolder -type f); do \
- sha256sum $$f | awk '{ print $$1 }' > $$f.sha256;
- done; \
- .PHONY: artifacts.clean
- .SILENT: artifacts.clean
- artifacts.clean:
- # produce a failure return code if any command return error \
- set -eo pipefail; \
- # set and create artifacts folder \
- artifactsFolder=$(shell git rev-parse --show-toplevel)/artifacts; \
- # remove artifacts folder if exist \
- if test -d $$artifactsFolder; then \
- rm -rf $$artifactsFolder; \
- mkdir -p $$artifactsFolder; \
- fi;
- .PHONY: docker.artifacts
- .SILENT: docker.artifacts
- docker.artifacts:
- # produce a failure return code if any command return error \
- set -eo pipefail; \
- # execute artifacts generate with docker \
- docker run \
- --rm \
- --privileged \
- -w="/app" \
- -v ${rootRepo}:/app \
- -it ${GIT_IMAGE} \
- make artifacts.generate;\
- .PHONY: docker.image
- .SILENT: docker.image
- docker.image:
- # generate docker image \
- make -C $$rootRepo/docker build \
- -e REPOSITORY="repository.fluig.com" \
- -e IMAGE="${IMAGE}"; \
- .PHONY: docker.push
- .SILENT: docker.push
- docker.push:
- # push docker image \
- make -C $$rootRepo/docker push \
- -e REPOSITORY="repository.fluig.com" \
- -e IMAGE="${IMAGE}"; \
- echo -e "\nDocker images were successfully created!\n"; \
- echo -e "Please use the commands below to pull them:\n"; \
- echo -e "docker pull docker.fluig.com/${IMAGE}:${VERSION}"; \
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement