-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (88 loc) · 3.41 KB
/
Copy pathMakefile
File metadata and controls
106 lines (88 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
.PHONY: default test help
default: help
PROJECT_VERSION := $(shell mvn help:evaluate -q -DforceStdout -D"expression=project.version")
PROJECT_NAME=$(shell mvn help:evaluate -q -DforceStdout -D"expression=project.name")
PROJECT_DOCKER_REPOSITORY=alphnology/${PROJECT_NAME}
LATEST=latest
COMMIT := $(shell git rev-parse --short HEAD)
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM=20
# Show this help.
help:
@echo ''
@echo ' ${YELLOW}Project ${GREEN}${PROJECT_NAME}${RESET}'
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
## Clean and build
PROJECT_DEPENDENCY=dependency:go-offline -Pproduction
PROJECT_CLEAN_PACKAGE=clean package -DskipTests -Pproduction
build:
@echo '${GREEN}Building the project: ${RESET}'$(PROJECT_NAME)
ifeq ($(OS),Windows_NT)
@echo '${YELLOW}OS:${RESET}'$(OS)
@.\mvnw.cmd ${PROJECT_DEPENDENCY}
@.\mvnw.cmd ${PROJECT_CLEAN_PACKAGE}
else
@echo '${YELLOW}OS: ${RESET}'$(shell uname)
@./mvnw ${PROJECT_DEPENDENCY}
@./mvnw ${PROJECT_CLEAN_PACKAGE}
endif
## Create the docker image
image:
@echo '${GREEN}building ${RESET}'$(PROJECT_NAME)
@echo '${GREEN}PROJECT_DOCKER_REPOSITORY ${RESET}'$(PROJECT_DOCKER_REPOSITORY):$(PROJECT_VERSION)
@docker build -t ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION} -t ${PROJECT_DOCKER_REPOSITORY}:${LATEST} -t ${PROJECT_DOCKER_REPOSITORY} .
image-amd64:
@echo '${GREEN}building ${RESET}'$(PROJECT_NAME)
@echo '${GREEN}PROJECT_DOCKER_REPOSITORY ${RESET}'$(PROJECT_DOCKER_REPOSITORY):$(PROJECT_VERSION)
ifeq ($(OS),Windows_NT)
@docker build -t ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION} -t ${PROJECT_DOCKER_REPOSITORY}:${LATEST} -t ${PROJECT_DOCKER_REPOSITORY} .
else
@docker buildx build --platform linux/amd64 -o type=docker -t ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION} -t ${PROJECT_DOCKER_REPOSITORY}:${LATEST} -t ${PROJECT_DOCKER_REPOSITORY} .
endif
## Clean docker image
clean:
@echo '${GREEN}Clean docker image ${RESET}'$(PROJECT_NAME)
docker compose down -v
docker compose up -d
ifeq ($(OS),Windows_NT)
@.\mvnw.cmd
else
@./mvnw
endif
## start full docker app (Using flyway)
start-app:
@echo "Starting app (Using flyway)"
@docker compose up -d
@docker compose -f docker-compose-app.yml up -d
## Create the docker image [build, image]
build-image: build image
build-image-amd64: build image-amd64
## Push images to dockerhub
build-push-image: build-image
@echo Pushing image to ECR
@echo '${GREEN}PROJECT_DOCKER_REPOSITORY ${RESET}'$(PROJECT_DOCKER_REPOSITORY):${PROJECT_VERSION}
@docker push ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION}
@docker push ${PROJECT_DOCKER_REPOSITORY}:${LATEST}
## Push images to dockerhub
build-push-image-amd64: build-image-amd64
@echo Pushing image to ECR
@echo '${GREEN}PROJECT_DOCKER_REPOSITORY ${RESET}'$(PROJECT_DOCKER_REPOSITORY):${PROJECT_VERSION}
@docker push ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION}
@docker push ${PROJECT_DOCKER_REPOSITORY}:${LATEST}