Commit e2a6616d authored by Abhishek's avatar Abhishek
Browse files

Merge branch 'new_moodle_file_abhishek' into 'master'

installation part added to docker-entrypoint.sh file

See merge request !6
parents 02ab583d 5e88c187
Pipeline #11791 skipped with stage
FROM debian:bookworm
# Install Apache, PHP, and other required extensions
# ADDED: sudo and mariadb-client for the entrypoint script
RUN apt-get update && apt-get install -y \
apache2 \
php \
......@@ -16,10 +17,11 @@ RUN apt-get update && apt-get install -y \
php-mbstring \
unzip \
git \
sudo \
mariadb-client \
&& rm -rf /var/lib/apt/lists/*
# Add custom PHP settings for Moodle
# We copy it to both the apache2 and cli config directories
COPY moodle.ini /etc/php/8.2/apache2/conf.d/99-moodle.ini
COPY moodle.ini /etc/php/8.2/cli/conf.d/99-moodle.ini
......@@ -35,7 +37,13 @@ RUN mkdir /var/www/moodledata && chown -R www-data:www-data /var/www/moodledata
WORKDIR /var/www/html
RUN chown -R www-data:www-data /var/www/html
# Copy a startup script
COPY --chown=root:root docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
# --- UPDATED SECTION ---
# Copy the entrypoint script to a standard location and make it executable
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Set the entrypoint
ENTRYPOINT ["docker-entrypoint.sh"]
# command to start Apache on Debian
CMD ["apache2ctl", "-D", "FOREGROUND"]
......@@ -29,6 +29,10 @@ services:
depends_on:
- db
restart: unless-stopped
environment:
- MOODLE_WWWROOT=http://localhost:8080
- MOODLE_ADMIN_USER=user
- MOODLE_ADMIN_PASS=QAYwsx@12345
backend:
container_name: backend
......
#!/bin/bash
set -e
# Apache gets grumpy about PID files pre-existing
# Define the path to Moodle's config file
MOODLE_CONFIG_FILE="/var/www/html/config.php"
# Check if Moodle is already installed by looking for config.php
if [ ! -f "$MOODLE_CONFIG_FILE" ]; then
echo " Moodle config.php not found. Starting first-time installation..."
# Wait for the database to be ready
echo "-> Waiting for database connection at 'db'..."
while ! mysqladmin ping -h"db" --silent; do
sleep 1
done
echo "-> Database is ready."
# --- FIX: Read wwwroot from an environment variable ---
# This makes the script flexible for any environment (local or CI/CD).
if [ -z "$MOODLE_WWWROOT" ]; then
echo "❌ ERROR: MOODLE_WWWROOT environment variable is not set."
exit 1
fi
# Run the Moodle installation command as the www-data user
# It gets admin credentials and wwwroot from environment variables.
sudo -u www-data php /var/www/html/admin/cli/install.php \
--lang=en \
--wwwroot="$MOODLE_WWWROOT" \
--dataroot="/var/www/moodledata" \
--dbtype="mariadb" \
--dbhost="db" \
--dbname="moodle" \
--dbuser="moodleuser" \
--dbpass="moodlepassword" \
--fullname="CI Test Site" \
--shortname="CITest" \
--adminuser="$MOODLE_ADMIN_USER" \
--adminpass="$MOODLE_ADMIN_PASS" \
--adminemail="admin@example.com" \
--non-interactive \
--agree-license
echo "-> Moodle installation complete."
echo "-> Setting no-reply email address..."
sudo -u www-data php /var/www/html/admin/cli/cfg.php --name=noreplyaddress --set="noreply@example.com"
echo "-> Installation finished. Moodle is ready."
else
echo " Moodle config.php found. Skipping installation."
fi
# Clean up any old PID files to ensure Apache starts correctly.
echo "-> Cleaning up pre-existing PID files..."
rm -f /var/run/apache2/apache2.pid
# This is the final command that starts the main process of the container (Apache).
echo "-> Starting Apache..."
exec "$@"
DEBUG: Data object being sent to add_moduleinfo():
stdClass Object
(
[course] => 6
[course] => 2
[modulename] => assign
[name] => Fully Automated DTA Assignment
[intro] => This assignment was created by the final automation script.
......@@ -11,7 +11,7 @@ stdClass Object
[assignsubmission_dta_enabled] => 1
[assignsubmission_file_enabled] => 1
[dta] => 1
[tests_draft_dta] => 432698970
[tests_draft_dta] => 879454372
[assignsubmission_file_maxsizebytes] => 0
[cmidnumber] =>
[assignsubmission_file_maxfiles] => 20
......@@ -28,12 +28,12 @@ stdClass Object
[markingworkflow] => 0
[markingallocation] => 0
[attemptreopenmethod] => none
[allowsubmissionsfromdate] => 1753362310
[duedate] => 1753967110
[allowsubmissionsfromdate] => 1756162043
[duedate] => 1756766843
[cutoffdate] => 0
[gradingduedate] => 0
[module] => 1
[timemodified] => 1753362310
[timemodified] => 1756162043
[alwaysshowdescription] => 0
[completionsubmit] => 0
)
......@@ -41,7 +41,7 @@ stdClass Object
DEBUG: Returned object from add_moduleinfo():
stdClass Object
(
[course] => 6
[course] => 2
[modulename] => assign
[name] => Fully Automated DTA Assignment
[intro] => This assignment was created by the final automation script.
......@@ -51,7 +51,7 @@ stdClass Object
[assignsubmission_dta_enabled] => 1
[assignsubmission_file_enabled] => 1
[dta] => 1
[tests_draft_dta] => 432698970
[tests_draft_dta] => 879454372
[assignsubmission_file_maxsizebytes] => 0
[cmidnumber] =>
[assignsubmission_file_maxfiles] => 20
......@@ -68,16 +68,16 @@ stdClass Object
[markingworkflow] => 0
[markingallocation] => 0
[attemptreopenmethod] => none
[allowsubmissionsfromdate] => 1753362310
[duedate] => 1753967110
[allowsubmissionsfromdate] => 1756162043
[duedate] => 1756766843
[cutoffdate] => 0
[gradingduedate] => 0
[module] => 1
[timemodified] => 1753362310
[timemodified] => 1756162043
[alwaysshowdescription] => 0
[completionsubmit] => 0
[instance] => 3
[coursemodule] => 10
[instance] => 1
[coursemodule] => 2
[groupingid] => 0
[completion] => 0
[completionview] => 0
......@@ -100,10 +100,10 @@ stdClass Object
(
[context:protected] => core\context\module Object
(
[_id:protected] => 28
[_id:protected] => 14
[_contextlevel:protected] => 70
[_instanceid:protected] => 10
[_path:protected] => /1/3/27/28
[_instanceid:protected] => 2
[_path:protected] => /1/3/13/14
[_depth:protected] => 4
[_locked:protected] => 0
)
......@@ -116,4 +116,4 @@ stdClass Object
[showgradingmanagement] =>
)
3
1
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment