This repository has been archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack
212 lines (190 loc) · 4.79 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
#!/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
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
docs - Build ./app/docs
up - Bring development environment up
down - Bring development environment down
test - Run PHPUnit tests
help - Show this message
"
}
function docker_ps {
docker 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_exec {
local container=$1
local cmd="${@:2:99}"
if [ "$container" = "" ]; then
container="lbd-php-fpm"
fi
if [ "$cmd" = "" ]; then
echo "Exec into $container"
docker exec -it $container bash
else
echo "Run $container $cmd"
docker exec $container $cmd
fi
}
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
# must be ran outside of Dockerfile due to mount
echo "Update composer"
docker exec lbd-php-fpm composer update -d .
docker exec lbd-php-fpm composer dump-autoload --optimize -d .
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_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_test {
docker exec lbd-php-fpm composer test
}
function docker_build_docs {
echo "Build Docs"
docker build \
-t ouxsoft:sphinx-docs \
-f ./docker/sphinx-docs/Dockerfile .
docker run --mount \
type=bind,src=$PWD/app,dst=/app \
-t ouxsoft:sphinx-docs \
bash -c ./build.sh
}
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" == "config" ]; then
docker_config $arg_2
elif [ "$arg_1" == "wipe" ]; then
docker_wipe
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" == "docs" ]; then
docker_build_docs
elif [ "$arg_1" == "up" ]; then
docker_up
elif [ "$arg_1" == "down" ]; then
docker_down
elif [ "$arg_1" == "test" ]; then
docker_test
elif [ "$arg_1" == "help" ]; then
show_help
else
show_help
fi