-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker-start.sh
executable file
·99 lines (87 loc) · 2.38 KB
/
docker-start.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
#!/bin/bash
Help()
{
# Display Help
echo "This script will install all docker related dependencies to run the gchan front end project for development."
echo "Start by running \"./docker-start.sh -u\" to install and start required containers. "
echo "With the containers started, run \"./docker-start.sh -s\" to start the development server."
echo
echo "sintaxe: docker-start.sh [-u|d|s]"
echo "options:"
echo "u Runs docker-compose up on the project services."
echo "d Runs docker-compose down on the project services."
echo "s Starts the front-end development server."
echo "b Builds the app for deployment into the /dist directory."
echo "c Watches for changes in scss files (compiles into css)."
echo
}
# uses either docker-compose or docker compose depending on host installation
d_compose() {
docker compose > /dev/null 2>&1
if [ "$?" == "1" ]; then
docker-compose $@
else
docker compose $@
fi
}
up_container() {
d_compose -f .devcontainer/docker-compose.yml up
}
down_container() {
d_compose -f .devcontainer/docker-compose.yml down
}
npm_install() {
docker exec -w /workspace gchan-frontend-app-1 npm install
}
run_dev_server() {
docker exec -it -w /workspace gchan-frontend-app-1 bash -c "npm run dev || exit 1"
}
run_build() {
docker exec -w /workspace gchan-frontend-app-1 npm run build
}
build_deployment_files() {
.devcontainer/post-start.sh prod
if ! run_build; then
npm_install
run_build
fi
}
start_dev_server() {
.devcontainer/post-start.sh dev
if ! run_dev_server; then
npm_install
run_dev_server
fi
}
watch_sass() {
docker exec -it -w /workspace gchan-frontend-app-1 bash -c "npm run sass || exit 1"
}
# handle script options
while getopts ":udsbc" option; do
case $option in
u) # ups the container
up_container
exit;;
d) # remove all docker related data
down_container
exit;;
s) # starts the development server
start_dev_server
exit;;
b) # builds necessary files for deployment
build_deployment_files
exit;;
c) # Watches for changes in scss files (compiles into css)
watch_sass
exit;;
\?) # invalid option
echo "Invalid option!"
Help
exit;;
esac
done
# shows help when script is called without params
if [ -z $1 ]; then
Help
exit
fi