-
Notifications
You must be signed in to change notification settings - Fork 257
/
moodle-docker-compose
executable file
·250 lines (216 loc) · 7.55 KB
/
moodle-docker-compose
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
#!/usr/bin/env bash
set -e
# First find out if this was called from symlink,
# then find the real path of parent directory.
# This is needed because macOS does not have GNU realpath.
thisfile=$( readlink "${BASH_SOURCE[0]}" ) || thisfile="${BASH_SOURCE[0]}"
basedir="$( cd "$( dirname "$thisfile" )/../" && pwd -P )"
if [ ! -d "$MOODLE_DOCKER_WWWROOT" ];
then
echo 'Error: $MOODLE_DOCKER_WWWROOT is not set or not an existing directory'
exit 1
fi
if [ -z "$MOODLE_DOCKER_DB" ];
then
echo 'Error: $MOODLE_DOCKER_DB is not set'
exit 1
fi
export ASSETDIR="${basedir}/assets"
# Test if we have docker compose v2, and keep quiet if we don't.
ver=$(docker compose version > /dev/null 2>&1 && docker compose version --short) || true
if [[ $ver =~ ^v?2 ]]; then
dockercompose="docker compose"
else
echo 'Compose v2 is not available in Docker CLI, falling back to use docker-compose script'
dockercompose="docker-compose"
fi
dockercompose="${dockercompose} -f ${basedir}/base.yml"
dockercompose="${dockercompose} -f ${basedir}/service.mail.yml"
# PHP Version.
export MOODLE_DOCKER_PHP_VERSION=${MOODLE_DOCKER_PHP_VERSION:-8.1}
# Database flavour.
dockercompose="${dockercompose} -f ${basedir}/db.${MOODLE_DOCKER_DB}.yml"
# Add support for version specific database settings.
if [ ! -z "$MOODLE_DOCKER_DB_VERSION" ];
then
filename="${basedir}/db.${MOODLE_DOCKER_DB}.${MOODLE_DOCKER_DB_VERSION}.yml"
if [ -f $filename ]; then
dockercompose="${dockercompose} -f ${filename}"
fi
fi
# Support PHP version overrides for DB not available any more.
# Expose DB port if requested.
if [[ $MOODLE_DOCKER_DB_PORT == *":"* ]] || [[ $MOODLE_DOCKER_DB_PORT -gt 0 ]]
then
# If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
if [[ ! $MOODLE_DOCKER_DB_PORT == *":"* ]]
then
export MOODLE_DOCKER_DB_PORT=127.0.0.1:$MOODLE_DOCKER_DB_PORT
fi
filename="${basedir}/db.${MOODLE_DOCKER_DB}.port.yml"
if [ -f $filename ];
then
dockercompose="${dockercompose} -f ${filename}"
fi
fi
# Guess mobile app runtime
if [ -z "$MOODLE_DOCKER_APP_RUNTIME" ];
then
if [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
then
appversion="$(cat $MOODLE_DOCKER_APP_PATH/package.json | sed -n -E 's/\s*"version": "([0-9]+\.[0-9]+\.[0-9]+)(.*)?",/\1/p')"
elif [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
then
appversion=$MOODLE_DOCKER_APP_VERSION
fi
if [[ ! -z $appversion ]];
then
if [[ ! -z "$(echo $appversion | sed -n -E 's/([0-9]+\.[0-9]+\.[0-9]+)/\1/p')" ]];
then
appmajorversion="$(echo $appversion | sed -n -E 's/([0-9]+)\.[0-9]+\.[0-9]+/\1/p')"
appminorversion="$(echo $appversion | sed -n -E 's/[0-9]+\.([0-9]+)\.[0-9]+/\1/p')"
if (( $appmajorversion > 4 || $appminorversion > 3));
then
export MOODLE_DOCKER_APP_RUNTIME="ionic7"
else
export MOODLE_DOCKER_APP_RUNTIME="ionic5"
fi
else
export MOODLE_DOCKER_APP_RUNTIME="ionic7"
fi
fi
fi
# Guess mobile app node version (only for local app development)
if [[ -z "$MOODLE_DOCKER_APP_NODE_VERSION" ]] && [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
then
appnodeversion="$(cat $MOODLE_DOCKER_APP_PATH/.nvmrc | sed -E "s/v(([0-9]+\.?)+)/\1/" || true)"
export MOODLE_DOCKER_APP_NODE_VERSION="$appnodeversion"
fi
# Guess mobile app port (only when using Docker app images)
if [[ -z "$MOODLE_DOCKER_APP_PORT" ]] && [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
then
if [[ "$MOODLE_DOCKER_APP_RUNTIME" = "ionic5" ]];
then
export MOODLE_DOCKER_APP_PORT="80"
else
export MOODLE_DOCKER_APP_PORT="443"
fi
fi
# Guess mobile app protocol
if [[ -z "$MOODLE_DOCKER_APP_PROTOCOL" ]];
then
if [[ "$MOODLE_DOCKER_APP_RUNTIME" = "ionic5" ]];
then
export MOODLE_DOCKER_APP_PROTOCOL="http"
else
export MOODLE_DOCKER_APP_PROTOCOL="https"
fi
fi
# Selenium browser
browserparts=(${MOODLE_DOCKER_BROWSER//:/ })
export MOODLE_DOCKER_BROWSER_NAME=${browserparts[0]}
export MOODLE_DOCKER_BROWSER_TAG=${browserparts[1]}
if [[ -z "$MOODLE_DOCKER_BROWSER_NAME" ]];
then
MOODLE_DOCKER_BROWSER_NAME=firefox
fi
if [[ -z "$MOODLE_DOCKER_BROWSER_TAG" ]];
then
if [[ "$MOODLE_DOCKER_BROWSER_NAME" = "firefox" ]];
then
MOODLE_DOCKER_BROWSER_TAG=3
elif [[ "$MOODLE_DOCKER_BROWSER_NAME" = "chrome" ]];
then
if [[ "$MOODLE_DOCKER_APP_RUNTIME" = "ionic5" ]];
then
MOODLE_DOCKER_BROWSER_TAG=3
else
MOODLE_DOCKER_BROWSER_TAG="120.0"
fi
fi
fi
# Mobile app for development
if [[ "$MOODLE_DOCKER_BROWSER_NAME" == "chrome" ]];
then
if [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
then
dockercompose="${dockercompose} -f ${basedir}/moodle-app-dev.yml"
elif [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
then
# Mobile app using a docker image
dockercompose="${dockercompose} -f ${basedir}/moodle-app.yml"
fi
fi
if [[ "$MOODLE_DOCKER_BROWSER_NAME" != "firefox" ]];
then
dockercompose="${dockercompose} -f ${basedir}/selenium.${MOODLE_DOCKER_BROWSER_NAME}.yml"
fi
# Selenium VNC port
export MOODLE_DOCKER_SELENIUM_SUFFIX=""
if [[ $MOODLE_DOCKER_SELENIUM_VNC_PORT == *":"* ]] || [[ $MOODLE_DOCKER_SELENIUM_VNC_PORT -gt 0 ]]
then
if [[ $(echo $MOODLE_DOCKER_BROWSER_TAG | sed 's/[^0-9].*//g') -lt 4 ]]
then
export MOODLE_DOCKER_SELENIUM_SUFFIX="-debug"
fi
# If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
if [[ ! $MOODLE_DOCKER_SELENIUM_VNC_PORT == *":"* ]]
then
MOODLE_DOCKER_SELENIUM_VNC_PORT=127.0.0.1:$MOODLE_DOCKER_SELENIUM_VNC_PORT
fi
dockercompose="${dockercompose} -f ${basedir}/selenium.debug.yml"
fi
# External services
if [[ ! -z "$MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES" ]];
then
dockercompose="${dockercompose} -f ${basedir}/phpunit-external-services.yml"
fi
# BBB Mock
if [[ ! -z "$MOODLE_DOCKER_BBB_MOCK" ]];
then
dockercompose="${dockercompose} -f ${basedir}/bbb-mock.yml"
fi
# Matrix Mock
if [[ ! -z "$MOODLE_DOCKER_MATRIX_MOCK" ]];
then
dockercompose="${dockercompose} -f ${basedir}/matrix-mock.yml"
fi
# Faildump directory
if [[ ! -z "$MOODLE_DOCKER_BEHAT_FAILDUMP" ]];
then
if [ ! -d "$MOODLE_DOCKER_BEHAT_FAILDUMP" ];
then
echo 'Error: $MOODLE_DOCKER_BEHAT_FAILDUMP is not an existing directory'
exit 1
fi
dockercompose="${dockercompose} -f ${basedir}/behat-faildump.yml"
fi
# Webserver host
export MOODLE_DOCKER_WEB_HOST=${MOODLE_DOCKER_WEB_HOST:-localhost}
# Webserver port
export MOODLE_DOCKER_WEB_PORT=${MOODLE_DOCKER_WEB_PORT:-8000}
if [[ $MOODLE_DOCKER_WEB_PORT == *":"* ]] || [[ $MOODLE_DOCKER_WEB_PORT -gt 0 ]]
then
# If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
if [[ ! $MOODLE_DOCKER_WEB_PORT == *":"* ]]
then
MOODLE_DOCKER_WEB_PORT=127.0.0.1:$MOODLE_DOCKER_WEB_PORT
fi
dockercompose="${dockercompose} -f ${basedir}/webserver.port.yml"
fi
# Behat test timeout factor
export MOODLE_DOCKER_TIMEOUT_FACTOR=${MOODLE_DOCKER_TIMEOUT_FACTOR:-1}
# Mac OS Compatbility
if [[ "$(uname)" == "Darwin" ]]; then
# Support https://docs.docker.com/docker-for-mac/osxfs-caching/
dockercompose="${dockercompose} -f ${basedir}/volumes-cached.yml"
fi
# Apply local customisations if a local.yml is found.
# Note: This must be the final modification before the docker-compose command is called.
localfile="${basedir}/local.yml"
if [ -f "${localfile}" ]
then
echo "Including local options from ${localfile}"
dockercompose="${dockercompose} -f ${localfile}"
fi
$dockercompose "$@"