-
Notifications
You must be signed in to change notification settings - Fork 2
/
stack
executable file
·261 lines (236 loc) · 6.33 KB
/
stack
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
# Simple shell script to run commonly used features
arg_1="$1"
arg_2="$2"
arg_3="$3"
function show_help {
echo "
Available commands:
start [environment] - Start development environment containers
stop [environment] - Stop development environment containers
exec [container] - Exec program inside the container
kill [container] - Kill a container by name
console - Symfont console commands
config - Show docker config
errors - Show apache2 error log
wipe - Remove all docker containers
top - Show top processes
ps - Show stack processes
build {clean} - Build containers
up - Bring development environment up
down - Bring development environment down
db diff - Doctrine generate Entity based migration
db migrate - Doctrine run migration
nginx reload - Reload nginx
clear cache - Clear cache
help - Show this message
"
}
function docker_ps {
docker-compose ps
}
function docker_kill {
local $container=$1
docker-compose kill $container
}
function docker_logs {
docker-compose logs
}
function docker_top {
docker-compose top
}
function docker_up {
docker-compose up
}
function docker_down {
docker-compose down
}
function docker_wipe {
docker system prune -a
}
function docker_volume_wipe {
local env=$1
if [ -f "./docker-compose.$env.yml" ]; then
docker-compose \
-f docker-compose.yml \
-f docker-compose.$env.yml \
down -v
else
echo "A valid stack environment required, e.g.:"
echo "./stack sql-wipe dev"
fi
}
function docker_exec {
local container=$1
if [ "$container" = "" ]; then
container="ocms-php-fpm"
fi
docker exec -it -u root:root $container bash
}
function docker_start {
local env=$1
if [ "$env" = "" ]; then
env="dev"
fi
if [ -f "./docker-compose.$env.yml" ]; then
echo "Start containers for $env environment"
if [ -f "./docker-compose.override.yml" ]; then
docker-compose \
-f docker-compose.yml \
-f docker-compose.override.yml \
-f docker-compose.$env.yml \
up -d --remove-orphans
else
docker-compose \
-f docker-compose.yml \
-f docker-compose.$env.yml \
up -d --remove-orphans
fi
if [ "$env" = "dev" ]; then
composer_update
echo "Set NGNIX file permissions on cache director"
docker exec ocms-nginx-server chmod 0755 var/cache/images
fi
docker_db_migrate
else
echo "A valid stack environment required, e.g.:"
echo "./stack start dev"
fi
}
function docker_stop {
local env=$1
if [ "$env" = "" ]; then
env="dev"
fi
if [ -f "./docker-compose.$env.yml" ]; then
echo "Stop containers for $env environment"
if [ -f "./docker-compose.override.yml" ]; then
docker-compose \
-f docker-compose.yml \
-f docker-compose.override.yml \
-f docker-compose.$env.yml \
down
else
docker-compose \
-f docker-compose.yml \
-f docker-compose.$env.yml \
down
fi
else
echo "A valid stack environment required, e.g.:"
echo "./stack stop dev"
fi
}
function docker_config {
local env=$1
if [ "$env" = "" ]; then
env="dev"
fi
if [ -f "./docker-compose.$env.yml" ]; then
echo "Show config for $env environment"
if [ -f "./docker-compose.override.yml" ]; then
docker-compose \
-f docker-compose.yml \
-f docker-compose.override.yml \
-f docker-compose.$env.yml \
config
else
docker-compose \
-f docker-compose.yml \
-f docker-compose.$env.yml \
config
fi
else
echo "A valid stack environment required, e.g.:"
echo "./stack config dev"
fi
}
function docker_db_backup {
docker exec ocms-mysql bash -c "mysqldump --databases hoopless > /docker-entrypoint-initdb.d/01-init.sql"
}
function docker_build {
local param_1=$1
echo "Build web server container"
if [ "$param_1" == "clean" ]; then
docker-compose build --pull --no-cache
else
docker-compose build
fi
}
function docker_errors {
echo "Tailing NGINX Error Log"
docker exec ocms-webserver tail ../var/log/nginx/error.log
}
function docker_db_diff {
echo "DB Migration Diff"
docker exec --user root ocms-php-fpm php ./vendor/bin/doctrine-migrations migrations:diff
}
function docker_db_migrate {
echo "DB Migrate"
docker exec --user root ocms-php-fpm php ./vendor/bin/doctrine-migrations migrations:migrate
}
function symfony_console {
local command=$1
docker exec --user root ocms-php-fpm ./bin/console $command
}
function nginx_reload {
docker exec -it ocms-webserver nginx -s reload
}
function clear_cache {
docker exec --user root ocms-php-fpm composer clear-image-cache
}
function composer_update {
# must be ran outside of Dockerfile due to mount
echo "Update composer"
docker exec --user root ocms-php-fpm composer update -d .
docker exec --user root ocms-php-fpm composer dump-autoload --optimize -d .
}
if [ "$arg_1" == "start" ]; then
docker_start $arg_2
elif [ "$arg_1" == "stop" ]; then
docker_stop $arg_2
elif [ "$arg_1" == "exec" ]; then
docker_exec $arg_2 ${@:3:99}
elif [ "$arg_1" == "kill" ]; then
docker_kill $arg_2
elif [ "$arg_1" == "console" ]; then
symfony_console $arg_2
elif [ "$arg_1" == "config" ]; then
docker_config $arg_2
elif [ "$arg_1" == "errors" ]; then
docker_errors
elif [ "$arg_1" == "wipe" ]; then
docker_wipe
elif [ "$arg_1" == "volume-wipe" ]; then
docker_volume_wipe $arg_2
elif [ "$arg_1" == "top" ]; then
docker_top
elif [ "$arg_1" == "ps" ]; then
docker_ps
elif [ "$arg_1" == "build" ]; then
docker_build $arg_2
elif [ "$arg_1" == "up" ]; then
docker_up
elif [ "$arg_1" == "down" ]; then
docker_down
elif [ "$arg_1" == "nginx" ]; then
if [ "$arg_2" == "reload" ]; then
nginx_reload
fi
elif [ "$arg_1" == "clear" ]; then
if [ "$arg_2" == "cache" ]; then
clear_cache
fi
elif [ "$arg_1" == "db" ]; then
if [ "$arg_2" == "diff" ]; then
docker_db_diff
elif [ "$arg_2" == "backup" ]; then
docker_db_backup
elif [ "$arg_2" == "migrate" ]; then
docker_db_migrate
fi
elif [ "$arg_1" == "help" ]; then
show_help
else
show_help
fi