From 3a029e912f462aeda58490b5c5027fb0e12c0841 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Fri, 1 Mar 2024 21:43:42 +0900 Subject: [PATCH] docker: Split caddy and mediawiki image --- .../{docker-php.yml => docker-caddy.yml} | 18 +-- .github/workflows/docker-mediawiki.yml | 43 +++++++ .github/workflows/docker-php-fpm.yml | 43 +++++++ .gitignore | 8 +- .../development => development}/Caddyfile | 0 .../development => development}/site-list.xml | 0 docker-compose.yml | 4 +- dockers/caddy/Dockerfile | 6 + dockers/caddy/README.md | 3 + dockers/femiwiki/Dockerfile | 113 ++---------------- dockers/femiwiki/{configs => }/Hotfix.php | 0 dockers/femiwiki/{configs => }/site-list.xml | 0 dockers/mediawiki/Dockerfile | 81 +++++++++++++ .../configs => mediawiki}/LocalSettings.php | 0 .../configs => mediawiki}/composer.local.json | 0 .../configs/secret.php.example | 0 dockers/{femiwiki => mediawiki}/cron/crontab | 0 .../cron/generate-sitemap | 0 dockers/{femiwiki => mediawiki}/cron/run-jobs | 0 .../cron/update-special-pages | 0 dockers/{php => php-fpm}/Dockerfile | 0 dockers/php-fpm/README.md | 3 + 22 files changed, 205 insertions(+), 117 deletions(-) rename .github/workflows/{docker-php.yml => docker-caddy.yml} (68%) create mode 100644 .github/workflows/docker-mediawiki.yml create mode 100644 .github/workflows/docker-php-fpm.yml rename {dockers/femiwiki/development => development}/Caddyfile (100%) rename {dockers/femiwiki/development => development}/site-list.xml (100%) create mode 100644 dockers/caddy/Dockerfile create mode 100644 dockers/caddy/README.md rename dockers/femiwiki/{configs => }/Hotfix.php (100%) rename dockers/femiwiki/{configs => }/site-list.xml (100%) create mode 100644 dockers/mediawiki/Dockerfile rename dockers/{femiwiki/configs => mediawiki}/LocalSettings.php (100%) rename dockers/{femiwiki/configs => mediawiki}/composer.local.json (100%) rename dockers/{femiwiki => mediawiki}/configs/secret.php.example (100%) rename dockers/{femiwiki => mediawiki}/cron/crontab (100%) rename dockers/{femiwiki => mediawiki}/cron/generate-sitemap (100%) rename dockers/{femiwiki => mediawiki}/cron/run-jobs (100%) rename dockers/{femiwiki => mediawiki}/cron/update-special-pages (100%) rename dockers/{php => php-fpm}/Dockerfile (100%) create mode 100644 dockers/php-fpm/README.md diff --git a/.github/workflows/docker-php.yml b/.github/workflows/docker-caddy.yml similarity index 68% rename from .github/workflows/docker-php.yml rename to .github/workflows/docker-caddy.yml index e3f95c93..0a77d408 100644 --- a/.github/workflows/docker-php.yml +++ b/.github/workflows/docker-caddy.yml @@ -1,4 +1,4 @@ -name: 'Docker: php' +name: 'Docker: caddy' env: TAG: '1.0.0' @@ -6,12 +6,12 @@ env: on: push: paths: - - 'dockers/php/**' - - .github/workflows/docker-php.yml + - 'dockers/caddy/**' + - .github/workflows/docker-caddy.yml pull_request: paths: - - 'dockers/php/**' - - .github/workflows/docker-php.yml + - 'dockers/caddy/**' + - .github/workflows/docker-caddy.yml workflow_dispatch: jobs: @@ -33,11 +33,11 @@ jobs: - uses: docker/build-push-action@v5 with: - context: '{{ defaultContext }}:dockers/php' + context: '{{ defaultContext }}:dockers/caddy' platforms: linux/amd64,linux/arm64 - cache-from: ghcr.io/femiwiki/php:latest + cache-from: ghcr.io/femiwiki/caddy:latest load: false push: ${{ github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' }} tags: | - ghcr.io/femiwiki/php:latest - ghcr.io/femiwiki/php:${{ env.TAG }} + ghcr.io/femiwiki/caddy:latest + ghcr.io/femiwiki/caddy:${{ env.TAG }} diff --git a/.github/workflows/docker-mediawiki.yml b/.github/workflows/docker-mediawiki.yml new file mode 100644 index 00000000..ba24e4be --- /dev/null +++ b/.github/workflows/docker-mediawiki.yml @@ -0,0 +1,43 @@ +name: 'Docker: mediawiki' + +env: + TAG: '1.0.0' + +on: + push: + paths: + - 'dockers/mediawiki/**' + - .github/workflows/docker-mediawiki.yml + pull_request: + paths: + - 'dockers/mediawiki/**' + - .github/workflows/docker-mediawiki.yml + workflow_dispatch: + +jobs: + docker-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-qemu-action@v3 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + if: github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/build-push-action@v5 + with: + context: '{{ defaultContext }}:dockers/mediawiki' + platforms: linux/amd64,linux/arm64 + cache-from: ghcr.io/femiwiki/mediawiki:latest + load: false + push: ${{ github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' }} + tags: | + ghcr.io/femiwiki/mediawiki:latest + ghcr.io/femiwiki/mediawiki:${{ env.TAG }} diff --git a/.github/workflows/docker-php-fpm.yml b/.github/workflows/docker-php-fpm.yml new file mode 100644 index 00000000..5e75b09f --- /dev/null +++ b/.github/workflows/docker-php-fpm.yml @@ -0,0 +1,43 @@ +name: 'Docker: php-fpm' + +env: + TAG: '1.0.0' + +on: + push: + paths: + - 'dockers/php-fpm/**' + - .github/workflows/docker-php-fpm.yml + pull_request: + paths: + - 'dockers/php-fpm/**' + - .github/workflows/docker-php-fpm.yml + workflow_dispatch: + +jobs: + docker-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-qemu-action@v3 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + if: github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/build-push-action@v5 + with: + context: '{{ defaultContext }}:dockers/php-fpm' + platforms: linux/amd64,linux/arm64 + cache-from: ghcr.io/femiwiki/php-fpm:latest + load: false + push: ${{ github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' }} + tags: | + ghcr.io/femiwiki/php-fpm:latest + ghcr.io/femiwiki/php-fpm:${{ env.TAG }} diff --git a/.gitignore b/.gitignore index 288698a8..da09f79c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ # secret -/dockers/femiwiki/development/secret.php -/dockers/femiwiki/development/LocalSettings.php -/dockers/femiwiki/development/Hotfix.php -/dockers/femiwiki/development/analytics-credentials-file.json +/development/secret.php +/development/LocalSettings.php +/development/Hotfix.php +/development/analytics-credentials-file.json # Composer /vendor diff --git a/dockers/femiwiki/development/Caddyfile b/development/Caddyfile similarity index 100% rename from dockers/femiwiki/development/Caddyfile rename to development/Caddyfile diff --git a/dockers/femiwiki/development/site-list.xml b/development/site-list.xml similarity index 100% rename from dockers/femiwiki/development/site-list.xml rename to development/site-list.xml diff --git a/docker-compose.yml b/docker-compose.yml index 442df362..e57ed7ed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - 8080:8080 volumes: - caddy:/etc/caddycerts - - ./dockers/femiwiki/development/Caddyfile:/srv/femiwiki.com/Caddyfile:ro + - ./development/Caddyfile:/srv/femiwiki.com/Caddyfile:ro environment: - CADDYPATH=/etc/caddycerts deploy: @@ -24,7 +24,7 @@ services: image: ghcr.io/femiwiki/mediawiki:latest volumes: # Mount secret.php, LocalSettings.php and site-list.xml - - ./dockers/femiwiki/development:/a:ro + - ./development:/a:ro - l18n_cache:/tmp/cache environment: - MEDIAWIKI_SERVER=http://127.0.0.1:8080 diff --git a/dockers/caddy/Dockerfile b/dockers/caddy/Dockerfile new file mode 100644 index 00000000..eeb1d2df --- /dev/null +++ b/dockers/caddy/Dockerfile @@ -0,0 +1,6 @@ +FROM --platform=$TARGETPLATFORM caddy:2-builder AS caddy +ARG CADDY_MWCACHE_COMMIT=9e9ac234170400406c6a328bbaaaa4c95e05bd73 + +RUN XCADDY_DEBUG=1 xcaddy build v2.7.5 \ + --with github.com/caddy-dns/route53 \ + --with "github.com/femiwiki/caddy-mwcache@${CADDY_MWCACHE_COMMIT}" diff --git a/dockers/caddy/README.md b/dockers/caddy/README.md new file mode 100644 index 00000000..8ca601fb --- /dev/null +++ b/dockers/caddy/README.md @@ -0,0 +1,3 @@ +# caddy + +Route53와 caddy-mwcache 패키지를 설치한 Caddy를 빌드한다. diff --git a/dockers/femiwiki/Dockerfile b/dockers/femiwiki/Dockerfile index 4936d09c..1b877a8f 100644 --- a/dockers/femiwiki/Dockerfile +++ b/dockers/femiwiki/Dockerfile @@ -1,63 +1,3 @@ -ARG MEDIAWIKI_VERSION=1.41.0 -ARG CADDY_MWCACHE_COMMIT=9e9ac234170400406c6a328bbaaaa4c95e05bd73 - -FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/femiwiki-extensions:1.0.0 AS base-extension -# -# Composer 스테이지. Composer 이미지는 PHP 버전을 따로 설정할 수 없어 스테이지를 생성해 -# /usr/bin/composer만 복사해 사용하여야 합니다. -# See 'PHP version & extensions' section on https://hub.docker.com/_/composer for more details. -# -FROM --platform=$TARGETPLATFORM composer:2.6.6 AS composer - -# -# 미디어위키 다운로드 스테이지. 다운받은 확장기능에 더해 미디어위키를 추가로 받고 -# Composer로 디펜던시들을 설치한다. -# -FROM --platform=$TARGETPLATFORM php:8.1.22-cli AS base-mediawiki - -ARG MEDIAWIKI_VERSION - -# Install dependencies and utilities -RUN apt-get update && apt-get install -y \ - libicu-dev \ - # https://getcomposer.org/doc/00-intro.md#system-requirements - git \ - unzip - -# Install the PHP extensions we need -RUN IPE_DEBUG=1 docker-php-ext-install -j8 \ - intl \ - calendar - -COPY --from=base-extension /mediawiki /tmp/mediawiki - -# Create a cache directory for composer -RUN mkdir -p /tmp/composer - -# MediaWiki setup -RUN MEDIAWIKI_MAJOR_VERSION="$(echo $MEDIAWIKI_VERSION | cut -d. -f-2)" &&\ - curl -fSL "https://releases.wikimedia.org/mediawiki/${MEDIAWIKI_MAJOR_VERSION}/mediawiki-core-${MEDIAWIKI_VERSION}.tar.gz" -o mediawiki.tar.gz &&\ - tar -xzf mediawiki.tar.gz --strip-components=1 --directory /tmp/mediawiki/ &&\ - rm mediawiki.tar.gz -COPY configs/composer.local.json /tmp/mediawiki/ - -COPY --from=composer /usr/bin/composer /usr/bin/composer -RUN COMPOSER_HOME=/tmp/composer /usr/bin/composer update --no-dev --working-dir '/tmp/mediawiki' - -# -# Caddy 스테이지. Route53와 caddy-mwcache 패키지를 설치한 Caddy를 빌드한다. -# -FROM --platform=$TARGETPLATFORM caddy:2-builder AS caddy -ARG CADDY_MWCACHE_COMMIT - -RUN XCADDY_DEBUG=1 xcaddy build v2.7.5 \ - --with github.com/caddy-dns/route53 \ - --with "github.com/femiwiki/caddy-mwcache@${CADDY_MWCACHE_COMMIT}" - -# -# 미디어위키 도커이미지 생성 스테이지. 미디어위키 실행에 필요한 각종 PHP -# 디펜던시들을 설치한다. -# # 파일 목록: # /usr/local/etc/php PHP 설정 # /srv/femiwiki.com 미디어위키 소스코드 및 확장들 @@ -66,8 +6,13 @@ RUN XCADDY_DEBUG=1 xcaddy build v2.7.5 \ # /var/log/cron.log 크론 로그 # /tini tini # -FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/php:1.0.0 -ARG TARGETPLATFORM +FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/caddy:1.0.0 AS caddy + +FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/mediawiki:1.0.0 + +# Set timezone +ENV TZ=Asia/Seoul +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # Install Caddy COPY --from=caddy /usr/bin/caddy /usr/bin/caddy @@ -78,50 +23,14 @@ RUN mkdir -p \ /etc/caddy \ /usr/share/caddy -# Set timezone -ENV TZ=Asia/Seoul -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -# Install Mediawiki and extensions -COPY --from=base-mediawiki --chown=www-data /tmp/mediawiki /srv/femiwiki.com - -# Create cache directories for mediawiki -# $wgCacheDirectory should not be accessible from the web and writable by the web server -# See https://www.mediawiki.org/wiki/Manual:$wgCacheDirectory for details -RUN sudo -u www-data mkdir -p /tmp/file-cache /tmp/cache +# Install MediaWiki +RUN mv /mediawiki /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 - -# Web server should be able to execute lua binary -# Reference: https://www.mediawiki.org/wiki/Extension:Scribunto#Additional_binaries -RUN chmod o+x /usr/bin/lua - - -# -# Install and register cron -# -COPY cron/crontab /tmp/crontab -RUN crontab /tmp/crontab && rm /tmp/crontab - -# Install scripts -RUN sudo -u www-data mkdir -p /srv/femiwiki.com/sitemap -COPY cron/generate-sitemap \ - cron/update-special-pages \ - cron/run-jobs \ - /usr/local/bin/ +WORKDIR /srv/femiwiki.com # Ship femiwiki resources COPY --chown=www-data:www-data resources /srv/femiwiki.com/ - -# Ship femiwiki-specific mediawiki configurations -COPY --chown=www-data [ "configs/LocalSettings.php", "configs/Hotfix.php", "configs/site-list.xml", "/a/" ] -# secret.php should be mounted to '/a/secret.php' -VOLUME /a - -WORKDIR /srv/femiwiki.com +COPY --chown=www-data:www-data ["site-list.xml", "Hotfix.php", "/a/"] EXPOSE 80 EXPOSE 443 diff --git a/dockers/femiwiki/configs/Hotfix.php b/dockers/femiwiki/Hotfix.php similarity index 100% rename from dockers/femiwiki/configs/Hotfix.php rename to dockers/femiwiki/Hotfix.php diff --git a/dockers/femiwiki/configs/site-list.xml b/dockers/femiwiki/site-list.xml similarity index 100% rename from dockers/femiwiki/configs/site-list.xml rename to dockers/femiwiki/site-list.xml diff --git a/dockers/mediawiki/Dockerfile b/dockers/mediawiki/Dockerfile new file mode 100644 index 00000000..4b5c3698 --- /dev/null +++ b/dockers/mediawiki/Dockerfile @@ -0,0 +1,81 @@ +ARG MEDIAWIKI_VERSION=1.41.0 + +# Composer 이미지는 PHP 버전을 따로 설정할 수 없어 스테이지를 생성해 /usr/bin/composer만 복사해 +# 사용하여야 합니다. +# See 'PHP version & extensions' section on https://hub.docker.com/_/composer for more details. +FROM --platform=$TARGETPLATFORM composer:2.6.6 AS composer + +FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/femiwiki-extensions:1.0.0 AS extensions + +FROM --platform=$TARGETPLATFORM php:8.1.22-cli AS base-mediawiki +ARG MEDIAWIKI_VERSION + +# Install dependencies and utilities +RUN apt-get update && apt-get install -y \ + libicu-dev \ + # https://getcomposer.org/doc/00-intro.md#system-requirements + git \ + unzip + +# Install the PHP extensions we need +RUN IPE_DEBUG=1 docker-php-ext-install -j8 \ + intl \ + calendar + +COPY --from=composer /usr/bin/composer /usr/bin/composer + +# Create a cache directory for composer +RUN mkdir -p /composer + +COPY --from=extensions /mediawiki /mediawiki + +# Download MediaWiki +RUN MEDIAWIKI_MAJOR_VERSION="$(echo $MEDIAWIKI_VERSION | cut -d. -f-2)" &&\ + curl -fSL "https://releases.wikimedia.org/mediawiki/${MEDIAWIKI_MAJOR_VERSION}/mediawiki-core-${MEDIAWIKI_VERSION}.tar.gz" -o mediawiki.tar.gz &&\ + tar -xzf mediawiki.tar.gz --strip-components=1 --directory /mediawiki/ &&\ + rm mediawiki.tar.gz + +COPY composer.local.json /mediawiki/ + +RUN COMPOSER_HOME=/composer /usr/bin/composer update --no-dev --working-dir '/mediawiki' + + +# +# PHP-FPM Stage +# + +FROM --platform=$TARGETPLATFORM ghcr.io/femiwiki/php-fpm:1.0.0 + +# Install Mediawiki and extensions +COPY --from=base-mediawiki --chown=www-data /mediawiki /mediawiki + +# Create cache directories for mediawiki +# $wgCacheDirectory should not be accessible from the web and writable by the web server +# See https://www.mediawiki.org/wiki/Manual:$wgCacheDirectory for details +RUN sudo -u www-data mkdir -p /tmp/file-cache /tmp/cache + +# 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 /mediawiki/extensions/Widgets/compiled_templates + +# Web server should be able to execute lua binary +# Reference: https://www.mediawiki.org/wiki/Extension:Scribunto#Additional_binaries +RUN chmod o+x /usr/bin/lua + +# Install and register cron +COPY cron/crontab /tmp/crontab +RUN crontab /tmp/crontab && rm /tmp/crontab +COPY cron/generate-sitemap \ + cron/update-special-pages \ + cron/run-jobs \ + /usr/local/bin/ + +# Install scripts +RUN sudo -u www-data mkdir -p /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/femiwiki/configs/LocalSettings.php b/dockers/mediawiki/LocalSettings.php similarity index 100% rename from dockers/femiwiki/configs/LocalSettings.php rename to dockers/mediawiki/LocalSettings.php diff --git a/dockers/femiwiki/configs/composer.local.json b/dockers/mediawiki/composer.local.json similarity index 100% rename from dockers/femiwiki/configs/composer.local.json rename to dockers/mediawiki/composer.local.json diff --git a/dockers/femiwiki/configs/secret.php.example b/dockers/mediawiki/configs/secret.php.example similarity index 100% rename from dockers/femiwiki/configs/secret.php.example rename to dockers/mediawiki/configs/secret.php.example diff --git a/dockers/femiwiki/cron/crontab b/dockers/mediawiki/cron/crontab similarity index 100% rename from dockers/femiwiki/cron/crontab rename to dockers/mediawiki/cron/crontab diff --git a/dockers/femiwiki/cron/generate-sitemap b/dockers/mediawiki/cron/generate-sitemap similarity index 100% rename from dockers/femiwiki/cron/generate-sitemap rename to dockers/mediawiki/cron/generate-sitemap diff --git a/dockers/femiwiki/cron/run-jobs b/dockers/mediawiki/cron/run-jobs similarity index 100% rename from dockers/femiwiki/cron/run-jobs rename to dockers/mediawiki/cron/run-jobs diff --git a/dockers/femiwiki/cron/update-special-pages b/dockers/mediawiki/cron/update-special-pages similarity index 100% rename from dockers/femiwiki/cron/update-special-pages rename to dockers/mediawiki/cron/update-special-pages diff --git a/dockers/php/Dockerfile b/dockers/php-fpm/Dockerfile similarity index 100% rename from dockers/php/Dockerfile rename to dockers/php-fpm/Dockerfile diff --git a/dockers/php-fpm/README.md b/dockers/php-fpm/README.md new file mode 100644 index 00000000..c4a30389 --- /dev/null +++ b/dockers/php-fpm/README.md @@ -0,0 +1,3 @@ +# php-fpm + +미디어위키 실행에 필요한 각종 PHP 디펜던시들을 설치한다.