Skip to content

Commit 52339d8

Browse files
authored
Merge pull request #2107 from Websoft9/dev
fix/moodle-upgrade-docker-compose
2 parents a3381ef + d705f3c commit 52339d8

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

apps/moodle/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LABEL org.opencontainers.image.authors="https://www.websoft9.com" \
1111
org.opencontainers.image.version="5.1.3"
1212

1313
ENV MOODLE_VERSION=5.1.3 \
14+
MOODLE_SRC=/usr/src/moodle \
1415
MOODLE_DATA=/var/moodledata \
1516
APACHE_DOCUMENT_ROOT=/var/www/html/public
1617

@@ -34,13 +35,14 @@ RUN mkdir -p ${MOODLE_DATA} \
3435
# For CI/CD: no proxy needed. For local builds behind a firewall:
3536
# docker build --network=host --build-arg CURL_PROXY=socks5h://127.0.0.1:1080 ...
3637
ARG CURL_PROXY=
37-
WORKDIR /var/www/html
38+
WORKDIR ${MOODLE_SRC}
3839
RUN curl ${CURL_PROXY:+--proxy "$CURL_PROXY"} -fsSL -o /tmp/moodle.zip \
3940
"https://packaging.moodle.org/stable501/moodle-${MOODLE_VERSION}.zip" \
4041
&& unzip -q /tmp/moodle.zip -d /tmp/moodle_src \
41-
&& cp -a /tmp/moodle_src/moodle/. /var/www/html/ \
42+
&& mkdir -p ${MOODLE_SRC} /var/www/html \
43+
&& cp -a /tmp/moodle_src/moodle/. ${MOODLE_SRC}/ \
4244
&& rm -rf /tmp/moodle.zip /tmp/moodle_src \
43-
&& chown -R www-data:www-data /var/www/html
45+
&& chown -R www-data:www-data ${MOODLE_SRC} /var/www/html
4446

4547
# Moodle scheduled task (cron)
4648
RUN echo "* * * * * www-data /usr/local/bin/php /var/www/html/admin/cli/cron.php >/dev/null 2>&1" \

apps/moodle/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
ports:
1111
- "${W9_HTTP_PORT_SET}:${W9_HTTP_PORT}"
1212
volumes:
13+
- moodle_app:/var/www/html
1314
- moodle_data:/var/moodledata
1415
- ./src/php.ini:/usr/local/etc/php/conf.d/moodle.ini
1516
depends_on:
@@ -33,6 +34,7 @@ services:
3334
start_period: 30s
3435

3536
volumes:
37+
moodle_app:
3638
moodle_data:
3739
mariadb_data:
3840

apps/moodle/entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@ set -euo pipefail
2020
rm -f /var/run/cron.pid 2>/dev/null || true
2121
cron
2222

23+
# Initialize the mounted application directory from the image seed on first start.
24+
if [ ! -f /var/www/html/public/index.php ]; then
25+
echo "Initializing Moodle application directory..."
26+
mkdir -p /var/www/html
27+
cp -a /usr/src/moodle/. /var/www/html/
28+
chown -R www-data:www-data /var/www/html
29+
fi
30+
2331
# Restore config.php from moodledata if it was persisted after a previous install
2432
if [ -f "${MOODLE_DATA}/.moodle_config.php" ] && [ ! -f /var/www/html/config.php ]; then
2533
echo "Restoring config.php from moodledata..."
2634
cp "${MOODLE_DATA}/.moodle_config.php" /var/www/html/config.php
35+
chown www-data:www-data /var/www/html/config.php
36+
chmod 644 /var/www/html/config.php
2737
fi
2838

2939
# Wait for the database to be ready (max 120 seconds)
@@ -72,12 +82,14 @@ if [ ! -f /var/www/html/config.php ]; then
7282
# Persist config.php to moodledata so it survives container recreations
7383
cp /var/www/html/config.php "${MOODLE_DATA}/.moodle_config.php"
7484
chown www-data:www-data /var/www/html/config.php
85+
chmod 644 /var/www/html/config.php
7586
elif php /var/www/html/admin/cli/upgrade.php --is-pending --non-interactive 2>/dev/null | grep -q "pending\|Upgrade"; then
7687
echo "Database upgrade pending, running upgrade..."
7788
php /var/www/html/admin/cli/upgrade.php --non-interactive
7889
echo "Moodle upgrade complete."
7990
cp /var/www/html/config.php "${MOODLE_DATA}/.moodle_config.php"
8091
chown www-data:www-data /var/www/html/config.php
92+
chmod 644 /var/www/html/config.php
8193
fi
8294

8395
exec "$@"

0 commit comments

Comments
 (0)