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 FROM debian:bookworm
# Install Apache, PHP, and other required extensions # Install Apache, PHP, and other required extensions
# ADDED: sudo and mariadb-client for the entrypoint script
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
apache2 \ apache2 \
php \ php \
...@@ -16,10 +17,11 @@ RUN apt-get update && apt-get install -y \ ...@@ -16,10 +17,11 @@ RUN apt-get update && apt-get install -y \
php-mbstring \ php-mbstring \
unzip \ unzip \
git \ git \
sudo \
mariadb-client \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Add custom PHP settings for Moodle # 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/apache2/conf.d/99-moodle.ini
COPY moodle.ini /etc/php/8.2/cli/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 ...@@ -35,7 +37,13 @@ RUN mkdir /var/www/moodledata && chown -R www-data:www-data /var/www/moodledata
WORKDIR /var/www/html WORKDIR /var/www/html
RUN chown -R www-data:www-data /var/www/html RUN chown -R www-data:www-data /var/www/html
# Copy a startup script # --- UPDATED SECTION ---
COPY --chown=root:root docker-entrypoint.sh / # Copy the entrypoint script to a standard location and make it executable
ENTRYPOINT ["/docker-entrypoint.sh"] 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"] CMD ["apache2ctl", "-D", "FOREGROUND"]
...@@ -29,6 +29,10 @@ services: ...@@ -29,6 +29,10 @@ services:
depends_on: depends_on:
- db - db
restart: unless-stopped restart: unless-stopped
environment:
- MOODLE_WWWROOT=http://localhost:8080
- MOODLE_ADMIN_USER=user
- MOODLE_ADMIN_PASS=QAYwsx@12345
backend: backend:
container_name: backend container_name: backend
......
#!/bin/bash #!/bin/bash
set -e 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 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 "$@" exec "$@"
DEBUG: Data object being sent to add_moduleinfo(): DEBUG: Data object being sent to add_moduleinfo():
stdClass Object stdClass Object
( (
[course] => 6 [course] => 2
[modulename] => assign [modulename] => assign
[name] => Fully Automated DTA Assignment [name] => Fully Automated DTA Assignment
[intro] => This assignment was created by the final automation script. [intro] => This assignment was created by the final automation script.
...@@ -11,7 +11,7 @@ stdClass Object ...@@ -11,7 +11,7 @@ stdClass Object
[assignsubmission_dta_enabled] => 1 [assignsubmission_dta_enabled] => 1
[assignsubmission_file_enabled] => 1 [assignsubmission_file_enabled] => 1
[dta] => 1 [dta] => 1
[tests_draft_dta] => 432698970 [tests_draft_dta] => 879454372
[assignsubmission_file_maxsizebytes] => 0 [assignsubmission_file_maxsizebytes] => 0
[cmidnumber] => [cmidnumber] =>
[assignsubmission_file_maxfiles] => 20 [assignsubmission_file_maxfiles] => 20
...@@ -28,12 +28,12 @@ stdClass Object ...@@ -28,12 +28,12 @@ stdClass Object
[markingworkflow] => 0 [markingworkflow] => 0
[markingallocation] => 0 [markingallocation] => 0
[attemptreopenmethod] => none [attemptreopenmethod] => none
[allowsubmissionsfromdate] => 1753362310 [allowsubmissionsfromdate] => 1756162043
[duedate] => 1753967110 [duedate] => 1756766843
[cutoffdate] => 0 [cutoffdate] => 0
[gradingduedate] => 0 [gradingduedate] => 0
[module] => 1 [module] => 1
[timemodified] => 1753362310 [timemodified] => 1756162043
[alwaysshowdescription] => 0 [alwaysshowdescription] => 0
[completionsubmit] => 0 [completionsubmit] => 0
) )
...@@ -41,7 +41,7 @@ stdClass Object ...@@ -41,7 +41,7 @@ stdClass Object
DEBUG: Returned object from add_moduleinfo(): DEBUG: Returned object from add_moduleinfo():
stdClass Object stdClass Object
( (
[course] => 6 [course] => 2
[modulename] => assign [modulename] => assign
[name] => Fully Automated DTA Assignment [name] => Fully Automated DTA Assignment
[intro] => This assignment was created by the final automation script. [intro] => This assignment was created by the final automation script.
...@@ -51,7 +51,7 @@ stdClass Object ...@@ -51,7 +51,7 @@ stdClass Object
[assignsubmission_dta_enabled] => 1 [assignsubmission_dta_enabled] => 1
[assignsubmission_file_enabled] => 1 [assignsubmission_file_enabled] => 1
[dta] => 1 [dta] => 1
[tests_draft_dta] => 432698970 [tests_draft_dta] => 879454372
[assignsubmission_file_maxsizebytes] => 0 [assignsubmission_file_maxsizebytes] => 0
[cmidnumber] => [cmidnumber] =>
[assignsubmission_file_maxfiles] => 20 [assignsubmission_file_maxfiles] => 20
...@@ -68,16 +68,16 @@ stdClass Object ...@@ -68,16 +68,16 @@ stdClass Object
[markingworkflow] => 0 [markingworkflow] => 0
[markingallocation] => 0 [markingallocation] => 0
[attemptreopenmethod] => none [attemptreopenmethod] => none
[allowsubmissionsfromdate] => 1753362310 [allowsubmissionsfromdate] => 1756162043
[duedate] => 1753967110 [duedate] => 1756766843
[cutoffdate] => 0 [cutoffdate] => 0
[gradingduedate] => 0 [gradingduedate] => 0
[module] => 1 [module] => 1
[timemodified] => 1753362310 [timemodified] => 1756162043
[alwaysshowdescription] => 0 [alwaysshowdescription] => 0
[completionsubmit] => 0 [completionsubmit] => 0
[instance] => 3 [instance] => 1
[coursemodule] => 10 [coursemodule] => 2
[groupingid] => 0 [groupingid] => 0
[completion] => 0 [completion] => 0
[completionview] => 0 [completionview] => 0
...@@ -100,10 +100,10 @@ stdClass Object ...@@ -100,10 +100,10 @@ stdClass Object
( (
[context:protected] => core\context\module Object [context:protected] => core\context\module Object
( (
[_id:protected] => 28 [_id:protected] => 14
[_contextlevel:protected] => 70 [_contextlevel:protected] => 70
[_instanceid:protected] => 10 [_instanceid:protected] => 2
[_path:protected] => /1/3/27/28 [_path:protected] => /1/3/13/14
[_depth:protected] => 4 [_depth:protected] => 4
[_locked:protected] => 0 [_locked:protected] => 0
) )
...@@ -116,4 +116,4 @@ stdClass Object ...@@ -116,4 +116,4 @@ stdClass Object
[showgradingmanagement] => [showgradingmanagement] =>
) )
3 1
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