forked from penpot/penpot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.sh
executable file
·270 lines (213 loc) · 7.34 KB
/
manage.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/env bash
set -e
export ORGANIZATION="penpotapp";
export DEVENV_IMGNAME="$ORGANIZATION/devenv";
export DEVENV_PNAME="penpotdev";
export CURRENT_USER_ID=$(id -u);
export CURRENT_VERSION=$(cat ./version.txt);
export CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD);
export CURRENT_HASH=$(git rev-parse --short HEAD);
export CURRENT_COMMITS=$(git rev-list --count HEAD)
function print-current-version {
if [ $CURRENT_BRANCH != "main" ]; then
echo -n "$CURRENT_BRANCH-$CURRENT_VERSION-$CURRENT_COMMITS-g$CURRENT_HASH"
else
echo -n "$CURRENT_VERSION-$CURRENT_COMMITS-g$CURRENT_HASH"
fi
}
function build-devenv {
echo "Building development image $DEVENV_IMGNAME:latest..."
pushd docker/devenv;
docker build -t $DEVENV_IMGNAME:latest .
popd;
}
function push-devenv {
docker push $DEVENV_IMGNAME:latest
}
function pull-devenv {
set -ex
docker pull $DEVENV_IMGNAME:latest
}
function pull-devenv-if-not-exists {
if [[ ! $(docker images $DEVENV_IMGNAME:latest -q) ]]; then
pull-devenv $@
fi
}
function start-devenv {
pull-devenv-if-not-exists $@;
# Check if the "backend-only" container is running. If it is, we need tot stop it first
if [[ ! $(docker ps -f "name=penpot-backend" -q) ]]; then
docker compose -p $DEVENV_PNAME --profile backend -f docker/devenv/docker-compose.yaml stop -t 2 backend;
fi
docker compose -p $DEVENV_PNAME --profile full -f docker/devenv/docker-compose.yaml up -d;
}
function start-backend {
pull-devenv-if-not-exists $@;
# Check if the "devenv" container is running. If it is, we need tot stop it first because conflicts with the backend
if [[ ! $(docker ps -f "name=penpot-devenv-main" -q) ]]; then
docker compose -p $DEVENV_PNAME --profile full -f docker/devenv/docker-compose.yaml stop -t 2 main;
fi
docker compose -p $DEVENV_PNAME --profile backend -f docker/devenv/docker-compose.yaml up -d;
}
function stop-devenv {
docker compose -p $DEVENV_PNAME --profile full --profile backend -f docker/devenv/docker-compose.yaml stop -t 2;
}
function drop-devenv {
docker compose -p $DEVENV_PNAME --profile full --profile backend -f docker/devenv/docker-compose.yaml down -t 2 -v;
echo "Clean old development image $DEVENV_IMGNAME..."
docker images $DEVENV_IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi
}
function log-devenv {
docker compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml logs -f --tail=50
}
function run-devenv {
if [[ ! $(docker ps -f "name=penpot-devenv-main" -q) ]]; then
start-devenv
fi
docker exec -ti penpot-devenv-main sudo -EH -u penpot /home/start-tmux.sh
}
function run-backend {
if [[ ! $(docker ps -f "name=penpot-backend" -q) ]]; then
start-backend
fi
docker exec -ti penpot-backend sudo -EH -u penpot /home/start-tmux-back.sh
}
function build {
echo ">> build start: $1"
local version=$(print-current-version);
pull-devenv-if-not-exists;
docker volume create ${DEVENV_PNAME}_user_data;
docker run -t --rm \
--mount source=${DEVENV_PNAME}_user_data,type=volume,target=/home/penpot/ \
--mount source=`pwd`,type=bind,target=/home/penpot/penpot \
-e EXTERNAL_UID=$CURRENT_USER_ID \
-e SHADOWCLJS_EXTRA_PARAMS=$SHADOWCLJS_EXTRA_PARAMS \
-w /home/penpot/penpot/$1 \
$DEVENV_IMGNAME:latest sudo -EH -u penpot ./scripts/build $version
echo ">> build end: $1"
}
function put-license-file {
local target=$1;
tee -a $target/LICENSE >> /dev/null <<EOF
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (c) UXBOX Labs SL
EOF
}
function build-frontend-bundle {
echo ">> bundle frontend start";
local version=$(print-current-version);
local bundle_dir="./bundle-frontend";
build "frontend";
rm -rf $bundle_dir;
mv ./frontend/target/dist $bundle_dir;
echo $version > $bundle_dir/version.txt;
put-license-file $bundle_dir;
echo ">> bundle frontend end";
}
function build-backend-bundle {
echo ">> bundle backend start";
local version=$(print-current-version);
local bundle_dir="./bundle-backend";
build "backend";
rm -rf $bundle_dir;
mv ./backend/target/dist $bundle_dir;
echo $version > $bundle_dir/version.txt;
put-license-file $bundle_dir;
echo ">> bundle frontend end";
}
function build-exporter-bundle {
echo ">> bundle exporter start";
local version=$(print-current-version);
local bundle_dir="./bundle-exporter";
build "exporter";
rm -rf $bundle_dir;
mv ./exporter/target $bundle_dir;
echo $version > $bundle_dir/version.txt
put-license-file $bundle_dir;
echo ">> bundle exporter end";
}
# DEPRECATED: temporary maintained for backward compatibility.
function build-app-bundle {
echo ">> bundle app start";
local version=$(print-current-version);
local bundle_dir="./bundle-app";
build "frontend";
build "backend";
rm -rf $bundle_dir
mkdir -p $bundle_dir;
mv ./frontend/target/dist $bundle_dir/frontend;
mv ./backend/target/dist $bundle_dir/backend;
echo $version > $bundle_dir/version.txt
put-license-file $bundle_dir;
echo ">> bundle app end";
}
function usage {
echo "PENPOT build & release manager"
echo "USAGE: $0 OPTION"
echo "Options:"
echo "- pull-devenv Pulls docker development oriented image"
echo "- build-devenv Build docker development oriented image"
echo "- start-devenv Start the development oriented docker compose service."
echo "- stop-devenv Stops the development oriented docker compose service."
echo "- drop-devenv Remove the development oriented docker compose containers, volumes and clean images."
echo "- run-devenv Attaches to the running devenv container and starts development environment"
echo "- start-backend Start the backend only service."
echo "- run-backend Starts a backend-only instance and attach tmux to it"
echo " based on tmux (frontend at localhost:3449, backend at localhost:6060)."
echo ""
}
case $1 in
version)
print-current-version
;;
## devenv related commands
pull-devenv)
pull-devenv ${@:2};
;;
build-devenv)
build-devenv ${@:2}
;;
push-devenv)
push-devenv ${@:2}
;;
start-devenv)
start-devenv ${@:2}
;;
start-backend)
start-backend ${@:2}
;;
run-devenv)
run-devenv ${@:2}
;;
run-backend)
run-backend ${@:2}
;;
stop-devenv)
stop-devenv ${@:2}
;;
drop-devenv)
drop-devenv ${@:2}
;;
log-devenv)
log-devenv ${@:2}
;;
# production builds
build-app-bundle)
build-app-bundle;
;;
build-frontend-bundle)
build-frontend-bundle;
;;
build-backend-bundle)
build-backend-bundle;
;;
build-exporter-bundle)
build-exporter-bundle;
;;
# Docker Image Tasks
*)
usage
;;
esac