-
Notifications
You must be signed in to change notification settings - Fork 0
/
devdeploy.sh
executable file
·81 lines (68 loc) · 1.69 KB
/
devdeploy.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
#!/bin/sh
# 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.
trap "exit 1" ERR
COMPOSE_FILE=docker-compose.yml
# Generates a new SSL certificate in ssl subfolder, which will be mounted by nginx
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
build_backend() {
cd backend
mvn compiler:compile war:war
cd ..
}
# Removes containers, images, cache, volumes, compiled java app.
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
}
# Runs docker-compose down
down () {
docker-compose -f "$COMPOSE_FILE" down
}
# Deploys using docker compose. Will build images if necessary.
deploy() {
docker-compose -f "$COMPOSE_FILE" up --build
}
case $1 in
clean)
# clean docker cache and backend target
clean
;;
down)
# shutdown docker containers
down
exit 0
;;
*)
if [ -n "$1" ]
then
echo "usage: $0 [clean|down]" >&2
exit 1
fi
;;
esac
# Generate ssl certificate, if needed
if ! [ -f ./ssl/ssl.crt ] || ! [ -f ./ssl/ssl.key ]; then
generate_ssl
fi
if ! [ -f ./backend/target/server.war ]; then
build_backend
fi
mkdir -p ./backend/logs
touch ./backend/logs/studie.log
deploy