-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (115 loc) · 6.49 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
#======================================================================
#
# example 'make init'
# example 'make package SKIP_TEST=true ENV=dev'
#
# author: chenlong
# date: 2020-09-27
#======================================================================
SHELL := /bin/bash -o pipefail
export BASE_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
# ----------------------------- variables <-----------------------------
# unit test flag
SKIP_TEST ?= false
# env
ENV ?= local
# ----------------------------- variables >-----------------------------
# ----------------------------- app.properties <-----------------------------
# app name
APPLICATION_NAME := $(shell grep "app.name" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //')
# jar name
APPLICATION_JAR := $(shell grep "app.name" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //')-$(shell grep "app.version" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //').jar
# port
APPLICATION_PORT := $(shell grep "app.port" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //')
# docker.repository.name
DOCKER_REPOSITORY_NAME := $(shell grep "docker.repository.name" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //')
# docker image name
DOCKER_IMAGE_NAME := $(shell grep "docker.image.name" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //')
# docker image tag
DOCKER_IMAGE_TAG := $(shell grep "docker.image.tag" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //')
# docker container name
DOCKER_CONTAINER_NAME := $(shell grep "docker.container.name" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //')
# helm namespace
HELM_NAMESPACE := $(shell grep "helm.namespace" $(BASE_PATH)/config/app.properties | cut -d'=' -f2| sed 's/\ //')
# ----------------------------- app.properties >-----------------------------
# ----------------------------- maven <-----------------------------
#
clean:
$(BASE_PATH)/mvnw --batch-mode --errors -f ${BASE_PATH}/pom.xml clean
#
test:
$(BASE_PATH)/mvnw --batch-mode --errors --fail-at-end --update-snapshots -f ${BASE_PATH}/pom.xml clean test -D test=*Test -DfailIfNoTests=false
#
package:
@cat ${BASE_PATH}/deploy/deploy/debugger.sh | \
sed 's/APPLICATION=[^<]*/APPLICATION=${APPLICATION_NAME}/1' | \
sed 's/APPLICATION_JAR=[^<]*/APPLICATION_JAR=${APPLICATION_JAR}/1' \
> ${BASE_PATH}/deploy/deploy/debugger.sh.newVersion && mv ${BASE_PATH}/deploy/deploy/debugger.sh.newVersion ${BASE_PATH}/deploy/deploy/debugger.sh
@cat ${BASE_PATH}/deploy/deploy/startup.sh | \
sed 's/APPLICATION=[^<]*/APPLICATION=${APPLICATION_NAME}/1' | \
sed 's/APPLICATION_JAR=[^<]*/APPLICATION_JAR=${APPLICATION_JAR}/1' \
> ${BASE_PATH}/deploy/deploy/startup.sh.newVersion && mv ${BASE_PATH}/deploy/deploy/startup.sh.newVersion ${BASE_PATH}/deploy/deploy/startup.sh
@cat ${BASE_PATH}/deploy/deploy/shutdown.sh | \
sed 's/APPLICATION=[^<]*/APPLICATION=${APPLICATION_NAME}/1' | \
sed 's/APPLICATION_JAR=[^<]*/APPLICATION_JAR=${APPLICATION_JAR}/1' \
> ${BASE_PATH}/deploy/deploy/shutdown.sh.newVersion && mv ${BASE_PATH}/deploy/deploy/shutdown.sh.newVersion ${BASE_PATH}/deploy/deploy/shutdown.sh
@cat ${BASE_PATH}/deploy/deploy/restart.sh | \
sed 's/APPLICATION=[^<]*/APPLICATION=${APPLICATION_NAME}/1' | \
sed 's/APPLICATION_JAR=[^<]*/APPLICATION_JAR=${APPLICATION_JAR}/1' \
> ${BASE_PATH}/deploy/deploy/restart.sh.newVersion && mv ${BASE_PATH}/deploy/deploy/restart.sh.newVersion ${BASE_PATH}/deploy/deploy/restart.sh
$(BASE_PATH)/mvnw --batch-mode --errors --fail-at-end --update-snapshots -f ${BASE_PATH}/pom.xml clean package -P ${ENV} -D maven.test.skip=$(SKIP_TEST)
#
package.uncompress: package
mkdir -p ${BASE_PATH}/target/app
tar -zxvf ${BASE_PATH}/target/*.tar.gz -C ${BASE_PATH}/target/app --strip-components 1
# ----------------------------- maven >-----------------------------
# ----------------------------- docker <-----------------------------
docker.init:
@cat ${BASE_PATH}/deploy/bin/docker/stop.sh | \
sed 's#DOCKER_CONTAINER_NAME=[^<]*#DOCKER_CONTAINER_NAME=${DOCKER_CONTAINER_NAME}#1' | \
sed 's#PROFILE=[^<]*#PROFILE=${ENV}#1' \
> ${BASE_PATH}/deploy/bin/docker/stop.sh.newVersion && \
mv ${BASE_PATH}/deploy/bin/docker/stop.sh.newVersion ${BASE_PATH}/deploy/bin/docker/stop.sh
@cat ${BASE_PATH}/deploy/bin/docker/remove.sh | \
sed 's#DOCKER_CONTAINER_NAME=[^<]*#DOCKER_CONTAINER_NAME=${DOCKER_CONTAINER_NAME}#1' | \
sed 's#PROFILE=[^<]*#PROFILE=${ENV}#1' \
> ${BASE_PATH}/deploy/bin/docker/remove.sh.newVersion && \
mv ${BASE_PATH}/deploy/bin/docker/remove.sh.newVersion ${BASE_PATH}/deploy/bin/docker/remove.sh
@cat ${BASE_PATH}/deploy/bin/docker/run.sh | \
sed 's#DOCKER_REPOSITORY_NAME=[^<]*#DOCKER_REPOSITORY_NAME=${DOCKER_REPOSITORY_NAME}#1' | \
sed 's#DOCKER_IMAGE_NAME=[^<]*#DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME}#1' | \
sed 's#DOCKER_IMAGE_TAG=[^<]*#DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}#1' | \
sed 's#DOCKER_CONTAINER_NAME=[^<]*#DOCKER_CONTAINER_NAME=${DOCKER_CONTAINER_NAME}#1' | \
sed 's#APPLICATION_PORT=[^<]*#APPLICATION_PORT=${APPLICATION_PORT}#1' | \
sed 's#PROFILE=[^<]*#PROFILE=${ENV}#1' \
> ${BASE_PATH}/deploy/bin/docker/run.sh.newVersion && \
mv ${BASE_PATH}/deploy/bin/docker/run.sh.newVersion ${BASE_PATH}/deploy/bin/docker/run.sh
#
docker.build: docker.init
sh ${BASE_PATH}/deploy/bin/docker/build.sh $(DOCKER_REPOSITORY_NAME) $(DOCKER_IMAGE_NAME) $(DOCKER_IMAGE_TAG) $(ENV)
#
docker.push:
sh ${BASE_PATH}/deploy/bin/docker/push.sh $(DOCKER_REPOSITORY_NAME) $(DOCKER_IMAGE_NAME) $(DOCKER_IMAGE_TAG) $(ENV)
#
docker.run:
sh ${BASE_PATH}/deploy/bin/docker/run.sh $(DOCKER_REPOSITORY_NAME) $(DOCKER_IMAGE_NAME) $(DOCKER_IMAGE_TAG) $(DOCKER_CONTAINER_NAME) $(ENV)
# docker logs -f $(DOCKER_CONTAINER_NAME)-$(ENV)
#
docker.stop:
sh ${BASE_PATH}/deploy/bin/docker/stop.sh $(DOCKER_CONTAINER_NAME) $(ENV)
#
docker.remove:
sh ${BASE_PATH}/deploy/bin/docker/remove.sh $(DOCKER_CONTAINER_NAME) $(ENV)
#
docker.clear:
docker rm -f $(docker ps -a | grep $(DOCKER_CONTAINER_NAME) | grep -v grep | awk '{ print $1 }')
docker rmi -f $(docker images | grep $(DOCKER_CONTAINER_NAME) | grep -v grep | awk '{ print $3 }')
# ----------------------------- docker >-----------------------------
# ----------------------------- helm <-----------------------------
#
helm.uninstall:
sh ${BASE_PATH}/deploy/bin/helm/uninstall.sh $(APPLICATION_NAME) $(HELM_NAMESPACE) $(ENV)
#
helm.upgrade:
sh ${BASE_PATH}/deploy/bin/helm/install.sh $(APPLICATION_NAME) $(HELM_NAMESPACE) $(ENV)
# ----------------------------- helm >-----------------------------