-
Notifications
You must be signed in to change notification settings - Fork 0
/
proddeploy.sh
executable file
·95 lines (78 loc) · 1.93 KB
/
proddeploy.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
#!/bin/bash
# Deployment script to quickly get a jukebox instance running on every machine.
# Dependencies: openssl, maven, docker, docker-compose
# All of those need to be available in the shell that is running this script.
export CI_REGISTRY=example.com:5000
export JUKEBOX_SSL_CERT=./ssl/ssl.crt
export JUKEBOX_SSL_KEY=./ssl/ssl.key
export JUKEBOX_PORT=443
export JUKEBOX_DATA=./data
export JUKEBOX_MUSIC_PATH=./music
export JUKEBOX_LOG=./logs
trap "exit 1" ERR
# Generates a new SSL certificate in ssl subfolder, which will be mounted by nginx
function generate_ssl {
mkdir -p ssl
openssl req \
-x509 \
-newkey rsa:4096 \
-keyout ssl/ssl.key \
-out ssl/ssl.crt \
-days 365 \
-nodes \
-subj "/C=DE/ST=NRW/L=Dortmund/O=Reactive Jukebox/OU=PG 607/CN=*/"
}
# Builds the backend from source
function build_frontend {
cd frontend
# install dependencies if necessary
if ! [ -d "./node_modules" ]; then
npm install
fi
# run build script
npm run build:aot:prod
cd ..
}
# Builds the backend from source
function build_backend {
cd backend
mvn compiler:compile war:war
mkdir -p logs
touch logs/studie.log
cd ..
}
clean () {
down
docker container prune --force
docker images "jukebox_*" --format='{{.Repository}}' | xargs --no-run-if-empty docker rmi
docker volume prune --force
rm -rf ./backend/target ./backend/logs
}
# Deploys using docker compose. Will build images if necessary.
function deploy {
docker-compose -f docker-compose.yml.prod up --build
}
case $1 in
clean)
# clean docker cache and backend target
clean
;;
down)
# shoutdown docker containers
down
exit 0
;;
*)
if [ -n "$1" ]
then
echo "usage: $0 [clean|down]" >&2
exit 1
fi
;;
esac
if ! [ -f ./ssl/ssl.crt ] || ! [ -f ./ssl/ssl.key ]; then
generate_ssl
fi
build_frontend
build_backend
deploy