-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp-docker-runtime-alpine
More file actions
executable file
·340 lines (307 loc) · 10.2 KB
/
temp-docker-runtime-alpine
File metadata and controls
executable file
·340 lines (307 loc) · 10.2 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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/env bash
temple_version='0.14.4'
new_version_for_dev='1.0.0'
#temple url
temple_url="https://github.com/bridgewwater/template-docker-runtime-alpine.git"
temple_repo_host="github.com"
temple_group="bridgewwater"
temple_name="template-docker-runtime-alpine"
temple_branch="v${temple_version}"
temple_hub_user="template-hub-user"
new_repo_host=${temple_repo_host}
new_repo_group=${temple_group}
new_project=
shell_run_name=$(basename $0)
shell_run_path=$(
cd $(dirname $0)
pwd
)
function Usage() {
cat <<HELP
${shell_run_name} can use fast init docker runtime project with github template
now template url is: ${temple_url}
now template version: ${temple_branch}
default repo setting
group/user: ${temple_group}
repo host : ${temple_repo_host}
Usage: ${shell_run_name} [newproject] [new group/user] [new host] [new hub user]
Example:
${shell_run_name} docker-new-runtime
${shell_run_name} docker-new-runtime sinlov github.com sinlov
HELP
}
ARG=$1
if [[ $# -eq 1 ]]; then
if [[ "$ARG" =~ "-h" ]]; then
Usage
exit 0
fi
fi
# log debug enable 1 open 0 close
LOG_DEBUG_ENABLE=1
# log color enable 1 open 0 close
LOG_COLOR_ENABLE=1
pV(){
if [[ 0 -ne ${LOG_COLOR_ENABLE} ]]; then
echo -e "\033[;37m$1\033[0m"
else
echo -e "$1"
fi
}
pI(){
if [[ 0 -ne ${LOG_COLOR_ENABLE} ]]; then
echo -e "\033[;32mINFO: $1\033[0m"
else
echo -e "$1"
fi
}
pD(){
if [[ 0 -ne ${LOG_DEBUG_ENABLE} ]]; then
if [[ 0 -ne ${LOG_COLOR_ENABLE} ]]; then
echo -e "\033[;34mDEBUG: $1\033[0m"
else
echo -e "$1"
fi
fi
}
pW(){
if [[ 0 -ne ${LOG_COLOR_ENABLE} ]]; then
echo -e "\033[;33mWARN: $1\033[0m"
else
echo -e "$1"
fi
}
pE(){
if [[ 0 -ne ${LOG_COLOR_ENABLE} ]]; then
echo -e "\033[;31mERROR: $1\033[0m"
else
echo -e "$1"
fi
}
#pV "V"
#pI "I"
#pD "D"
#pW "W"
#pE "E"
checkFuncBack() {
if [ ! $? -eq 0 ]; then
echo -e "\033[;31mRun [ $1 ] error exit code 1\033[0m"
exit 1
# else
# echo -e "\033[;30mRun [ $1 ] success\033[0m"
fi
}
checkBinary() {
local evn_checker=$(which $1)
checkFuncBack "which $1"
if [ ! -n "$evn_checker" ]; then
echo -e "\033[;31mCheck event [ $1 ] error exit\033[0m"
exit 1
# else
# echo -e "\033[;32mCli [ $1 ] event check success\033[0m\n-> \033[;34m$1 at Path: ${evn_checker}\033[0m"
fi
}
release="unix"
bit=""
check_sys() {
case "$(uname)" in
Darwin*)
release="Darwin"
;;
*)
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
;;
esac
bit=$(uname -m)
}
check_sys
# replace file text by regular
# $1 file
# $2 regular from
# $3 regular to
# Error will return 1
replaceFileByRegular() {
local target_file=$1
local word_from=$2
local word_to=$3
if [[ -z "${word_from}" ]]; then
pW "replaceFileByRegular word_from is empty"
return 1
fi
if [[ -z "${word_to}" ]]; then
pW "replaceFileByRegular word_to is empty"
return 1
fi
if [[ "${release}" -eq "Darwin" ]]; then
# pD "in darwin ; word_from: ${word_from} ; word_to: ${word_to} ; target_file: ${target_file}"
sed -i "" "s#${word_from}#${word_to}#g" ${target_file}
else
# pD "in other ; word_from: ${word_from} ; word_to: ${word_to} ; target_file: ${target_file}"
sed -i "s#${word_from}#${word_to}#g" ${target_file}
fi
}
# find file list and replace text by regular
# $1 target_file_root use . or folder
# $2 target_file_regular
# $3 word_regular_from
# $4 word_regular_to
# Error will return 1
findFileReplaceByRegular() {
local target_file_root=$1
local target_file_regular=$2
local word_regular_from=$3
local word_regular_to=$4
if [[ -z "${target_file_root}" ]]; then
pW "findFileReplaceByRegular target_file_regular is empty"
return 1
fi
if [[ -z "${target_file_regular}" ]]; then
pW "findFileReplaceByRegular target_file_regular is empty"
return 1
fi
if [[ -z "${word_regular_from}" ]]; then
pW "findFileReplaceByRegular word_regular_from is empty"
return 1
fi
if [[ -z "${word_regular_to}" ]]; then
pW "findFileReplaceByRegular word_regular_to is empty"
return 1
fi
if [[ "${release}" -eq "Darwin" ]]; then
# pD "in darwin ; target_file_regular: ${target_file_regular} ; word_regular_from: ${word_regular_from} ; word_regular_to: ${word_regular_to}"
find "${target_file_root}" -name "${target_file_regular}" | xargs sed -i "" "s#${word_regular_from}#${word_regular_to}#g"
else
# pD "in other ; target_file_regular: ${target_file_regular} ; word_regular_from: ${word_regular_from} ; word_regular_to: ${word_regular_to}"
find "${target_file_root}" -name "${target_file_regular}" | xargs sed -i "s#${word_regular_from}#${word_regular_to}#g"
fi
}
removeFileExist() {
local target_file_path=$1
if [[ -z "${target_file_path}" ]]; then
pW "removeFileByRegular target_file_path is empty"
return 1
fi
if [[ -f "${target_file_path}" ]]; then
rm -f ${target_file_path}
checkFuncBack "rm -f ${target_file_path}"
# pI "removeFileExist ${target_file_path}"
else
pW "want remove file not exist at: ${target_file_path}"
fi
}
# remove file by regular
# $1 target_file_regular
# Error will return 1
removeFileByRegular() {
local target_file_regular=$1
if [[ -z "${target_file_regular}" ]]; then
pW "removeFileByRegular target_file_regular is empty"
return 1
fi
# pW "removeFileByRegular cli: find . -name ${target_file_regular} | xargs rm -f"
find . -name "${target_file_regular}" | xargs rm -f
}
checkBinary git
checkBinary make
if [[ $# -lt 1 ]]; then
echo -e "\033[;31mCLI error!\033[0m see ${shell_run_name} -h"
exit 1
fi
new_project=$1
if [ ! -n "${new_project}" ]; then
echo -e "\033[;31mError you must set new_project at first!\033[0m"
exit 1
fi
if [ -d ${new_project} ]; then
echo -e "\033[;31mError new new project is exist -> ${new_project}\033[0m"
exit 1
fi
if [[ -n $2 ]]; then
new_repo_group="$2"
else
# echo "set default repo group: ${temple_group}"
new_repo_group=${temple_group}
fi
if [[ -n $3 ]]; then
new_repo_host="$3"
else
# echo "set default repo host: ${temple_repo_host}"
new_repo_host=${temple_repo_host}
fi
if [[ -n $4 ]]; then
new_hub_user="$4"
else
# echo "set default hub user: ${temple_hub_user}"
new_hub_user=${temple_hub_user}
fi
new_git_http_url=https://${new_repo_host}/${new_repo_group}/${new_project}
echo -e "=> temple url: ${temple_url}
=> temple_branch: ${temple_branch}
-> new_repo_host: ${new_repo_host}
-> new_group: ${new_repo_group}
-> new_project: ${new_project}
-> new_hub_user: ${new_hub_user}
-> new remote url: ${new_git_http_url}
"
pI "Clone from ${temple_url}"
git clone --depth 1 ${temple_url} -b ${temple_branch} ${new_project}
rm -rf ${new_project}/.git/
sleep 1
removeFileExist ${new_project}/${shell_run_name}
removeFileExist ${new_project}/CHANGELOG.md
# replace code text at file
replaceFileByRegular ${new_project}/README.md ${temple_repo_host}\/${temple_group}\/${temple_name} ${new_repo_host}\/${new_repo_group}\/${new_project}
replaceFileByRegular ${new_project}/README.md ${temple_repo_host} ${new_repo_host}
replaceFileByRegular ${new_project}/README.md ${temple_name} ${new_project}
replaceFileByRegular ${new_project}/README.md ${temple_group}\/${temple_name} ${new_repo_group}\/${new_project}
replaceFileByRegular ${new_project}/Dockerfile ${temple_group}\/${temple_name} ${new_repo_group}\/${new_project}
replaceFileByRegular ${new_project}/Dockerfile ${temple_group} ${new_repo_group}
replaceFileByRegular ${new_project}/Dockerfile ${temple_name} ${new_project}
replaceFileByRegular ${new_project}/Dockerfile ${temple_hub_user} ${new_hub_user}
replaceFileByRegular ${new_project}/build.dockerfile ${temple_group}\/${temple_name} ${new_repo_group}\/${new_project}
replaceFileByRegular ${new_project}/build.dockerfile ${temple_group} ${new_repo_group}
replaceFileByRegular ${new_project}/build.dockerfile ${temple_name} ${new_project}
replaceFileByRegular ${new_project}/Makefile ${temple_group} ${new_repo_group}
replaceFileByRegular ${new_project}/Makefile ${temple_name} ${new_project}
replaceFileByRegular ${new_project}/Makefile ${temple_hub_user} ${new_hub_user}
replaceFileByRegular ${new_project}/package.json ${temple_group}\/${temple_name} ${new_repo_group}\/${new_project}
replaceFileByRegular ${new_project}/package.json ${temple_name} ${new_project}
replaceFileByRegular ${new_project}/package.json ${temple_hub_user} ${new_hub_user}
replaceFileByRegular ${new_project}/package.json ${temple_version} ${new_version_for_dev}
replaceFileByRegular ${new_project}/docker-bake.hcl ${temple_name} ${new_project}
# replace code at folder
findFileReplaceByRegular ${new_project} "*.mk" ${temple_repo_host}\/${temple_group}\/${temple_name} ${new_repo_host}\/${new_repo_group}\/${new_project}
findFileReplaceByRegular ${new_project} "*.mk" ${temple_group} ${new_repo_group}
findFileReplaceByRegular ${new_project} "*.mk" ${temple_name} ${new_project}
findFileReplaceByRegular ${new_project} "*.md" ${temple_group} ${new_repo_group}
findFileReplaceByRegular ${new_project} "*.md" ${temple_name} ${new_project}
findFileReplaceByRegular ${new_project} "*.md" ${temple_hub_user} ${new_hub_user}
findFileReplaceByRegular ${new_project} "*.yml" ${temple_group} ${new_repo_group}
findFileReplaceByRegular ${new_project} "*.yml" ${temple_name} ${new_project}
findFileReplaceByRegular ${new_project} "*.yml" ${temple_hub_user} ${new_hub_user}
findFileReplaceByRegular ${new_project} "*.dockerfile" ${temple_hub_user} ${new_hub_user}
# # remove README.md last line
# if [[ ${release} -eq "Darwin" ]]; then
# sed -i "" '70,84d' ./${new_project}/README.md
# else
# sed -i '70,84d' ./${new_project}/README.md
# fi
cd ${new_project}
git init
cd ..
echo -e "Finish make ${temple_name} project => \033[;32m${new_project}\033[0m"
echo "please add secrets key: DOCKERHUB_TOKEN at ${new_git_http_url}/settings/secrets/actions"