Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: Split caddy and mediawiki image #825

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: 'Docker: php'
name: 'Docker: caddy'

Check failure on line 1 in .github/workflows/docker-caddy.yml

View workflow job for this annotation

GitHub Actions / docker-image

.github/workflows/docker-caddy.yml#L1

This run was manually canceled.

env:
TAG: '1.0.0'

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:
Expand All @@ -33,11 +33,11 @@

- 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 }}
6 changes: 3 additions & 3 deletions .github/workflows/docker-femiwiki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:

- name: Edit configuration
run: |
mv dockers/femiwiki/configs/secret.php.example dockers/femiwiki/development/secret.php
mv dockers/femiwiki/configs/LocalSettings.php dockers/femiwiki/development
mv dockers/femiwiki/configs/Hotfix.php dockers/femiwiki/development
mv dockers/mediawiki/secret.php.example development/secret.php
mv dockers/mediawiki/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

- run: |
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/docker-mediawiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: 'Docker: mediawiki'

Check failure on line 1 in .github/workflows/docker-mediawiki.yml

View workflow job for this annotation

GitHub Actions / docker-image

.github/workflows/docker-mediawiki.yml#L1

This run was manually canceled.

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 }}
43 changes: 43 additions & 0 deletions .github/workflows/docker-php-fpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: 'Docker: php-fpm'

Check failure on line 1 in .github/workflows/docker-php-fpm.yml

View workflow job for this annotation

GitHub Actions / docker-image

.github/workflows/docker-php-fpm.yml#L1

This run was manually canceled.

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 }}
9 changes: 4 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ jobs:
- uses: actions/checkout@v4
- name: Format caddyfile
run: |
cd dockers/femiwiki/development
cp Caddyfile Caddyfile.orig
docker run -v $PWD:/srv caddy \
caddy fmt --overwrite
diff Caddyfile.orig Caddyfile
for CADDYFILE_PATH in **/Caddyfile; do
docker run -v $(dirname $(realpath $CADDYFILE_PATH)):/srv caddy \
caddy fmt --diff
done

etc-lint:
runs-on: ubuntu-22.04
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Caddy를 실행할 경우에는 Caddyfile을 `/srv/femiwiki.com/Caddyfile`로
```bash
docker swarm init

cp dockers/femiwiki/configs/secret.php.example dockers/femiwiki/development/secret.php
cp dockers/femiwiki/configs/LocalSettings.php dockers/femiwiki/development
cp dockers/femiwiki/configs/Hotfix.php dockers/femiwiki/development
cp dockers/mediawikiwiki/secret.php.example development/secret.php
cp dockers/mediawikiwiki/LocalSettings.php development/
cp dockers/femiwiki/Hotfix.php development/

# In case of Docker swarm
docker stack deploy --prune -c docker-compose.yml mediawiki
Expand Down
File renamed without changes.
File renamed without changes.
34 changes: 17 additions & 17 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
# 혹은:
# docker-compose up
version: '3'
services:
# http:
# volumes:
# - ../Femiwiki:/srv/femiwiki.com/skins/Femiwiki
# fastcgi:
# volumes:
# - ../Femiwiki:/srv/femiwiki.com/skins/Femiwiki
# - ../AchievementBadges:/srv/femiwiki.com/extensions/AchievementBadges
# - ../DiscordRCFeed:/srv/femiwiki.com/extensions/DiscordRCFeed
# - ../FacetedCategory:/srv/femiwiki.com/extensions/FacetedCategory
# - ../PageViewInfoGA:/srv/femiwiki.com/extensions/PageViewInfoGA
# - ../Sanctions:/srv/femiwiki.com/extensions/Sanctions
# - ../UnifiedExtensionForFemiwiki:/srv/femiwiki.com/extensions/UnifiedExtensionForFemiwiki
# environment:
# - MEDIAWIKI_SKIP_INSTALL=1
# - MEDIAWIKI_SKIP_UPDATE=1
# - MEDIAWIKI_SKIP_IMPORT_SITES=1
# services:
# http:
# volumes:
# - ../Femiwiki:/srv/femiwiki.com/skins/Femiwiki
# fastcgi:
# volumes:
# - ../Femiwiki:/srv/femiwiki.com/skins/Femiwiki
# - ../AchievementBadges:/srv/femiwiki.com/extensions/AchievementBadges
# - ../DiscordRCFeed:/srv/femiwiki.com/extensions/DiscordRCFeed
# - ../FacetedCategory:/srv/femiwiki.com/extensions/FacetedCategory
# - ../PageViewInfoGA:/srv/femiwiki.com/extensions/PageViewInfoGA
# - ../Sanctions:/srv/femiwiki.com/extensions/Sanctions
# - ../UnifiedExtensionForFemiwiki:/srv/femiwiki.com/extensions/UnifiedExtensionForFemiwiki
# environment:
# - MEDIAWIKI_SKIP_INSTALL=1
# - MEDIAWIKI_SKIP_UPDATE=1
# - MEDIAWIKI_SKIP_IMPORT_SITES=1
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions dockers/caddy/Dockerfile
Original file line number Diff line number Diff line change
@@ -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}"
3 changes: 3 additions & 0 deletions dockers/caddy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# caddy

Route53와 caddy-mwcache 패키지를 설치한 Caddy를 빌드한다.
113 changes: 11 additions & 102 deletions dockers/femiwiki/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 미디어위키 소스코드 및 확장들
Expand All @@ -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
Expand All @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading