-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.sh
127 lines (110 loc) · 2.71 KB
/
manager.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
#!/bin/bash
############################################################
# Help #
############################################################
Help() {
# Display Help
echo "Docker compose manager."
echo
echo "Syntax: manager.sh -a build"
echo "Syntax: manager.sh -a start -m ng-build -b"
echo "Syntax: manager.sh -a start -b -t"
echo "Syntax: manager.sh -a ng-build"
echo "Syntax: manager.sh -a down"
echo "options:"
echo "a set action [start|down|build]"
echo "m set mode [ng-build|ng-build-dev]"
echo "b run docker containers in background"
echo "t run with Traefik"
echo
}
############################################################
############################################################
# Main program #
############################################################
############################################################
# Set variables
Action=""
Mode=""
Background=""
Traefik=""
dockerComposeYML="./.docker/docker-compose.yml"
function copyEnvironment() {
echo "Copying environment"
cp ./backend/.env ./.docker/.env
}
function generateCertificates() {
echo "Generating certificates"
(
cd ./.docker/certs/
bash cert.sh jira-logger.io
)
}
function ngBuild() {
ttraefik=${1:-""}
bbackground=${2:-""}
buildCmd=${3:-"build"}
echo "Starting ng-$buildCmd"
docker-compose -f ./.docker/docker-compose.yml run node npm ci
docker-compose -f ./.docker/docker-compose.yml run node npm run build
}
############################################################
# Process the input options. Add options as needed. #
############################################################
# Get the options
while getopts "hibtm:a:" options; do
case "${options}" in
a)
Action=${OPTARG}
;;
m)
Mode=${OPTARG}
;;
b)
Background=" -d"
;;
t)
Traefik=" -f ./.docker/docker-compose-traefik.yml"
;;
*) # Invalid option
Help
exit
;;
esac
done
case $Action in
build)
echo "Running action $Action"
copyEnvironment
generateCertificates
docker-compose -f $dockerComposeYML build
;;
start)
echo "Running action $Action"
copyEnvironment
generateCertificates
docker-compose -f $dockerComposeYML $Traefik up $Background
case $Mode in
ng-build-dev)
ngBuild $Traefik $Background build-dev
;;
ng-build)
ngBuild $Traefik $Background build
;;
*) ;;
esac
;;
down)
echo "Running action $Action"
docker-compose -f $dockerComposeYML -f ./.docker/docker-compose-traefik.yml down
;;
ng-build)
ngBuild $Traefik $Background build
;;
ng-build-dev)
ngBuild $Traefik $Background build-dev
;;
*)
Help
;;
esac