-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.sh
executable file
·83 lines (66 loc) · 2.22 KB
/
run.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
#!/bin/bash -e
deploy_all=false
deploy_backend=false
deploy_frontend=false
# deploy_database=false
print_usage() {
echo "Usage: $0 [-a] [-b] [-d] [-f] [-h]" >&2;
echo "options:
-a Deploy all containers
-b Deploy backend container
-f Build and Deploy frontend container
-h this help message"
exit 1;
}
while getopts ":abfh" OPTION; do
case "$OPTION" in
a) deploy_all=true;;
b) deploy_backend=true;;
# d) deploy_database=true;;
f) deploy_frontend=true;;
h) print_usage;;
\?) echo "$0: Error: Invalid option: -${OPTARG}" >&2; exit 1;;
:) echo "$0: Error: option -${OPTARG} requires an argument" >&2; exit 1;;
esac
done
shift "$(($OPTIND -1))"
echo "all: $deploy_all"
echo "backend: $deploy_backend"
# echo "database: $deploy_database"
echo "frontend: $deploy_frontend"
if $deploy_all; then
echo "Re-deploy all containers"
#clean up possible old containers
docker compose --profile client down
BASE_PATH=$(pwd)
FRONTEND_PATH="$BASE_PATH/frontend"
# create vue-builder image
cd $FRONTEND_PATH
docker build --network host -t vue-builder -f Dockerfile.build .
# run vue-builder image to create dist
docker run --rm -v $FRONTEND_PATH/dist:/root/dist vue-builder
# Start the containers with help of docker compose
# remove data (mysql container generates data folder)
docker compose --profile client up -d --build
else
if $deploy_backend; then
docker compose --profile backend down || true
docker compose --profile backend up -d
fi
if $deploy_frontend; then
docker compose --profile frontend down || true
BASE_PATH=$(pwd)
FRONTEND_PATH="$BASE_PATH/frontend"
# create vue-builder image
cd $FRONTEND_PATH
docker build --network host -t vue-builder -f Dockerfile.build .
# run vue-builder image to create dist
docker run --rm -v $FRONTEND_PATH/dist:/root/dist vue-builder
cd $BASE_PATH
docker compose --profile frontend up -d --build
fi
# if $deploy_database; then
# docker compose --profile database down || true
# docker compose --profile database up -d
# fi
fi