From 6649b7cd3351954681e42d3f04045702971796ca Mon Sep 17 00:00:00 2001 From: Lens0021 / Leslie Date: Tue, 21 May 2024 19:29:55 +0900 Subject: [PATCH] Improve docker layers (#844) * Improve docker layers * fix: Embed LocalSettings.php in femiwiki image * Load TorBlock * Update Dockerfile * Load RealMe and GoogleNewsSitemap * Ignore phpactor * actions: Reduce timeout to 2 minutes * fix: Do not embed LocalSettings.php in mediawiki image * fix: Docker name in github actions workflow --- .github/workflows/docker-femiwiki.yml | 12 ++++----- .github/workflows/docker-mediawiki.yml | 2 +- .gitignore | 3 +++ docker-compose.yml | 4 +-- dockers/femiwiki/Dockerfile | 26 ++++++++++++++++--- .../{mediawiki => femiwiki}/LocalSettings.php | 9 +++++++ dockers/femiwiki/README.md | 12 +++++++-- .../composer.local.json | 0 dockers/mediawiki/Dockerfile | 3 --- dockers/mediawiki/README.md | 4 +++ 10 files changed, 57 insertions(+), 18 deletions(-) rename dockers/{mediawiki => femiwiki}/LocalSettings.php (99%) rename dockers/{mediawiki => femiwiki}/composer.local.json (100%) diff --git a/.github/workflows/docker-femiwiki.yml b/.github/workflows/docker-femiwiki.yml index 5b755542..74b8e320 100644 --- a/.github/workflows/docker-femiwiki.yml +++ b/.github/workflows/docker-femiwiki.yml @@ -24,9 +24,9 @@ jobs: - name: Edit configuration run: | mv development/secret.php.example development/secret.php - mv dockers/mediawiki/LocalSettings.php development + mv dockers/femiwiki/LocalSettings.php development mv dockers/femiwiki/Hotfix.php development - sed -i -r 's~ghcr\.io\/femiwiki\/mediawiki:.+~ghcr\.io\/femiwiki\/mediawiki:docker-test~' docker-compose.yml + sed -i -r 's~ghcr\.io\/femiwiki\/femiwiki:.+~ghcr\.io\/femiwiki\/femiwiki:docker-test~' docker-compose.yml - run: | echo "version=$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_OUTPUT @@ -36,11 +36,11 @@ jobs: with: context: '{{ defaultContext }}:dockers/femiwiki' platforms: linux/amd64 - cache-from: ghcr.io/femiwiki/mediawiki:latest + cache-from: ghcr.io/femiwiki/femiwiki:latest cache-to: mode=max,type=local,dest=/tmp/.buildx-cache load: true push: false - tags: ghcr.io/femiwiki/mediawiki:docker-test + tags: ghcr.io/femiwiki/femiwiki:docker-test - name: Initialize docker swarm and start services run: | @@ -48,7 +48,7 @@ jobs: docker stack deploy -c docker-compose.yml mediawiki - name: Access 127.0.0.1:8080 until success - timeout-minutes: 3 + timeout-minutes: 2 run: | echo 'Waiting for http...' until curl -sLfo /dev/null 127.0.0.1:8080; do @@ -96,7 +96,7 @@ jobs: context: '{{defaultContext}}:dockers/femiwiki' platforms: linux/amd64,linux/arm64 cache-from: | - ghcr.io/femiwiki/mediawiki:latest + ghcr.io/femiwiki/femiwiki:latest type=local,src=/tmp/.buildx-cache cache-to: mode=max,type=inline load: false diff --git a/.github/workflows/docker-mediawiki.yml b/.github/workflows/docker-mediawiki.yml index 22d7f793..3ec890d3 100644 --- a/.github/workflows/docker-mediawiki.yml +++ b/.github/workflows/docker-mediawiki.yml @@ -1,7 +1,7 @@ name: 'Docker: mediawiki' env: - TAG: '2.0.0' + TAG: '2.0.1' on: push: diff --git a/.gitignore b/.gitignore index da09f79c..8e12d534 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ /development/Hotfix.php /development/analytics-credentials-file.json +# PHP +.phpactor.json + # Composer /vendor diff --git a/docker-compose.yml b/docker-compose.yml index 0b43da6a..0aaf3af0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: http: - image: ghcr.io/femiwiki/femiwiki:latest + image: ghcr.io/femiwiki/femiwiki:dev command: caddy run ports: - 8080:8080 @@ -21,7 +21,7 @@ services: options: max-size: '100m' fastcgi: - image: ghcr.io/femiwiki/femiwiki:latest + image: ghcr.io/femiwiki/femiwiki:dev volumes: # Mount secret.php, LocalSettings.php and site-list.xml - ./development:/a:ro diff --git a/dockers/femiwiki/Dockerfile b/dockers/femiwiki/Dockerfile index 21a72366..bc4fec93 100644 --- a/dockers/femiwiki/Dockerfile +++ b/dockers/femiwiki/Dockerfile @@ -8,12 +8,21 @@ # FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/caddy:1.0.0 AS caddy -FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/mediawiki:1.1.0 +FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/femiwiki-extensions:1.2.0 AS extensions + +FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/mediawiki:2.0.0 # Set timezone ENV TZ=Asia/Seoul RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +# Install Mediawiki and extensions +RUN mv /mediawiki /srv/femiwiki.com/ &&\ + rm -rf /srv/femiwiki.com/extensions &&\ + rm -rf /srv/femiwiki.com/skins +COPY --from=extensions /mediawiki/extensions /srv/femiwiki.com/extensions +COPY --from=extensions /mediawiki/skins /srv/femiwiki.com/skins + # Install Caddy COPY --from=caddy /usr/bin/caddy /usr/bin/caddy @@ -23,14 +32,23 @@ RUN mkdir -p \ /etc/caddy \ /usr/share/caddy -# Install MediaWiki -RUN mv /mediawiki /srv/femiwiki.com - WORKDIR /srv/femiwiki.com +COPY composer.local.json /srv/femiwiki.com + +RUN COMPOSER_HOME=/composer /usr/bin/composer update --no-dev --working-dir /srv/femiwiki.com + +# Web server should be able to write 'extensions/Widgets/compiled_templates' +# directory Required by 'Widgets' extension +# Reference: https://www.mediawiki.org/wiki/Extension:Widgets +RUN chmod o+w /srv/femiwiki.com/extensions/Widgets/compiled_templates + # Ship femiwiki resources COPY --chown=www-data:www-data resources /srv/femiwiki.com/ COPY --chown=www-data:www-data ["site-list.xml", "Hotfix.php", "/a/"] +RUN mkdir /mediawiki/ + +COPY --chown=www-data LocalSettings.php /a/ EXPOSE 80 EXPOSE 443 diff --git a/dockers/mediawiki/LocalSettings.php b/dockers/femiwiki/LocalSettings.php similarity index 99% rename from dockers/mediawiki/LocalSettings.php rename to dockers/femiwiki/LocalSettings.php index 5581f41d..626ed263 100644 --- a/dockers/mediawiki/LocalSettings.php +++ b/dockers/femiwiki/LocalSettings.php @@ -590,6 +590,9 @@ $wgGrantPermissions['editinterface']['gadgets-edit'] = true; $wgGrantPermissions['editinterface']['gadgets-definition-edit'] = true; +// GoogleNewsSitemap +wfLoadExtension( 'GoogleNewsSitemap' ); + // GoogleSiteSearch wfLoadExtension( 'GoogleSiteSearch' ); $wgGoogleSiteSearchCSEID = '44508684d5c0e489c'; @@ -767,6 +770,9 @@ // QuickInstantCommons wfLoadExtension( 'QuickInstantCommons' ); +// RealMe +wfLoadExtension( 'RealMe' ); + // RelatedArticles wfLoadExtension( 'RelatedArticles' ); $wgRelatedArticlesCardLimit = 6; @@ -833,6 +839,9 @@ // TitleBlacklist wfLoadExtension( 'TitleBlacklist' ); +// TorBlock +wfLoadExtension( 'TorBlock' ); + // Translate wfLoadExtension( 'Translate' ); $wgGroupPermissions['autoconfirmed']['translate'] = true; diff --git a/dockers/femiwiki/README.md b/dockers/femiwiki/README.md index 84c97e55..22a57f20 100644 --- a/dockers/femiwiki/README.md +++ b/dockers/femiwiki/README.md @@ -1,5 +1,13 @@ # femiwiki -## 1.1.0 +## v1.1.1 -- Bump mediawiki to v1.1.0 +- Bump femiwiki/mediawiki to v2.0.0 +- Run Composer +- Download extensions from femiwiki/femiwiki-extensions v1.1.1 +- Embed LocalSettings.php in this image +- Load TorBlock, RealMe, GoogleNewsSitemap + +## v1.1.0 + +- Bump femiwiki/mediawiki to v1.1.0 diff --git a/dockers/mediawiki/composer.local.json b/dockers/femiwiki/composer.local.json similarity index 100% rename from dockers/mediawiki/composer.local.json rename to dockers/femiwiki/composer.local.json diff --git a/dockers/mediawiki/Dockerfile b/dockers/mediawiki/Dockerfile index ea4faee9..dea6747b 100644 --- a/dockers/mediawiki/Dockerfile +++ b/dockers/mediawiki/Dockerfile @@ -28,8 +28,5 @@ COPY cron/generate-sitemap \ RUN mkdir -p /mediawiki/sitemap &&\ chown www-data:www-data /mediawiki/sitemap -# Ship femiwiki-specific mediawiki configurations -COPY --chown=www-data LocalSettings.php /a/ - # secret.php should be mounted to '/a/secret.php' VOLUME /a diff --git a/dockers/mediawiki/README.md b/dockers/mediawiki/README.md index 6d949c13..03e2b908 100644 --- a/dockers/mediawiki/README.md +++ b/dockers/mediawiki/README.md @@ -1,5 +1,9 @@ # docker-mediawiki +## 2.0.1 + +- Do not embed LocalSettings.php + ## 2.0.0 - Remove extensions