-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·139 lines (127 loc) · 3.21 KB
/
run.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
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env sh
set -e
RED="\033[0;31m"
CYAN="\033[0;36m"
BBLUE="\033[1;34m"
BYELLOW="\033[1;33m"
NC="\033[0m" #NO COLOR
start_services() {
printf "${BBLUE}Starting cuttlink development services...${NC}\n\n"
docker-compose up -d
docker-compose logs -f
}
stop_services() {
printf "${BYELLOW}Stopping cuttlink services...${NC}\n\n"
docker-compose stop
}
teardown_services() {
if [ -n "$2" ] && [ "$(echo "$2" | sed 's/RMI=//')" = "true" ]; then
printf "${BYELLOW}Tearing down all cuttlink services (containers, networks, volumes, built images)...${NC}\n\n"
docker-compose down --rmi 'local' -v --remove-orphans
else
printf "${BYELLOW}Tearing down all cuttlink services (containers, networks, volumes)...${NC}\n\n"
docker-compose down -v --remove-orphans
fi
}
stop_service() {
if [ -z "$1" ]; then
printf "${BYELLOW}Specify the service name.${NC}\n"
else
printf "${BYELLOW}Stopping $1 service...${NC}\n\n"
docker-compose stop "$1"
if [ -n "$2" ] && [ "$(echo "$2" | sed 's/RM=//')" = "true" ]; then
printf "${BYELLOW}Removing $1 service...${NC}\n\n"
docker-compose rm -v --force "$1"
fi
fi
}
rebuild_service() {
if [ -z "$1" ]; then
printf "${BYELLOW}Specify the service name.${NC}\n"
else
stop_service "$1"
printf "${BBLUE}Rebuilding and starting $1 service...${NC}\n\n"
docker-compose up --build -d --no-deps --renew-anon-volumes "$1"
docker-compose logs -f
fi
}
list_services() {
printf "${BBLUE}Listing all services...${NC}\n\n"
docker-compose ps -a
}
build_services() {
teardown_services RMI=true
printf "${BBLUE}Creating and starting cuttlink production services...${NC}\n\n"
docker-compose -f docker-compose.yml docker-compose.prod.yml up --build -d
docker-compose logs -f
}
pause() {
if [ -n "$1" ]; then
printf "${BYELLOW}Pausing $1 service...${NC}\n\n"
docker-compose pause "$1"
else
printf "${BYELLOW}Pausing all services...${NC}\n\n"
docker-compose pause
fi
}
exec_into() {
if [ -z "$1" ]; then
printf "${BYELLOW}Specify at least the container name you want to run the command on.${NC}\n\n"
printf "${BYELLOW}Example:${NC} ./run.sh exec_into ${CYAN}cuttlink_server${NC}\n"
else
printf "${BYELLOW}Executing into the specified container...${NC}\n\n"
docker exec -it "$@" /usr/bin/env sh
fi
}
case $1 in
ls)
list_services
exit
;;
start)
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1
start_services
exit
;;
stop)
stop_services
exit
;;
teardown)
teardown_services "$@"
exit
;;
stop_service)
"$@"
exit
;;
rebuild_service)
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1
"$@"
exit
;;
build)
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1
build_services
exit
;;
pause)
"$@"
exit
;;
exec_into)
"$@"
exit
;;
*)
if [ -n "$1" ]; then
printf "${CYAN}$1${NC} ${RED}is not a supported command.${NC}\n"
else
printf "${RED}Please specify a command.${NC}\n"
fi
exit 1
;;
esac