-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
147 lines (124 loc) · 4.62 KB
/
Makefile
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
.PHONY: default test help
default: help
PROJECT_VERSION := $(shell mvn help:evaluate -q -DforceStdout -D"expression=project.version")
PROJECT_NAME=timesched
PROJECT_DOCKER_REPOSITORY=fredpena/${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} .
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} .
else
@docker buildx build --platform linux/amd64 -o type=docker -t ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION} .
endif
## Clean docker image
clean:
@echo '${GREEN}Clean docker image ${RESET}'$(PROJECT_NAME)
docker-compose down -v
docker-compose up -d
restart: clean
@echo '${GREEN}Restart docker image ${RESET}'$(PROJECT_NAME)
ifeq ($(OS),Windows_NT)
@.\mvnw.cmd
else
@./mvnw
endif
start : restart
restart-with-backup: clean
@echo '${GREEN}Restart docker image with backup ${RESET}'$(PROJECT_NAME)
@echo '${GREEN}Waiting for docker ${RESET}'$(PROJECT_NAME)
$(shell sleep 1)
@docker-compose exec -T postgres psql -U postgres -d barcamp < $(shell pwd)/backup/backup.sql
ifeq ($(OS),Windows_NT)
@.\mvnw.cmd
else
@./mvnw
endif
#ifeq ($(OS),Windows_NT)
# @echo '${YELLOW}OS:${RESET}'$(OS)
# @.\mvnw.cmd clean install
#else
# @echo '${YELLOW}OS: ${RESET}'$(shell uname)
# @./mvnw clean install
#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}
## 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}
## Create Release Tags version
create-release: build-image
@echo Creating Release ${COMMIT} ${PROJECT_VERSION}
@docker tag ${PROJECT_DOCKER_REPOSITORY} ${PROJECT_DOCKER_REPOSITORY}:${COMMIT}
@docker tag ${PROJECT_DOCKER_REPOSITORY} ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION}
@#docker tag ${PROJECT_DOCKER_REPOSITORY} ${PROJECT_DOCKER_REPOSITORY}:${LATEST}
@docker push ${PROJECT_DOCKER_REPOSITORY}
# @docker push ${PROJECT_DOCKER_REPOSITORY}:${COMMIT}
@docker push ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION}
## Create Release Tags version
create-release-amd64: build-image-amd64
@echo Creating Release ${COMMIT} ${PROJECT_VERSION}
@#docker tag ${PROJECT_DOCKER_REPOSITORY} ${PROJECT_DOCKER_REPOSITORY}:${COMMIT}
@#docker tag ${PROJECT_DOCKER_REPOSITORY} ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION}
@#docker tag ${PROJECT_DOCKER_REPOSITORY} ${PROJECT_DOCKER_REPOSITORY}:${LATEST}
@#docker push ${PROJECT_DOCKER_REPOSITORY}
@#docker push ${PROJECT_DOCKER_REPOSITORY}:${COMMIT}
@docker push ${PROJECT_DOCKER_REPOSITORY}:${PROJECT_VERSION}