commit 2eff037f6bc623b8826ce8b7fea63bc21d4dc45f Author: Paul Date: Tue Jan 12 08:49:20 2021 +0100 Initial commit diff --git a/000-default.conf b/000-default.conf new file mode 100644 index 0000000..9853c50 --- /dev/null +++ b/000-default.conf @@ -0,0 +1,14 @@ + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html + + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, + # error, crit, alert, emerg. + LogLevel warn + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + Alias /wiki /var/www/html/index.php + Alias /uploads /var/www/localstore/images + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ec9e2dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,87 @@ +FROM mediawiki:1.35 + +ARG COMPOSER_VERSION=2.0.8 + +ENV \ + WG_SITENAME="Test Wiki" \ + WG_SCRIPT_PATH="" \ + WG_SERVER="https://wiki.example.com" \ + SEMANTIC_URL="wiki.example.com" \ + WG_ENABLE_UPLOADS="false" \ + WG_ENABLE_EMAIL="false" \ + WG_UPLOAD_PATH="/uploads" \ + WG_META_NAMESPACE="Meta" \ + WG_LANGUAGE_CODE="en" \ + MEDIAWIKI_ADMIN_USER="admin" \ + MEDIAWIKI_ADMIN_PASS="password" \ + WG_DB_TYPE="sqlite" \ + WG_DB_SERVER="" \ + WG_DB_NAME="my_wiki" \ + WG_DB_PASSWORD="password" \ + WG_DB_PREFIX="" \ + WG_DB_MWSCHEMA="" \ + WG_DATABASE_DIR="/var/www/data" \ + WG_SECRET_KEY="0000000000000000000000000000000000000000000000000000000000000000" \ + WG_EMERGENCY_CONTACT="admin@example.com" \ + WG_PASSWORD_SENDER="wiki@example.com" \ + ALLOW_PUBLIC_REGISTRATION="false" \ + ALLOW_PUBLIC_EDIT="false" \ + ALLOW_PUBLIC_READ="true" \ + DISABLE_ICONS="false" \ + DEBUG="false" + +# System dependencies for extensions +RUN set -eu; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + zip \ + unzip \ + libpq-dev \ + cron \ + rclone \ + ; \ + rm -rf /var/lib/apt/lists/* + +# PHP extensions +RUN set -eu; \ + docker-php-ext-install -j$(nproc) pgsql; \ + docker-php-ext-install -j$(nproc) pdo_pgsql + +RUN set -eu; \ + mkdir /var/www/conf; \ + mkdir -p /var/www/localstore/smwconfig; \ + mkdir -p /var/www/localstore/images + +# Non-composer based extensions +# JsonConfig required by Graph. +RUN set -euo pipefail; \ + cd /var/www/html/extensions; \ + curl https://extdist.wmflabs.org/dist/extensions/JsonConfig-REL1_35-a0bdbfb.tar.gz |tar -xz; \ + curl https://extdist.wmflabs.org/dist/extensions/Graph-REL1_35-fa2b9af.tar.gz |tar -xz; \ + curl https://extdist.wmflabs.org/dist/extensions/SubPageList3-REL1_35-622c298.tar.gz| tar -xz; \ + curl https://extdist.wmflabs.org/dist/extensions/MsUpload-REL1_35-5998b96.tar.gz| tar -xz; \ + curl https://extdist.wmflabs.org/dist/extensions/TemplateStyles-REL1_35-7743810.tar.gz| tar -xz + +# Install composer packages +RUN set -eu; \ + curl -o /tmp/composer-setup.php https://getcomposer.org/installer; \ + curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig; \ + php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }"; \ + php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer --version=${COMPOSER_VERSION}; \ + rm -rf /tmp/composer-setup.php; \ + ln -s /var/www/conf/LocalSettings.local.php /var/www/html/LocalSettings.local.php; \ + ln -s /var/www/conf/LocalSettings.php /var/www/html/LocalSettings.php +COPY composer.local.json /var/www/html +RUN composer update --no-dev + +# Place config files +COPY conf/* /var/www/conf/ +COPY 000-default.conf /etc/apache2/sites-available + +# Place our maintenence and setup scripts +COPY scripts/* /usr/local/bin/ +RUN chmod 755 /usr/local/bin/* + +# Add crontab file in the cron directory +ADD crontab /etc/crontab +RUN chmod 0644 /etc/crontab diff --git a/composer.local.json b/composer.local.json new file mode 100644 index 0000000..7ec8c49 --- /dev/null +++ b/composer.local.json @@ -0,0 +1,10 @@ +{ + "require": { + "mediawiki/semantic-bundle": "~4.0", + "mediawiki/semantic-scribunto": "~2.1", + + "mediawiki/mermaid": "~3.0", + + "wikimedia/css-sanitizer": "2.0.1" + } +} \ No newline at end of file diff --git a/conf/LocalSettings.local.php b/conf/LocalSettings.local.php new file mode 100644 index 0000000..eca9a28 --- /dev/null +++ b/conf/LocalSettings.local.php @@ -0,0 +1,3 @@ + "favicon-202x202.png", + "2x" => "favicon-202x202.png" +]; + +# Footer icons + +if (getenv("DISABLE_ICONS")) { + unset( $wgFooterIcons['poweredby'] ); +} + +# Responsive +$wgVectorResponsive = true; \ No newline at end of file diff --git a/crontab b/crontab new file mode 100644 index 0000000..4a4835e --- /dev/null +++ b/crontab @@ -0,0 +1,12 @@ +# Reference: https://www.semantic-mediawiki.org/wiki/Cron_jobs + +# Every day at 07:45, Update Special Pages +45 7 * * * root /usr/local/bin/updateSpecialPages.sh > /proc/1/fd/1 2>/proc/1/fd/2 + +# SemanticMediaWiki recommended maintenance +30 * * * * root /usr/local/bin/updateEntityCollation.sh > /proc/1/fd/1 2>/proc/1/fd/2 +15 9 * * SAT root /usr/local/bin/rebuildData.sh > /proc/1/fd/1 2>/proc/1/fd/2 +15 9 * * SUN root /usr/local/bin/setupStore.sh > /proc/1/fd/1 2>/proc/1/fd/2 +15 3 1 * * root php /usr/local/bin/removeDuplicateEntities.sh > /proc/1/fd/1 2>/proc/1/fd/2 + +# file requires a trailing newline! diff --git a/scripts/crontab-foreground b/scripts/crontab-foreground new file mode 100644 index 0000000..a2ae5ea --- /dev/null +++ b/scripts/crontab-foreground @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +cron -f -L 15 \ No newline at end of file diff --git a/scripts/db-setup.sh b/scripts/db-setup.sh new file mode 100644 index 0000000..122fcab --- /dev/null +++ b/scripts/db-setup.sh @@ -0,0 +1,39 @@ +#!/bin/bash +set -euo pipefail + +cd /var/www/html/ + +# The install script doesn't want there to be a LocalSettings.php file +echo Killing LocalSettings.php +echo + +rm /var/www/html/LocalSettings.php + +echo Install.php +echo + +php maintenance/install.php --dbtype "${MEDIAWIKI_DB_TYPE}" --dbname "${MEDIAWIKI_DB_NAME}" --dbuser "${MEDIAWIKI_DB_USER}" --dbport "${MEDIAWIKI_DB_PORT}" --dbpass "${MEDIAWIKI_DB_PASSWORD}" --scriptpath "/var/www/html/" --dbserver "${MEDIAWIKI_DB_HOST}" --pass "${MEDIAWIKI_ADMIN_PASS}" --dbpath "${MEDIAWIKI_DATABASE_DIR}" "${MEDIAWIKI_SITE_NAME}" "${MEDIAWIKI_ADMIN_USER}" + +# Now, we're going to replace the LocalSettings.php file that install.php just generated with ours +# This way, update.php will work. +rm /var/www/html/LocalSettings.php +ln -s /var/www/conf/LocalSettings.php /var/www/html/LocalSettings.php + +echo LocalSettings.php restored +echo + +echo Creating localstore +echo + +# Copy the htaccess file +mkdir -p /var/www/localstore/images +mkdir -p /var/www/localstore/smwconfig +cp /var/www/html/images/* /var/www/localstore/images +chown -R www-data:www-data /var/www/localstore + +# Run update.php, to set up all of the extensions + +echo update.php +echo + +php maintenance/update.php --quick \ No newline at end of file diff --git a/scripts/ensure-permissions.sh b/scripts/ensure-permissions.sh new file mode 100644 index 0000000..9700094 --- /dev/null +++ b/scripts/ensure-permissions.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -euo pipefail + +# Copy the htaccess file +mkdir -p /var/www/localstore/images +mkdir -p /var/www/localstore/smwconfig +cp /var/www/html/images/* /var/www/localstore/images +chown -R www-data:www-data /var/www/localstore +chown -R www-data:www-data /var/www/data diff --git a/scripts/mwjobrunner b/scripts/mwjobrunner new file mode 100644 index 0000000..f2871f1 --- /dev/null +++ b/scripts/mwjobrunner @@ -0,0 +1,23 @@ +#!/bin/bash +set -euo pipefail + +# From https://www.mediawiki.org/wiki/Manual:Job_queue +IP=/var/www/html +RJ=$IP/maintenance/runJobs.php +echo Starting job service... +# Wait a minute after the server starts up to give other processes time to get started +sleep 60 +echo Started. +while true; do + # Job types that need to be run ASAP mo matter how many of them are in the queue + # Those jobs should be very "cheap" to run + php $RJ --type="enotifNotify" + php $RJ --type="htmlCacheUpdate" --maxjobs=50 + # Everything else, limit the number of jobs on each batch + # The --wait parameter will pause the execution here until new jobs are added, + # to avoid running the loop without anything to do + php $RJ --wait --maxjobs=10 + # Wait some seconds to let the CPU do other things, like handling web requests, etc + echo Waiting for 10 seconds... + sleep 10 +done \ No newline at end of file diff --git a/scripts/rebuildData.sh b/scripts/rebuildData.sh new file mode 100644 index 0000000..c6bd418 --- /dev/null +++ b/scripts/rebuildData.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -euo pipefail + +echo rebuildData +echo + +php /var/www/html/extensions/SemanticMediaWiki/maintenance/rebuildData.php -d 100 +echo rebuildData finished \ No newline at end of file diff --git a/scripts/removeDuplicateEntities.sh b/scripts/removeDuplicateEntities.sh new file mode 100644 index 0000000..c5a5695 --- /dev/null +++ b/scripts/removeDuplicateEntities.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -euo pipefail + +echo removeDuplicateEntities +echo + +/usr/local/bin/php /var/www/html/extensions/SemanticMediaWiki/maintenance/removeDuplicateEntities.php +echo removeDuplicateEntities finished + diff --git a/scripts/run-update.sh b/scripts/run-update.sh new file mode 100644 index 0000000..6326a2b --- /dev/null +++ b/scripts/run-update.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -euo pipefail + +/usr/local/bin/php maintenance/update.php \ No newline at end of file diff --git a/scripts/setupStore.sh b/scripts/setupStore.sh new file mode 100644 index 0000000..539377a --- /dev/null +++ b/scripts/setupStore.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -euo pipefail + +echo setupStore +echo + +/usr/local/bin/php /var/www/html/extensions/SemanticMediaWiki/maintenance/setupStore.php --skip-import +echo setupStore finished \ No newline at end of file diff --git a/scripts/updateEntityCollation.sh b/scripts/updateEntityCollation.sh new file mode 100644 index 0000000..28288ff --- /dev/null +++ b/scripts/updateEntityCollation.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -euo pipefail + +echo updateEntityCollation +echo + +/usr/local/bin/php /var/www/html/extensions/SemanticMediaWiki/maintenance/updateEntityCollation.php +echo updateEntityCollation finished \ No newline at end of file diff --git a/scripts/updateSpecialPages.sh b/scripts/updateSpecialPages.sh new file mode 100644 index 0000000..9ac6ec6 --- /dev/null +++ b/scripts/updateSpecialPages.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -euo pipefail + +echo updateSpecialPages +echo + +/usr/local/bin/php /var/www/html/maintenance/updateSpecialPages.php +echo updateSpecialPages finished \ No newline at end of file