-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmake.sh
More file actions
executable file
·195 lines (166 loc) · 3.82 KB
/
make.sh
File metadata and controls
executable file
·195 lines (166 loc) · 3.82 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
#!/usr/bin/env bash
NAME="verdaccio"
PATH_APP="/${NAME}"
PORT=4873
RELEASE="2.7.3"
RELEASE_LABEL="${NAME}-${RELEASE}"
RELEASE_FILE="${RELEASE_LABEL}.tar.gz"
TAG_PREFIX="deployable"
TAG_NAME="${NAME}"
TAG_TAG="latest"
rundir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")
canonical="$rundir/$(basename -- "$0")"
if [ -n "${1:-}" ]; then
cmd=$1
shift
else
cmd=build
fi
cd "$rundir"
set -uex
# Environment
DOCKER_BUILD_PROXY=${DOCKER_BUILD_PROXY:-}
####
die(){
echo "ERROR: $@"
echo "Exiting..."
exit 1
}
run_build_web(){
cd "$rundir/$RELEASE_LABEL"
yarn install
yarn run build:webui
}
run_build_proxy(){
DOCKER_BUILD_PROXY=${DOCKER_BUILD_PROXY:-http://10.8.10.8:3142}
DOCKER_BUILD_ARGS=${DOCKER_BUILD_ARGS:---build-arg DOCKER_BUILD_PROXY=$DOCKER_BUILD_PROXY}
DOCKER_BUILD_PROXY="$DOCKER_BUILD_PROXY" DOCKER_BUILD_ARGS="$DOCKER_BUILD_ARGS" run_build
}
run_build(){
local tag=${1:-${TAG_TAG}}
DOCKER_BUILD_ARGS=${DOCKER_BUILD_ARGS:-}
run_download_if_missing
run_extract_if_missing
#run_build_web
docker build $DOCKER_BUILD_ARGS -t ${TAG_PREFIX}/${TAG_NAME}:${RELEASE} .
docker tag ${TAG_PREFIX}/${TAG_NAME}:${RELEASE} ${TAG_PREFIX}/${TAG_NAME}:${tag}
if [ -f config.yaml.local ]; then
run_build_local $tag
fi
}
run_build_local(){
local tag=${1:-${TAG_TAG}}
DOCKER_BUILD_ARGS=${DOCKER_BUILD_ARGS:-}
docker build $DOCKER_BUILD_ARGS -f Dockerfile.local -t ${TAG_PREFIX}/${TAG_NAME}:${RELEASE}-local .
docker tag ${TAG_PREFIX}/${TAG_NAME}:${RELEASE}-local ${TAG_PREFIX}/${TAG_NAME}:${tag}-local
}
run_download_if_missing(){
cd "$rundir"
if [ ! -f "$RELEASE_FILE" ]; then
run_download
fi
}
run_download(){
cd "$rundir"
wget -cO "$RELEASE_FILE".tmp "https://github.com/verdaccio/verdaccio/archive/v${RELEASE}.tar.gz"
mv "${RELEASE_FILE}.tmp" "$RELEASE_FILE"
}
run_extract_if_missing(){
cd "$rundir"
if [ ! -d "${RELEASE_LABEL}" ]; then
run_extract
fi
}
run_extract(){
cd "$rundir"
tar -xvf ${RELEASE_FILE}
}
run_restart(){
run_stop
run_start
}
run_rebuild(){
run_build
run_restart
}
run_rebuild_proxy(){
run_build_proxy
run_restart
}
run_run(){ run_start "$@"; }
run_start(){
run_start_local=${1:-}
if [ -n "$run_start_local" ]; then
run_start_local="-$run_start_local"
fi
docker run \
--detach \
--volume ${NAME}-storage:${PATH_APP}/storage:rw \
--publish ${PORT}:${PORT} \
--name ${NAME} \
--restart always \
${TAG_PREFIX}/${TAG_NAME}:${RELEASE}${run_start_local}
}
run_run_local(){ run_start local "$@"; }
run_stop(){
docker stop ${NAME} || echo stop failed
docker rm -f ${NAME} || echo remove failed
}
run_shell(){
docker exec -ti ${NAME} bash
}
run_logs(){
docker logs --tail 10 -f ${NAME}
}
run_publish(){
local tag=${1:-${TAG_TAG}}
docker push ${TAG_PREFIX}/${TAG_NAME}:${tag}
}
run_release(){
local release_date=$(date +%Y%m%d-%H%M%S)
[ -z "$(git status --porcelain)" ] || die "Git status not clean"
build ${release_date}
build latest
test_run
git push
git tag -f ${release_date}
publish $release_date
publish latest
git push -f --tags
}
test_start(){
echo "implement test_start"
}
test_exec(){
echo "implement test_exec"
}
test_stop(){
echo "implement test_stop"
}
test_clean(){
echo "implement test_clean"
}
test_run(){
test_start
test_exec
test_stop
test_clean
}
####
run_help(){
echo "Commands:"
awk '/ ".*"/{ print " "substr($1,2,length($1)-3) }' make.sh
}
set -x
case $cmd in
"build") run_build "$@";;
"rebuild") run_rebuild "$@";;
"rebuild:proxy") run_rebuild_proxy "$@";;
"download") run_download "$@";;
"build:proxy") run_build_proxy "$@";;
"run") run_run "$@";;
"stop") run_stop "$@";;
"run:local") run_run_local "$@";;
"restart") run_restart "$@";;
'-h'|'--help'|'h'|'help') run_help;;
esac