diff --git a/.github/workflows/build-moodle.yaml b/.github/workflows/build-moodle.yaml new file mode 100644 index 00000000..841d56f2 --- /dev/null +++ b/.github/workflows/build-moodle.yaml @@ -0,0 +1,61 @@ +name: Build Moodle image + +# Moodle publishes no runtime image (Bitnami's moved behind a paywall in 2025), +# so the catalog template runs this one: services/moodle/image, the official +# checksum-pinned Moodle release on the official PHP Apache image. +# main/staging pushes publish the release tag the template uses; any other +# branch publishes only - for pre-merge testing. +on: + workflow_dispatch: + push: + paths: + - 'services/moodle/image/**' + - '.github/workflows/build-moodle.yaml' + +permissions: + contents: read + packages: write + +env: + IMAGE: ghcr.io/stackblaze/stack-templates/moodle + VERSION: 5.3.1-1 + +jobs: + build: + # GitHub-hosted: the org's self-hosted runners are not visible to this + # repo (the other build jobs here sit queued until they are cancelled). + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Tags + id: tags + run: | + short="${GITHUB_SHA::7}" + tags="${IMAGE}:${VERSION}-${short}" + if [ "$GITHUB_REF" = refs/heads/main ] || [ "$GITHUB_REF" = refs/heads/staging ]; then + tags="${tags},${IMAGE}:${VERSION}" + fi + echo "tags=${tags}" >> "$GITHUB_OUTPUT" + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: services/moodle/image + platforms: linux/amd64 + push: true + tags: ${{ steps.tags.outputs.tags }} + labels: | + org.opencontainers.image.source=https://github.com/stackblaze/stack-templates + org.opencontainers.image.description=Moodle ${{ env.VERSION }} for the StackBlaze catalog + org.opencontainers.image.licenses=GPL-3.0-or-later diff --git a/index.json b/index.json index b93c6a64..d07ff8d7 100644 --- a/index.json +++ b/index.json @@ -9714,31 +9714,34 @@ "source": "https://github.com/moodle/moodle", "icon": "https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/icon.png", "website": "https://moodle.org/", - "installation": "Moodle requires MySQL/MariaDB (the maintained container images target MariaDB, not PostgreSQL), so this template ships the mariadb add-on. The image is elestio/moodle, an actively-rebuilt Verified Publisher image tracking current Moodle releases (Bitnami's moodle image moved behind a paywall in 2025 and is no longer freely pullable). On first boot the container runs the Moodle installer against the database using the MOODLE_DATABASE_* env vars and provisions the admin account from MOODLE_USERNAME/MOODLE_PASSWORD/MOODLE_EMAIL; MOODLE_HOST and MOODLE_REVERSEPROXY are set so generated links resolve to the public HTTPS URL behind the ingress. After deploy, log in with the seeded admin and ROTATE: the MOODLE_PASSWORD env value, the MariaDB add-on password, and configure real SMTP under Site administration > Server > Email. Two persistent volumes are mounted: /bitnami/moodle holds the Moodle code plus config.php, and /bitnami/moodledata holds uploaded course files, caches and sessions. For production raise the app pod size (Moodle/PHP needs >=1Gi) and PHP memory_limit, and schedule the Moodle cron (admin/cli/cron.php) every minute. Optional companions: deploy the memcached add-on and point Moodle's MUC application cache at it for performance, and add an external Solr/Elasticsearch only if you enable global search (neither is required for a base install).", + "installation": "Moodle is installed from the command line on the first start (a few minutes), so its web installer is never open to the first visitor. Sign in at /login as the user in MOODLE_ADMIN_USER (admin) with the password generated in MOODLE_ADMIN_PASSWORD (both under Variables), then set your own email under your profile and the site name under Site administration. Changing those variables after the first start has no effect: manage users in Moodle. The site address is MOODLE_URL (the app URL); change it when you add a custom domain. Course files and uploads live on the volume at /var/www/moodledata; the database is PostgreSQL 17. A worker runs Moodle's cron every minute (forum and notification email, completion, cleanup). Email (password resets, enrolment and forum notifications) goes through the platform Email add-on and is always sent from its address. For safety, plugins cannot be installed or updated from Site administration: the Moodle code ships in the template image, and new Moodle versions arrive as a new image, upgraded automatically on start.", "architecture": [], "categories": [ - "productivity", + "school", "collaboration", - "work" + "productivity" ], "screenshots": [ - "https://moodle.org/theme/moodleorg/pix/moodle_logo_tm.png" + "https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/screenshot-course.png", + "https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/screenshot-quiz.png", + "https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/screenshot-dashboard.png" ], "links": [ - "https://docs.moodle.org/en/Installation", - "https://hub.docker.com/r/elestio/moodle" + "https://docs.moodle.org/503/en/Main_page", + "https://github.com/stackblaze/stack-templates/tree/main/services/moodle/image" ], "addons": [ - "MariaDB" + "Cluster", + "Smtp" ], - "stars": 6200, - "forks": 620, - "watchers": 6200, - "issues": 0, - "last_updated": "2026-06-13T00:00:00Z", - "last_pushed": "2026-06-13T00:00:00Z", - "created_at": "2020-01-01T00:00:00Z", - "size": 0, + "stars": 7613, + "forks": 7714, + "watchers": 432, + "issues": 1, + "last_updated": "2026-11-12T03:19:57Z", + "last_pushed": "2026-11-12T03:19:57Z", + "created_at": "2009-12-16T23:01:23Z", + "size": 986322, "language": "PHP", "gitops": false, "template": "https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/app.yaml", diff --git a/scripts/capture-specs/moodle.json b/scripts/capture-specs/moodle.json new file mode 100644 index 00000000..ba1f9187 --- /dev/null +++ b/scripts/capture-specs/moodle.json @@ -0,0 +1,39 @@ +{ + "viewport": { "width": 1920, "height": 1080 }, + "deviceScaleFactor": 2, + "login": { + "path": "/login/index.php", + "steps": [ + { "waitForSelector": "#username", "timeout": 60000 }, + { "fill": { "#username": "student" } }, + { "fill": { "#password": "${MOODLE_STUDENT_PASSWORD}" } }, + { "click": "#loginbtn" }, + { "waitForURL": "**/my/**", "timeout": 60000 } + ], + "waitAfterMs": 2000 + }, + "pages": [ + { + "name": "course", + "path": "/course/search.php?search=ASTRO101", + "waitFor": "text=Astronomy 101: The Night Sky", + "steps": [ + { "click": "a:has-text('Astronomy 101: The Night Sky')" }, + { "waitForSelector": "text=Night sky quiz", "timeout": 30000 }, + { "sleep": 1500 } + ] + }, + { "name": "dashboard-courses", "path": "/my/courses.php", "waitFor": "text=Creative Writing Workshop", "waitMs": 2000 }, + { + "name": "lesson", + "path": "/course/search.php?search=ASTRO101", + "waitFor": "text=Astronomy 101: The Night Sky", + "steps": [ + { "click": "a:has-text('Astronomy 101: The Night Sky')" }, + { "click": "a:has-text('Phases of the Moon')" }, + { "waitForSelector": "text=The Moon shines by reflected light", "timeout": 30000 }, + { "sleep": 1000 } + ] + } + ] +} diff --git a/services/moodle/app.yaml b/services/moodle/app.yaml index 67d80823..a348ed69 100644 --- a/services/moodle/app.yaml +++ b/services/moodle/app.yaml @@ -8,28 +8,24 @@ metadata: learning management system (LMS) for building online courses, classrooms and e-learning. kubero.dev/template.icon: https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/icon.png - kubero.dev/template.installation: 'Moodle requires MySQL/MariaDB (the maintained - container images target MariaDB, not PostgreSQL), so this template ships the - mariadb add-on. The image is elestio/moodle, an actively-rebuilt Verified Publisher - image tracking current Moodle releases (Bitnami''s moodle image moved behind - a paywall in 2025 and is no longer freely pullable). On first boot the container - runs the Moodle installer against the database using the MOODLE_DATABASE_* env - vars and provisions the admin account from MOODLE_USERNAME/MOODLE_PASSWORD/MOODLE_EMAIL; - MOODLE_HOST and MOODLE_REVERSEPROXY are set so generated links resolve to the - public HTTPS URL behind the ingress. After deploy, log in with the seeded admin - and ROTATE: the MOODLE_PASSWORD env value, the MariaDB add-on password, and - configure real SMTP under Site administration > Server > Email. Two persistent - volumes are mounted: /bitnami/moodle holds the Moodle code plus config.php, - and /bitnami/moodledata holds uploaded course files, caches and sessions. For - production raise the app pod size (Moodle/PHP needs >=1Gi) and PHP memory_limit, - and schedule the Moodle cron (admin/cli/cron.php) every minute. Optional companions: - deploy the memcached add-on and point Moodle''s MUC application cache at it - for performance, and add an external Solr/Elasticsearch only if you enable global - search (neither is required for a base install).' - kubero.dev/template.links: '["https://docs.moodle.org/en/Installation", "https://hub.docker.com/r/elestio/moodle"]' - kubero.dev/template.screenshots: '["https://moodle.org/theme/moodleorg/pix/moodle_logo_tm.png"]' + kubero.dev/template.installation: 'Moodle is installed from the command line on + the first start (a few minutes), so its web installer is never open to the + first visitor. Sign in at /login as the user in MOODLE_ADMIN_USER (admin) with + the password generated in MOODLE_ADMIN_PASSWORD (both under Variables), then + set your own email under your profile and the site name under Site administration. + Changing those variables after the first start has no effect: manage users in + Moodle. The site address is MOODLE_URL (the app URL); change it when you add a + custom domain. Course files and uploads live on the volume at /var/www/moodledata; + the database is PostgreSQL 17. A worker runs Moodle''s cron every minute (forum + and notification email, completion, cleanup). Email (password resets, enrolment + and forum notifications) goes through the platform Email add-on and is always + sent from its address. For safety, plugins cannot be installed or updated from + Site administration: the Moodle code ships in the template image, and new + Moodle versions arrive as a new image, upgraded automatically on start.' + kubero.dev/template.links: '["https://docs.moodle.org/503/en/Main_page", "https://github.com/stackblaze/stack-templates/tree/main/services/moodle/image"]' + kubero.dev/template.screenshots: '["https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/screenshot-course.png", "https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/screenshot-quiz.png", "https://raw.githubusercontent.com/stackblaze/stack-templates/main/services/moodle/screenshot-dashboard.png"]' kubero.dev/template.source: https://github.com/moodle/moodle - kubero.dev/template.categories: '["productivity", "collaboration", "work"]' + kubero.dev/template.categories: '["school", "collaboration", "productivity"]' kubero.dev/template.title: Moodle kubero.dev/template.website: https://moodle.org/ labels: @@ -38,32 +34,25 @@ spec: name: moodle deploymentstrategy: docker addons: - - displayName: MariaDB + # Moodle 5.3 needs PostgreSQL 17+ (public/admin/environment.xml). + - displayName: PostgreSQL (CloudNativePG) env: [] - icon: /img/addons/mysql.svg + icon: /img/addons/pgsql.svg id: kubero-operator - kind: MariaDB + kind: Cluster resourceDefinitions: - MariaDB: - apiVersion: k8s.mariadb.com/v1alpha1 - kind: MariaDB + Cluster: + apiVersion: postgresql.cnpg.io/v1 + kind: Cluster metadata: - name: '{{STACKBLAZE_APP_NAME}}-mysql' + name: '{{STACKBLAZE_APP_NAME}}-postgresql' spec: - metrics: - enabled: true - rootPasswordSecretKeyRef: - name: '{{STACKBLAZE_APP_NAME}}-mysql-root' - key: password - database: moodle - username: moodle - passwordSecretKeyRef: - name: '{{STACKBLAZE_APP_NAME}}-mysql-app' - key: password + instances: 1 + imageName: ghcr.io/cloudnative-pg/postgresql:17 + primaryUpdateStrategy: unsupervised storage: + storageClass: smart size: 5Gi - storageClassName: fast - replicas: 1 resources: requests: cpu: 100m @@ -71,74 +60,112 @@ spec: limits: cpu: '1' memory: 1Gi - rootSecret: + bootstrap: + initdb: + database: moodle + owner: moodle + secret: + name: '{{STACKBLAZE_APP_NAME}}-postgresql-app' + postInitApplicationSQL: + - GRANT ALL ON SCHEMA public TO moodle + - GRANT CREATE ON SCHEMA public TO moodle + - ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO moodle + enableSuperuserAccess: true + superuserSecret: + name: '{{STACKBLAZE_APP_NAME}}-postgresql-superuser' + superuserSecret: apiVersion: v1 kind: Secret metadata: - name: '{{STACKBLAZE_APP_NAME}}-mysql-root' - type: Opaque + name: '{{STACKBLAZE_APP_NAME}}-postgresql-superuser' + type: kubernetes.io/basic-auth stringData: - password: moodle - appSecret: + username: postgres + password: '{{STACKBLAZE_GEN_ALNUM:24}}' + appUserSecret: apiVersion: v1 kind: Secret metadata: - name: '{{STACKBLAZE_APP_NAME}}-mysql-app' - type: Opaque + name: '{{STACKBLAZE_APP_NAME}}-postgresql-app' + type: kubernetes.io/basic-auth stringData: - password: moodle + username: moodle + password: '{{STACKBLAZE_GEN_ALNUM:24}}' + # Platform email (README "Email contract"): password resets, enrolment, + # forum and assignment notifications. Moodle has no email environment + # variables of its own; the image's config.php reads the injected SMTP_* + # (smtphosts, smtpuser, smtppass, noreplyaddress) and does nothing without + # SMTP_HOST, so no mapping is needed here. + - displayName: Email + env: [] + icon: /img/addons/email.svg + id: kubero-smtp + kind: Smtp + resourceDefinitions: {} envVars: - - name: MOODLE_DATABASE_TYPE - value: mariadb - - name: MOODLE_DATABASE_HOST - value: '$(MYSQL_HOST)' - - name: MOODLE_DATABASE_PORT_NUMBER - value: '$(MYSQL_PORT)' - - name: MOODLE_DATABASE_NAME - value: '$(MYSQL_DATABASE)' - - name: MOODLE_DATABASE_USER - value: '$(MYSQL_USER)' - - name: MOODLE_DATABASE_PASSWORD - value: '$(MYSQL_PASSWORD)' - - name: MOODLE_USERNAME + - name: MOODLE_DB_HOST + value: '$(PGHOST)' + - name: MOODLE_DB_PORT + value: '$(PGPORT)' + - name: MOODLE_DB_NAME + value: '$(PGDATABASE)' + - name: MOODLE_DB_USER + value: '$(PGUSER)' + - name: MOODLE_DB_PASSWORD + value: '$(PGPASSWORD)' + # The site address ($CFG->wwwroot). + - name: MOODLE_URL + value: '{{STACKBLAZE_APP_URL}}' + # First-start install (moodle-start). Changing these later does nothing. + - name: MOODLE_ADMIN_USER value: admin - - name: MOODLE_PASSWORD - value: replace-with-openssl-rand-base64-32 - - name: MOODLE_EMAIL + - name: MOODLE_ADMIN_PASSWORD + value: '{{STACKBLAZE_GEN_ALNUM:24}}' + - name: MOODLE_ADMIN_EMAIL value: admin@example.com - - name: MOODLE_HOST - value: '{{STACKBLAZE_APP_URL}}' - - name: MOODLE_REVERSEPROXY - value: 'yes' - - name: MOODLE_SSLPROXY - value: 'yes' - - name: PHP_MEMORY_LIMIT - value: 512M + - name: MOODLE_SITE_NAME + value: My Moodle site + - name: MOODLE_SITE_SHORTNAME + value: moodle + # moodledata: course files, uploads, submissions, backups, language packs and + # the shared cache. Not served by Apache (only public/ is). extraVolumes: - accessModes: - ReadWriteMany emptyDir: false - mountPath: /bitnami/moodle - name: moodle-app - size: 5Gi - storageClass: shared - - accessModes: - - ReadWriteMany - emptyDir: false - mountPath: /bitnami/moodledata - name: '{{STACKBLAZE_APP_NAME}}-data' - size: 5Gi + mountPath: /var/www/moodledata + name: '{{STACKBLAZE_APP_NAME}}-moodledata' + size: 10Gi storageClass: shared cronjobs: [] + # One image, two processes: the web pod serves Moodle (PROC_TYPE=web), the + # worker runs admin/cli/cron.php every minute (PROC_TYPE=worker). Both mount + # moodledata. web: replicaCount: 1 worker: - replicaCount: 0 + replicaCount: 1 + resources: + requests: + cpu: 100m + memory: 384Mi + limits: + cpu: '1' + memory: 1Gi + # A static file Apache serves without PHP or the database. + healthcheck: + enabled: true + path: /pix/moodlelogo.svg + startupSeconds: 600 + timeoutSeconds: 5 + periodSeconds: 10 image: containerPort: '80' - pullPolicy: Always - repository: docker.io/elestio/moodle - tag: latest + pullPolicy: IfNotPresent + # Built by .github/workflows/build-moodle.yaml from services/moodle/image: + # Moodle 5.3.1 (official package, checksum-pinned) on php:8.4-apache. + repository: ghcr.io/stackblaze/stack-templates/moodle + tag: 5.3.1-1 run: securityContext: readOnlyRootFilesystem: false diff --git a/services/moodle/icon.png b/services/moodle/icon.png index 7b1fa26f..4adec28c 100644 Binary files a/services/moodle/icon.png and b/services/moodle/icon.png differ diff --git a/services/moodle/image/Dockerfile b/services/moodle/image/Dockerfile new file mode 100644 index 00000000..ec24793d --- /dev/null +++ b/services/moodle/image/Dockerfile @@ -0,0 +1,69 @@ +# Moodle publishes no runtime image (Bitnami's moved behind a paywall in 2025), +# so the catalog template runs this one: the official Moodle 5.3.1 release +# package (checksum-pinned) on the official PHP 8.4 Apache image. +# +# - Code is read-only in the image (root-owned). Plugins and upgrades come from +# a new image, never from the web UI ($CFG->disableupdateautodeploy). +# - moodledata is the template's volume at /var/www/moodledata. +# - config.php reads the database, URL and email from the environment. +# - moodle-start installs Moodle from the command line on the first start (no +# web installer), runs pending upgrades, then starts Apache. With +# PROC_TYPE=worker it runs Moodle's cron every minute instead. +FROM docker.io/library/php:8.4.27-apache-bookworm + +ARG MOODLE_VERSION=5.3.1 +ARG MOODLE_SHA256=820ee2bcd89acc6b91df255b2010bbbab108f29952ab78895a79c4feabf541e7 + +# PHP extensions Moodle 5.3 needs (public/admin/environment.xml): pgsql, intl, +# zip, gd, soap, exif and opcache on top of the image's built-ins (sodium, +# mbstring, curl, openssl, dom, xml...). Ghostscript is for annotating PDF +# assignment submissions. Build-only packages are removed again. +RUN set -eux; \ + savedAptMark="$(apt-mark showmanual)"; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libpq-dev libicu-dev libzip-dev libpng-dev libjpeg62-turbo-dev \ + libfreetype6-dev libwebp-dev libxml2-dev; \ + docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \ + docker-php-ext-install -j"$(nproc)" pgsql intl zip gd soap exif opcache; \ + apt-mark auto '.*' > /dev/null; \ + apt-mark manual $savedAptMark; \ + find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ + | sort -u | xargs -r dpkg-query --search | cut -d: -f1 | sort -u | xargs -rt apt-mark manual; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + apt-get install -y --no-install-recommends ghostscript; \ + rm -rf /var/lib/apt/lists/* + +RUN set -eux; \ + curl -fsSL -o /tmp/moodle.tgz "https://packaging.moodle.org/stable503/moodle-${MOODLE_VERSION}.tgz"; \ + echo "${MOODLE_SHA256} /tmp/moodle.tgz" | sha256sum -c -; \ + tar -xzf /tmp/moodle.tgz -C /var/www; \ + rm /tmp/moodle.tgz; \ + grep -q "'${MOODLE_VERSION} " /var/www/moodle/public/version.php; \ + mkdir -p /var/www/moodledata /var/cache/moodle; \ + chown www-data:www-data /var/www/moodledata /var/cache/moodle + +# Moodle's own libraries ship in public/lib; upstream also expects the +# Composer runtime dependencies (vendor/, outside the web root) installed from +# its composer.lock, without the developer packages. +COPY --from=docker.io/library/composer:2.11.2 /usr/bin/composer /usr/local/bin/composer +RUN set -eux; \ + cd /var/www/moodle; \ + COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --classmap-authoritative --no-interaction --no-progress; \ + rm -rf /usr/local/bin/composer /root/.composer /root/.cache + +COPY config.php /var/www/moodle/config.php +COPY php.ini /usr/local/etc/php/conf.d/moodle.ini +COPY apache.conf /etc/apache2/sites-available/000-default.conf +COPY stackblaze-install.php /usr/local/lib/stackblaze/install.php +COPY moodle-start /usr/local/bin/moodle-start +RUN set -eux; \ + chmod 0755 /usr/local/bin/moodle-start; \ + a2enmod rewrite headers remoteip > /dev/null; \ + echo 'ServerName localhost' > /etc/apache2/conf-enabled/servername.conf; \ + php -l /var/www/moodle/config.php; php -l /usr/local/lib/stackblaze/install.php + +WORKDIR /var/www/moodle +EXPOSE 80 +CMD ["/usr/local/bin/moodle-start"] diff --git a/services/moodle/image/apache.conf b/services/moodle/image/apache.conf new file mode 100644 index 00000000..a11c060f --- /dev/null +++ b/services/moodle/image/apache.conf @@ -0,0 +1,24 @@ +# StackBlaze: Moodle 5.1+ serves only public/; config.php, the CLI scripts and +# the libraries outside it are not reachable from the web. + + DocumentRoot /var/www/moodle/public + + Options -Indexes +FollowSymLinks + AllowOverride None + Require all granted + AcceptPathInfo On + DirectoryIndex index.php + # Moodle router ($CFG->routerconfigured). + FallbackResource /r.php + + # Moodle is installed from the command line on the first start; the web + # installer is never needed. + + Require all denied + + # Client addresses from the platform's ingress. + RemoteIPHeader X-Forwarded-For + RemoteIPInternalProxy 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + diff --git a/services/moodle/image/config.php b/services/moodle/image/config.php new file mode 100644 index 00000000..42707683 --- /dev/null +++ b/services/moodle/image/config.php @@ -0,0 +1,80 @@ +dbtype = 'pgsql'; +$CFG->dblibrary = 'native'; +$CFG->dbhost = getenv('MOODLE_DB_HOST'); +$CFG->dbname = getenv('MOODLE_DB_NAME'); +$CFG->dbuser = getenv('MOODLE_DB_USER'); +$CFG->dbpass = getenv('MOODLE_DB_PASSWORD'); +$CFG->prefix = 'mdl_'; +$CFG->dboptions = [ + 'dbpersist' => false, + 'dbsocket' => false, + 'dbport' => (int) (getenv('MOODLE_DB_PORT') ?: 5432), +]; + +// The site address (MOODLE_URL, the app URL by default). Moodle redirects every +// other host name here, so change MOODLE_URL when you add a custom domain. +$CFG->wwwroot = rtrim((string) getenv('MOODLE_URL'), '/'); +$CFG->dataroot = '/var/www/moodledata'; +$CFG->admin = 'admin'; +$CFG->directorypermissions = 02777; + +// TLS ends at the platform's edge. +$CFG->sslproxy = true; +// Apache sends unknown paths to r.php (apache.conf FallbackResource). +$CFG->routerconfigured = true; + +// moodledata is a shared network volume: keep the per-node cache on local +// disk, and sessions in the database (no file locks on the volume). +$CFG->localcachedir = '/var/cache/moodle'; +$CFG->session_handler_class = '\core\session\database'; +$CFG->session_database_acquire_lock_timeout = 120; + +// Code execution from the web UI is off: +// - no plugin installs or updates from Site administration (the code in the +// image is read-only anyway; add plugins by building a new image); +// - executable paths cannot be changed from the web. +$CFG->disableupdateautodeploy = true; +$CFG->preventexecpath = true; +$CFG->pathtogs = '/usr/bin/gs'; +$CFG->pathtophp = '/usr/local/bin/php'; +$CFG->pathtodu = '/usr/bin/du'; +$CFG->aspellpath = ''; +$CFG->pathtodot = ''; + +// Cron runs in the worker (admin/cli/cron.php every minute), never from the web. +$CFG->cronclionly = true; + +// Email through the platform Email add-on (SMTP_* are injected while it is +// connected). SMTP_FROM is "address" or "Name
"; the relay accepts +// only that sender, so every message goes out from it (Reply-To keeps the +// real author). +if (getenv('SMTP_HOST')) { + $port = (int) (getenv('SMTP_PORT') ?: 587); + $CFG->smtphosts = getenv('SMTP_HOST') . ':' . $port; + $CFG->smtpsecure = $port === 465 ? 'ssl' : 'tls'; + $CFG->smtpauthtype = 'LOGIN'; + $CFG->smtpuser = (string) getenv('SMTP_USER'); + $CFG->smtppass = (string) getenv('SMTP_PASSWORD'); + $from = trim((string) getenv('SMTP_FROM')); + if (preg_match('/<([^>]+)>/', $from, $m)) { + $from = trim($m[1]); + } + if ($from !== '') { + $CFG->noreplyaddress = $from; + } + // Empty = never send from a user's own address (can_send_from_real_email_address). + $CFG->allowedemaildomains = ''; +} + +require_once(__DIR__ . '/lib/setup.php'); +// There is no php closing tag in this file, it is intentional because it +// prevents trailing whitespace problems! diff --git a/services/moodle/image/moodle-start b/services/moodle/image/moodle-start new file mode 100755 index 00000000..d203d3f8 --- /dev/null +++ b/services/moodle/image/moodle-start @@ -0,0 +1,38 @@ +#!/bin/bash +# StackBlaze: start Moodle. +# web (default): wait for the database, install or upgrade Moodle from the +# command line, then start Apache. Apache never starts on a half-installed +# site, so the web installer is never reachable. +# worker (PROC_TYPE=worker): run Moodle's cron every minute (scheduled and +# background tasks: forum and notification mail, completion, cleanup). +set -euo pipefail + +as_www() { setpriv --reuid=www-data --regid=www-data --init-groups "$@"; } + +# The volume may arrive root-owned. +if [ "$(stat -c %U /var/www/moodledata)" != "www-data" ]; then + chown www-data:www-data /var/www/moodledata +fi + +as_www php /usr/local/lib/stackblaze/install.php wait + +if [ "${PROC_TYPE:-web}" = "worker" ]; then + until as_www php /usr/local/lib/stackblaze/install.php ready; do + echo "[stackblaze] cron: waiting for the web pod to finish installing Moodle" + sleep 15 + done + echo "[stackblaze] cron: running admin/cli/cron.php every minute" + trap 'exit 0' TERM INT + while true; do + start=$(date +%s) + as_www php /var/www/moodle/admin/cli/cron.php --keep-alive=0 > /tmp/cron.log 2>&1 \ + || { echo "[stackblaze] cron run failed:"; tail -n 20 /tmp/cron.log; } + # Error lines only; the full log of the last run is /tmp/cron.log. + grep -E 'Exception|Fatal|Error' /tmp/cron.log | head -n 5 || true + left=$(( 60 - ($(date +%s) - start) )) + if [ "$left" -gt 0 ]; then sleep "$left" & wait $! || true; fi + done +fi + +as_www php /usr/local/lib/stackblaze/install.php install +exec apache2-foreground diff --git a/services/moodle/image/php.ini b/services/moodle/image/php.ini new file mode 100644 index 00000000..ef016df9 --- /dev/null +++ b/services/moodle/image/php.ini @@ -0,0 +1,14 @@ +; StackBlaze: PHP settings for Moodle. +memory_limit = 256M +upload_max_filesize = 100M +post_max_size = 110M +max_execution_time = 300 +max_input_vars = 5000 +zend.exception_ignore_args = On +expose_php = Off +; The code in the image never changes at runtime. +opcache.enable = 1 +opcache.memory_consumption = 256 +opcache.interned_strings_buffer = 16 +opcache.max_accelerated_files = 30000 +opcache.validate_timestamps = 0 diff --git a/services/moodle/image/stackblaze-install.php b/services/moodle/image/stackblaze-install.php new file mode 100644 index 00000000..416d4eee --- /dev/null +++ b/services/moodle/image/stackblaze-install.php @@ -0,0 +1,146 @@ + /tmp/moodle-install.log 2>&1'; + $code = run($cmd); + if ($code !== 0) { + say("install failed (exit $code); last lines:"); + run('tail -n 30 /tmp/moodle-install.log'); + exit(1); + } + // Check the result, not just the exit code. + $user = getenv('MOODLE_ADMIN_USER') ?: 'admin'; + $hash = value($db, "SELECT password FROM mdl_user WHERE username = $1 AND deleted = 0", [$user]); + if (state($db) !== 'complete' || !$hash || !password_verify($pass, $hash)) { + say('install finished but the site or the admin login is missing'); + exit(1); + } + // Let people pick light or dark mode (Boost colour modes, off upstream). + // A first-install default only: admins can switch it off again. + run('php ' . escapeshellarg("$dir/admin/cli/cfg.php") . ' --component=theme_boost --name=enablecolourmodes --set=1 > /dev/null'); + say("Moodle installed; sign in as '$user' with MOODLE_ADMIN_PASSWORD"); +} else { + // A newer image: run the upgrade before serving pages. + $code = run('php ' . escapeshellarg("$dir/admin/cli/upgrade.php") . ' --is-pending > /dev/null 2>&1'); + if ($code === 2) { + say('upgrading Moodle to the version in this image'); + if (run('php ' . escapeshellarg("$dir/admin/cli/upgrade.php") . ' --non-interactive') !== 0) { + say('upgrade failed'); + exit(1); + } + } else if ($code !== 0) { + say("upgrade check failed (exit $code)"); + exit(1); + } + say('Moodle is installed and up to date'); +} +value($db, 'SELECT pg_advisory_unlock(803530)'); +exit(0); diff --git a/services/moodle/screenshot-course.png b/services/moodle/screenshot-course.png new file mode 100644 index 00000000..930cc207 Binary files /dev/null and b/services/moodle/screenshot-course.png differ diff --git a/services/moodle/screenshot-dashboard.png b/services/moodle/screenshot-dashboard.png new file mode 100644 index 00000000..fc7c73b6 Binary files /dev/null and b/services/moodle/screenshot-dashboard.png differ diff --git a/services/moodle/screenshot-quiz.png b/services/moodle/screenshot-quiz.png new file mode 100644 index 00000000..60f7e4c4 Binary files /dev/null and b/services/moodle/screenshot-quiz.png differ