Commit 2b46065e authored by Abhishek's avatar Abhishek
Browse files

Update .gitlab-ci.yml file with dind

parent e0e9b8cb
Pipeline #11948 failed
image: 41abku1mst/moodle-web:latest # your Moodle image in registry
# This GitLab CI/CD pipeline is designed to run the complete Moodle
# automation script in a single, manually triggered job.
stages:
- full_test
image: docker:20.10.16
services:
- name: mariadb:10.6
alias: db
- name: hftstuttgart/cota-backend:latest
alias: backend
- name: docker:20.10.16-dind
alias: docker
stages:
- full_test
variables:
# Moodle settings
MOODLE_URL: "http://localhost"
MOODLE_WWWROOT: "http://localhost"
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
EUSER: "appuser"
EGID: "137"
MOODLE_WWWROOT: "http://docker:8080" # For the entrypoint installation
MOODLE_URL: "http://docker:8080" # For the test script's curl commands
# Add the admin credentials here so they are also written to the .env file
MOODLE_ADMIN_USER: "user"
MOODLE_ADMIN_PASS: "QAYwsx@12345"
# MariaDB settings
MARIADB_ROOT_PASSWORD: verysecretpassword
MARIADB_DATABASE: moodle
MARIADB_USER: moodleuser
MARIADB_PASSWORD: moodlepassword
# Backend URL
BACKEND_URL: "http://backend:8080"
run_full_automation:
stage: full_test
script:
- apt-get update && apt-get install -y curl netcat-openbsd
- echo "🚀 Starting Apache..."
- apache2ctl -D FOREGROUND &
- sleep 10
when: manual
- echo "⏳ Waiting for MariaDB..."
- timeout=180
- |
until mysqladmin ping -h"db" --silent; do
timeout=$((timeout - 5))
if [ $timeout -le 0 ]; then
echo "❌ MariaDB did not start after 3 minutes."
exit 1
fi
echo " -> DB not ready, retrying in 5s"
sleep 5
done
- echo "✅ MariaDB is ready."
before_script:
- apk add --no-cache curl docker-compose bash jq
- until docker info > /dev/null 2>&1; do echo "Waiting for Docker daemon..."; sleep 3; done
- echo "⏳ Waiting for backend:8080..."
- timeout=180
- |
until nc -z backend 8080; do
timeout=$((timeout - 5))
if [ $timeout -le 0 ]; then
echo "❌ Backend port 8080 not reachable after 3 minutes."
exit 1
fi
echo " -> Backend not ready, retrying in 5s"
sleep 5
done
- echo "✅ Backend port is open."
# --- THIS IS THE FIX ---
# 1. Explicitly create the named volume so we know it exists.
- docker volume create cota-infra_dta_tests_data
# 2. Run a temporary container that mounts this volume and changes the ownership
# of the directory to user 137, which is the 'appuser' inside the backend container.
- echo "Setting permissions on dta_tests_data volume..."
- docker run --rm -v cota-infra_dta_tests_data:/data alpine chown 137:137 /data
script:
# --- THIS IS THE FIX ---
# Create a .env file on the fly. Docker Compose will automatically read this
# file and pass the variables to the containers.
- echo "Creating .env file for Docker Compose..."
- echo "MOODLE_WWWROOT=${MOODLE_WWWROOT}" > .env
- echo "MOODLE_ADMIN_USER=${MOODLE_ADMIN_USER}" >> .env
- echo "MOODLE_ADMIN_PASS=${MOODLE_ADMIN_PASS}" >> .env
- echo "EUSER=${EUSER}" >> .env
- echo "EGID=${EGID}" >> .env
- echo "⏳ Checking backend health endpoint..."
- |
if curl -s -f $BACKEND_URL/actuator/health >/dev/null; then
echo "✅ Backend health endpoint OK"
else
echo "⚠️ Backend health endpoint not available, continuing anyway"
fi
- echo "Starting Docker environment..."
- docker-compose up -d
- timeout=300
- echo "Waiting for Moodle web server to be ready..."
# Loop until the Moodle installation is complete.
- echo "Waiting for Moodle first-time installation to complete..."
- |
until curl -s -f http://localhost >/dev/null; do
timeout=300
while ! docker exec moodle-web-official [ -f /var/www/html/config.php ]; do
timeout=$((timeout - 5))
if [ $timeout -le 0 ]; then
echo "❌ Moodle did not become ready in 5 minutes"
echo "❌ ERROR: Moodle installation timed out after 5 minutes."
docker logs moodle-web-official
exit 1
fi
echo " -> Moodle not ready yet, retrying in 5s..."
echo " -> Installation not yet complete, waiting 5 more seconds..."
sleep 5
done
- echo "✅ Moodle is live"
- echo "✅ Moodle installation complete (config.php found)."
- echo "▶️ Running Moodle automation..."
# Now that Moodle is stable, we can proceed with the rest of the script.
- chmod +x test-moodle.sh
- echo "Executing the main automation script..."
- ./test-moodle.sh
after_script:
- echo "Tearing down Docker environment..."
- docker-compose down -v
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