-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·246 lines (189 loc) · 3.92 KB
/
build.sh
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
CMD=$1
RUNNER=
USERNAME="admin"
REPONAME="$(basename ${PWD})"
REGISTRY="${REPONAME}"
if [ "${GITLAB_USER_ID}" != "" ]; then
# gitlab
RUNNER="gitlab"
USERNAME=${GITLAB_USER_ID:-$USERNAME}
REPONAME=${CI_PROJECT_NAME:-$REPONAME}
REGISTRY="${REPONAME}"
fi
# default port
PORT=8080
command -v tput > /dev/null && TPUT=true
_echo() {
if [ "${TPUT}" != "" ] && [ "$2" != "" ]; then
echo -e "$(tput setaf $2)$1$(tput sgr0)"
else
echo -e "$1"
fi
}
_result() {
echo
_echo "# $@" 4
}
_command() {
echo
_echo "$ $@" 3
}
_success() {
echo
_echo "+ $@" 2
exit 0
}
_error() {
echo
_echo "- $@" 1
exit 1
}
get_version() {
if [ -f ./target/VERSION ]; then
VERSION=$(cat ./target/VERSION | xargs)
elif [ -f ./VERSION ]; then
VERSION=$(cat ./VERSION | xargs)
fi
_result "VERSION=${VERSION}"
}
npm_build() {
_command "npm run build"
npm run build
}
npm_start() {
_command "npm run start"
npm run start
}
npm_clean() {
_command "npm run clean"
npm run clean
}
mvn_clean() {
_command "mvn clean"
mvn clean
}
mvn_build() {
get_version
if [ "${VERSION}" == "" ]; then
_command "mvn package"
mvn package
else
_command "mvn package -Dcurrent.version=${VERSION}"
mvn package -Dcurrent.version=${VERSION}
fi
# jmx
if [ -f jmx/config.yaml ]; then
mkdir -p target/jmx
cp jmx/config.yaml target/jmx/config.yaml
cp jmx/jmx_* target/jmx/jmx_javaagent.jar
fi
}
chart_build() {
get_version
pushd charts/${REPONAME}
sed -i -e \"s/name: .*/name: ${REPONAME}/\" Chart.yaml
sed -i -e \"s/appVersion: .*/appVersion: ${VERSION}/\" Chart.yaml
sed -i -e \"s/version: .*/version: ${VERSION}/\" Chart.yaml
sed -i -e \"s/tag: .*/tag: ${VERSION}/g\" values.yaml
sed -i -e \"s|repository: .*|repository: ${REGISTRY}|\" values.yaml
helm lint .
helm push . chartmuseum
popd
}
chart_push() {
get_version
}
docker_ps() {
_command "docker ps -a"
docker ps -a
}
docker_build() {
get_version
_command "docker build -t ${REGISTRY}:${VERSION} ."
docker build -t ${REGISTRY}:${VERSION} .
}
docker_push() {
get_version
_command "docker push ${REGISTRY}:${VERSION}"
docker push ${REGISTRY}:${VERSION}
}
docker_run() {
get_version
_command "docker run --name ${REPONAME} -p ${PORT}:${PORT} -d ${REGISTRY}:${VERSION}"
docker run --name ${REPONAME} -p ${PORT}:${PORT} -d ${REGISTRY}:${VERSION}
docker_ps
_result "http://localhost:${PORT}"
}
docker_stop() {
docker_ps
CNT="$(docker ps -a | grep ${REPONAME} | wc -l | xargs)"
if [ "x${CNT}" != "x0" ]; then
_command "docker stop ${REPONAME}"
docker stop ${REPONAME}
_command "docker rm ${REPONAME}"
docker rm ${REPONAME}
docker_ps
fi
}
_clean() {
# npm
if [ -f ./package.json ]; then
npm_clean
fi
# mvn
if [ -f ./pom.xml ]; then
mvn_clean
fi
}
_build() {
mkdir -p target
# npm
if [ -f ./package.json ]; then
npm_build
fi
# mvn
if [ -f ./pom.xml ]; then
mvn_build
fi
# entrypoint.sh
if [ -f ./entrypoint.sh ]; then
cp ./entrypoint.sh target/entrypoint.sh
fi
}
_bump() {
date > DATE
mkdir build
echo "bump new version" > build/commit_message.txt
}
_run() {
case ${CMD} in
clean)
_clean
docker_stop
;;
start)
docker_stop
docker_build
docker_run
;;
stop)
docker_stop
;;
docker)
docker_build
docker_push
;;
chart)
chart_build
chart_push
;;
bump)
_bump
;;
*)
_build
esac
}
_run
_success