-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.sh
70 lines (56 loc) · 1.84 KB
/
docker.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
#!/bin/bash
##### FUNCTIONS ######
function quit {
echo -e "Possible args:"
echo -e "\tpull - pull mysql:latest image"
echo -e "\tbuild - build project and platform container"
echo -e "\tstart - pull images, build platform and run all containers"
echo -e "\trun - run platform container"
echo -e "\trun mysql - run mysql container"
echo -e "\trerun - stop, build and run platform"
echo -e "\tstop - stop and rm platform container"
echo -e "\tstop all - stop and rm all containers"
echo -e "Recommended to use start the first time and rerun when code is changed"
exit
}
function pull {
docker pull mysql:latest
}
function run_mysql {
docker run --name mysql-socatel -e MYSQL_ROOT_PASSWORD={your_root_password} -e MYSQL_DATABASE={your_database} -e MYSQL_USER={your_user} -e MYSQL_PASSWORD={your_password} -d mysql:latest
}
function build {
mvn clean package && docker build . -t socatel-platform
}
function run_platform {
docker run -p 8080:8080 --name socatel-platform --link mysql-socatel:mysql -d socatel-platform
}
function rerun {
stop_platform
build && run_platform
}
function start {
pull
run_mysql
build
run_platform
}
function stop_platform {
docker stop socatel-platform
docker rm socatel-platform
}
function stop_mysql {
docker stop mysql-socatel
docker rm mysql-socatel
}
function stop_all {
stop_platform
stop_mysql
}
##### MAIN SCRIPT #####
[[ $# -eq 0 ]] && quit
if [[ $# -eq 1 ]]; then
([[ "$1" = "pull" ]] && pull) || ([[ "$1" = "start" ]] && start) || ([[ "$1" = "build" ]] && build) || ([[ "$1" = "run" ]] && run_platform) || ([[ "$1" = "stop" ]] && stop_platform) || ([[ "$1" = "rerun" ]] && rerun) || quit
else
([[ "$1" = "run" ]] && [[ "$2" = "mysql" ]] && run_mysql) || ([[ "$1" = "stop" ]] && [[ "$2" = "all" ]] && stop_all) || quit
fi