Skip to content

Commit

Permalink
Improve docker building (#500)
Browse files Browse the repository at this point in the history
* Bump ruby from 2.7 to 3.0.1

Bumps ruby from 2.7 to 3.0.1.

Signed-off-by: dependabot[bot] <[email protected]>

* Bump parallel from 1.13.0 to 1.20.1 in /extension-installer

Bumps [parallel](https://github.com/grosser/parallel) from 1.13.0 to 1.20.1.
- [Release notes](https://github.com/grosser/parallel/releases)
- [Commits](grosser/parallel@v1.13.0...v1.20.1)

Signed-off-by: dependabot[bot] <[email protected]>

* test: Simplify workflow file name

* Add support for arm64

* build: Resolve id conflict

* replace deprecated bundler parameters

* Use alpine image for ruby

Avoids #502

* Split base-mediawiki stage

* Build and load for amd first

* Improve the failure step

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
lens0021 and dependabot[bot] authored Apr 18, 2021
1 parent f843d40 commit cc132f9
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 67 deletions.
62 changes: 35 additions & 27 deletions .github/workflows/test-and-publish.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Edit configuration
run: |
mv configs/secret.php.example configs/secret.php;
Expand All @@ -58,18 +64,17 @@ jobs:
- run: echo "::set-output name=version::$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8)"
id: version

- name: Build docker image using cache
env:
DOCKER_BUILDKIT: 1
run: |
docker pull ghcr.io/femiwiki/mediawiki:latest
docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from ghcr.io/femiwiki/mediawiki:latest \
--tag ghcr.io/femiwiki/mediawiki:latest \
--tag ghcr.io/femiwiki/mediawiki:docker-test \
--tag ghcr.io/femiwiki/mediawiki:${{ steps.version.outputs.version }} \
.
# Build amd64 only for testing, do not push.
- name: Build
uses: docker/build-push-action@v2
with:
cache-to: type=inline
platforms: linux/amd64
load: true
tags: |
ghcr.io/femiwiki/mediawiki:latest
ghcr.io/femiwiki/mediawiki:docker-test
ghcr.io/femiwiki/mediawiki:${{ steps.version.outputs.version }}
- name: Initialize docker swarm and start services
run: |
Expand All @@ -82,29 +87,29 @@ jobs:
echo 'Waiting for http...'
until curl -sLfo /dev/null 127.0.0.1; do
sleep 1; done
- name: Test Parsoid API
run: |
echo 'Waiting for parsoid...'
until [ -n "$(docker ps -qf 'name=^mediawiki_parsoid')" ]; do
sleep 1; done
ID="$(docker ps -qf 'name=^mediawiki_parsoid')"
until [ "$(docker inspect "$ID" --format='{{json .State.Health.Status}}')" = \"healthy\" ]; do
sleep 1; done
- name: Test Parsoid API
run: |
URL="http://127.0.0.1/api.php?action=visualeditor&format=json&page=arbitrary_page&paction=parse&wikitext=arbitrary"
[[ ! "$(curl -Ls "$URL")" = *\"error\"* ]]
- name: backup of failure
if: ${{ failure() }}
# Allow fails
shell: bash
run: |
echo 'Failed to connect to 127.0.0.1';
curl -sLo /dev/null localhost; echo $?
curl -Ls "$URL" http://127.0.0.1/api.php?action=visualeditor&format=json&page=arbitrary_page&paction=parse&wikitext=arbitrary
curl -sLo /dev/null localhost && echo "success" || echo "failure"
URL="http://127.0.0.1/api.php?action=visualeditor&format=json&page=arbitrary_page&paction=parse&wikitext=arbitrary"
curl -Ls "$URL" && echo "success" || echo "failure"
docker ps;
for s in $(docker service ls -q ); do docker service ps "$s"; done
docker container ps;
for s in $(docker service ls -q ); do docker service logs "$s"; done
- name: Check if the container is still up
run: test "$(docker service ps -qf 'desired-state=Running' -f 'desired-state=Ready' mediawiki_fastcgi)"
- name: Try to access the mediawiki
Expand All @@ -115,12 +120,15 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: femiwiki-bot
password: ${{ secrets.CR_PAT }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to Registry
# Publish only when in the default branch
if: github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main'
run: |
docker push ghcr.io/femiwiki/mediawiki:latest
docker push ghcr.io/femiwiki/mediawiki:${{ steps.version.outputs.version }}
- name: Build and push
uses: docker/build-push-action@v2
with:
cache-to: type=inline
platforms: linux/amd64,linux/arm64
push: ${{ github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' }}
tags: |
ghcr.io/femiwiki/mediawiki:latest
ghcr.io/femiwiki/mediawiki:${{ steps.version.outputs.version }}
84 changes: 49 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,56 @@
ARG MEDIAWIKI_VERSION=1.35.2

#
# 미디어위키 확장 설치 스테이지. 루비 스크립트를 이용해 수많은 미디어위키
# 미디어위키 확장 설치 스테이지. 루비 스크립트를 이용해 수많은 미디어위키
# 확장들을 병렬로 빠르게 미리 다운받아 놓는다.
#
FROM ruby:2.7 AS base-extension
FROM --platform=$TARGETPLATFORM ruby:3.0.1-alpine AS base-extension

ARG MEDIAWIKI_VERSION=1.35.2
ARG COMPOSER_VERSION=2.0.12
# ARG instructions without a value inside of a build stage to use the default
# value of an ARG declared before the first FROM use
ARG MEDIAWIKI_VERSION

# Install composer, aria2, sudo and preload configuration file of
# aria2
#
# References:
# https://getcomposer.org/
# https://aria2.github.io/
RUN apk update && apk add \
aria2

# Install aria2.conf
COPY extension-installer/aria2.conf /root/.config/aria2/aria2.conf

RUN mkdir -p /tmp/mediawiki/

# Extensions and skins setup
COPY extension-installer/* /tmp/
RUN bundle config set deployment 'true' &&\
bundle config set path '/var/www/.gem' &&\
bundle install --gemfile /tmp/Gemfile
RUN MEDIAWIKI_BRANCH="REL$(echo $MEDIAWIKI_VERSION | cut -d. -f-2 | sed 's/\./_/g')" &&\
GEM_HOME=/var/www/.gem/ruby/3.0.0 ruby /tmp/install_extensions.rb "${MEDIAWIKI_BRANCH}"

#
# 미디어위키 다운로드와 Composer 스테이지. 다운받은 확장기능에 더해 미디어위키를 추가로 받고
# Composer로 디펜던시들을 설치한다.
#
FROM --platform=$TARGETPLATFORM php:7.4.16-cli AS base-mediawiki

ARG MEDIAWIKI_VERSION
ARG COMPOSER_VERSION=2.0.12

# Install dependencies and utilities
RUN apt-get update && apt-get install -y \
# Required for composer
php7.3-cli \
php7.3-mbstring \
# Required for aws-sdk-php
php7.3-simplexml \
# Install other CLI utilities
aria2 \
sudo
git

COPY --from=base-extension /tmp/mediawiki /tmp/mediawiki

# Install Composer
RUN EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)" &&\
#
# References:
# https://getcomposer.org/
RUN EXPECTED_SIGNATURE="$(curl -fSL https://composer.github.io/installer.sig)" &&\
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" &&\
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")" &&\
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then \
Expand All @@ -35,32 +61,20 @@ RUN EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)
php composer-setup.php --version "${COMPOSER_VERSION}" --install-dir=/usr/local/bin --filename=composer --quiet

# Create a cache directory for composer
RUN sudo -u www-data mkdir -p /tmp/composer

# Install aria2.conf
COPY extension-installer/aria2.conf /root/.config/aria2/aria2.conf

RUN mkdir -p /tmp/mediawiki/ &&\
chown www-data:www-data /tmp/mediawiki/

# Extensions and skins setup
COPY extension-installer/* /tmp/
RUN bundle install --deployment --gemfile /tmp/Gemfile --path /var/www/.gem
RUN export MEDIAWIKI_BRANCH="REL$(echo $MEDIAWIKI_VERSION | cut -d. -f-2 | sed 's/\./_/g')" &&\
sudo -u www-data ruby /tmp/install_extensions.rb "${MEDIAWIKI_BRANCH}"
RUN mkdir -p /tmp/composer

# MediaWiki setup
COPY --chown=www-data configs/composer.local.json /tmp/mediawiki/
RUN export MEDIAWIKI_MAJOR_VERSION="$(echo $MEDIAWIKI_VERSION | cut -d. -f-2)" &&\
COPY configs/composer.local.json /tmp/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 &&\
sudo -u www-data tar -xzf mediawiki.tar.gz --strip-components=1 --directory /tmp/mediawiki/ &&\
tar -xzf mediawiki.tar.gz --strip-components=1 --directory /tmp/mediawiki/ &&\
rm mediawiki.tar.gz
RUN sudo -u www-data COMPOSER_HOME=/tmp/composer composer update --no-dev --working-dir '/tmp/mediawiki'
RUN COMPOSER_HOME=/tmp/composer composer update --no-dev --working-dir '/tmp/mediawiki'

#
# Caddy에 Route53 패키지를 설치한다.
# Caddy 스테이지. Route53와 caddy-mwcache 패키지를 설치한 Caddy를 빌드한다.
#
FROM caddy:2.3.0-builder AS caddy
FROM --platform=$TARGETPLATFORM caddy:2.3.0-builder AS caddy

RUN xcaddy build \
--with github.com/caddy-dns/route53 \
Expand All @@ -78,7 +92,7 @@ RUN xcaddy build \
# /tmp/log/cron 크론 로그
# /tini tini
#
FROM php:7.4.16-fpm
FROM --platform=$TARGETPLATFORM php:7.4.16-fpm

# Install dependencies and utilities
RUN apt-get update && apt-get install -y \
Expand Down Expand Up @@ -141,7 +155,7 @@ COPY php/www.conf /usr/local/etc/php-fpm.d/www.conf
COPY php/opcache-recommended.ini /usr/local/etc/php/conf.d/opcache-recommended.ini

# Install Mediawiki and extensions
COPY --from=base-extension --chown=www-data /tmp/mediawiki /srv/femiwiki.com
COPY --from=base-mediawiki --chown=www-data /tmp/mediawiki /srv/femiwiki.com
# TODO Check the next line is valid when bump MediaWiki version
# TODO Remove the next line in MW 1.36
# Fix https://phabricator.wikimedia.org/T264735
Expand Down
2 changes: 1 addition & 1 deletion development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ services:
- MEDIAWIKI_LINTING=true
- MEDIAWIKI_APIS_DOMAIN=localhost
mysql:
image: mysql:8.0
image: mysql/mysql-server:8.0
command: --default-authentication-plugin=mysql_native_password
volumes:
- database:/var/lib/mysql
Expand Down
2 changes: 1 addition & 1 deletion extension-installer/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
source "https://rubygems.org"

gem 'parallel', "1.13"
gem 'parallel', "1.20.1"
4 changes: 2 additions & 2 deletions extension-installer/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
parallel (1.13.0)
parallel (1.20.1)

PLATFORMS
ruby

DEPENDENCIES
parallel (= 1.13)
parallel (= 1.20.1)

BUNDLED WITH
1.17.2
2 changes: 1 addition & 1 deletion production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ services:
mathoid:
image: ghcr.io/femiwiki/mathoid:2020-12-09T04-56-c3db867c
mysql:
image: mysql:8.0.23
image: mysql/mysql-server:8.0.23
ports:
- 3306:3306
command: --default-authentication-plugin=mysql_native_password
Expand Down

0 comments on commit cc132f9

Please sign in to comment.