Skip to content

Commit

Permalink
Add multi-arch support for images (#61)
Browse files Browse the repository at this point in the history
* Add multi-arch amd64, arm64 support for images
* Update README.md
* New workflows for CI/CD to automatically push Architecture builds on tagged releases

Authored-by: Brett Tasker (brettt89)
  • Loading branch information
brettt89 authored Aug 8, 2022
1 parent b7b650f commit 50d2451
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 95 deletions.
61 changes: 61 additions & 0 deletions .github/actions/build-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build & Test
description: "Builds and tests the docker images"
inputs:
php:
required: true
description: "PHP Version"
distro:
required: true
description: "PHP Distribution (e.g. apache, fpm, cli)"
os:
required: true
description: "Debian Operating System Distribution"
framework:
required: true
description: "Silverstripe CMS Recipe Version"
runs:
using: "composite"
steps:
- name: Build Images
env:
TAG: ${{ inputs.php }}-${{ inputs.distro }}-${{ inputs.os }}
BUILD_DIR: src/${{ inputs.php }}/${{ inputs.distro }}/${{ inputs.os }}
run: docker-compose build
shell: bash

- name: Get Composer Cache Directory
id: composer-data
run: |
echo "::set-output name=dir::$(composer config --global data-dir)"
shell: bash

- name: Cache Composer Downloads
uses: actions/cache@v1
with:
path: ${{ steps.composer-data.outputs.dir }}
key: ${{ runner.os }}-composer-${{ inputs.framework }}-${{ inputs.php }}
restore-keys: |
${{ runner.os }}-composer-${{ inputs.framework }}
- name: Create Silverstripe ${{ inputs.framework }} test project
env:
COMPOSER_HOME: ${{ steps.composer-data.outputs.dir }}
run: |
docker-compose run composer config -g platform.php ${{ inputs.php }}
docker-compose run composer config -g platform.ext-intl 1
docker-compose run composer config -g --no-interaction allow-plugins.composer/installers true
docker-compose run composer create-project --no-interaction --no-dev silverstripe/installer . ^${{ inputs.framework }}
shell: bash

- name: Run tests
env:
TAG: ${{ inputs.php }}-${{ inputs.distro }}-${{ inputs.os }}
run: docker-compose run sut
shell: bash

- name: The job has failed
if: ${{ failure() }}
run: |
docker-compose logs
shell: bash

87 changes: 0 additions & 87 deletions .github/workflows/build_test.yml

This file was deleted.

79 changes: 79 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Release
on:
push:
# Pattern matched against refs/tags
tags:
- '*' # Push events to every tag not containing /

jobs:
release:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [bullseye, buster, alpine]
php: ['7.4', '8.0', '8.1']
distro: [apache, fpm, cli]
exclude:
- os: alpine
distro: apache
include:
- os: bullseye
additional_distro: true
- os: bullseye
distro: apache
additional_php: true
- os: bullseye
php: 8.1
distro: apache
latest: true
steps:
- name: Checkout code
uses: actions/checkout@v2

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

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

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- id: test
uses: ./.github/actions/build-test
with:
php: ${{ matrix.php }}
distro: ${{ matrix.distro }}
os: ${{ matrix.os }}
framework: 4

- name: Populate Default Tag
run: |
echo "docker_tags=brettt89/silverstripe-web:${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}" >> $GITHUB_ENV
- if: ${{ matrix.additional_distro }}
name: Populate Additional Distro Tag
run: |
echo "docker_tags=${{ env.docker_tags }},brettt89/silverstripe-web:${{ matrix.php }}-${{ matrix.distro }}" >> $GITHUB_ENV
- if: ${{ matrix.additional_php }}
name: Populate Additional PHP Tag
run: |
echo "docker_tags=${{ env.docker_tags }},brettt89/silverstripe-web:${{ matrix.php }}" >> $GITHUB_ENV
- if: ${{ matrix.latest }}
name: Populate Latest Tag
run: |
echo "docker_tags=${{ env.docker_tags }},brettt89/silverstripe-web:latest" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v3
with:
context: src/${{ matrix.php }}/${{ matrix.distro }}/${{ matrix.os }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.docker_tags }}
40 changes: 40 additions & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: GitHub CI
on:
pull_request:
# Pattern matched against changes to src/, test/ and .github/
paths:
- 'src/**'
- 'tests/**'
- '.github/**'
push:
branches:
- master
jobs:
test:
# This job runs on Linux
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [bullseye, buster, alpine]
php: ['7.4', '8.0', '8.1']
framework: [3, 4]
distro: [apache, fpm, cli]
exclude:
- os: alpine
distro: apache
- php: 8.0
framework: 3
- php: 8.1
framework: 3
steps:
- name: Checkout code
uses: actions/checkout@v2

- id: test
uses: ./.github/actions/build-test
with:
php: ${{ matrix.php }}
distro: ${{ matrix.distro }}
os: ${{ matrix.os }}
framework: ${{ matrix.framework }}
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
![Github CI](https://github.com/brettt89/silverstripe-docker/workflows/Test%20Silverstripe%20installation/badge.svg)
- ![GitHub CI](https://github.com/brettt89/silverstripe-docker/workflows/GitHub%20CI/badge.svg?branch=master)
- ![Release](https://github.com/brettt89/silverstripe-docker/workflows/Release/badge.svg?branch=master)

# Quick reference

- **Where to file issues**:
[https://github.com/brettt89/silverstripe-docker/issues](https://github.com/brettt89/silverstripe-docker/issues)

- **Supported architectures**: ([more info](https://github.com/docker-library/official-images#architectures-other-than-amd64))
`amd64`, `arm64v8`

# Supported Tags and respective `Dockerfile` links

Expand Down Expand Up @@ -67,6 +76,7 @@ Legacy Tags are PHP versions which are no longer directly supported by PHP. As t
- [`5.6-fpm-alpine`](https://github.com/brettt89/silverstripe-docker/blob/master/src/5.6/fpm/alpine/Dockerfile)
- [`5.6-cli-alpine`](https://github.com/brettt89/silverstripe-docker/blob/master/src/5.6/cli/alpine/Dockerfile)


# What is Silverstripe CMS

Silverstripe CMS is a free and open source Content Management System (CMS) and Framework for creating and maintaining websites and web applications. It provides an out of the box web-based administration panel that enables users to make modifications to parts of the website, which includes a WYSIWYG website editor. The core of the software is Silverstripe Framework, a PHP Web application framework.
Expand Down Expand Up @@ -142,7 +152,7 @@ Many extensions are already compiled into the image, so it's worth checking the
We provide the helper scripts [`docker-php-extension-installer`](https://hub.docker.com/r/mlocati/php-extension-installer) to more easily install PHP extensions.

```Dockerfile
FROM brettt89/silverstripe-web:7.4-apache
FROM brettt89/silverstripe-web:8.1-apache
RUN install-php-extensions xdebug
```

Expand All @@ -166,14 +176,22 @@ The following extensions are installed by default on top of the default PHP imag

# Image Variants

The php images come in many flavors, each designed for a specific use case.
The `php` images come in many flavors, each designed for a specific use case.

Some of these tags may have names like `buster` or `stretch` in them. These are the suite code names for releases of Debian and indicate which release the image is based on. If your image needs to install any additional packages beyond what comes with the image, you'll likely want to specify one of these explicitly to minimize breakage when there are new releases of Debian.
Some of these tags may have names like `bullseye` or `buster` in them. These are the suite code names for releases of [Debian](https://wiki.debian.org/DebianReleases) and indicate which release the image is based on. If your image needs to install any additional packages beyond what comes with the image, you'll likely want to specify one of these explicitly to minimize breakage when there are new releases of Debian.

## `brettt89/silverstripe-web:<version>-apache`

This image contains Debian's Apache httpd in conjunction with PHP (as mod_php) and uses mpm_prefork by default. See Basic Usage for examples on how to use.

## `brettt89/silverstripe-web:<version>-cli`

This variant contains the [PHP CLI](https://secure.php.net/manual/en/features.commandline.php) tool with default mods. If you need a web server, this is probably not the image you are looking for. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as a base from which to build other images.

It also is the only variant which contains the (not recommended) `php-cgi` binary, which is likely necessary for some things like [PPM](https://github.com/php-pm/php-pm).

Note that *all* variants of `php` contain the PHP CLI (`/usr/local/bin/php`).

## `brettt89/silverstripe-web:<version>-fpm`

This variant contains PHP-FPM, which is a FastCGI implementation for PHP. See the PHP-FPM website for more information about PHP-FPM.
Expand All @@ -188,6 +206,14 @@ Some potentially helpful resources:
- [Stack Overflow discussion](https://stackoverflow.com/q/29905953/433558)
- [Apache httpd Wiki example](https://wiki.apache.org/httpd/PHPFPMWordpress)

## `brettt89/silverstripe-web:<version>-alpine`

This image is based on the popular [Alpine Linux project](https://alpinelinux.org), available in [the `alpine` official image](https://hub.docker.com/_/alpine). Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

This variant is useful when final image size being as small as possible is your primary concern. The main caveat to note is that it does use [musl libc](https://musl.libc.org) instead of [glibc and friends](https://www.etalabs.net/compare_libcs.html), so software will often run into issues depending on the depth of their libc requirements/assumptions. See [this Hacker News comment thread](https://news.ycombinator.com/item?id=10782897) for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.

To minimize image size, it's uncommon for additional related tools (such as `git` or `bash`) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the [`alpine` image description](https://hub.docker.com/_/alpine/) for examples of how to install packages if you are unfamiliar).

# License

View [license information](http://php.net/license/) for the software contained in this image.
Expand Down
2 changes: 1 addition & 1 deletion build/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ cat "${DOCKERFILE}" > "${OUTPUT}"
docker build -t "${IMAGE}:${TAG}" ${DOCKER_BUILD_ARGS} "${BUILD_DIR%/}" > "${OUTPUT}"

# If we got this far, then all good. remove log.
rm -f build.log || true
rm -f "${OUTPUT}" || true
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ services:
build:
context: ${BUILD_DIR:-src/7.4/apache/buster}
dockerfile: Dockerfile
args:
TAG: ${TAG:-7.4-apache-buster}
image: ${IMAGE:-brettt89/silverstripe-web}:${TAG:-7.4-apache-buster}
volumes:
- codebase:${MOUNT_DIR:-/var/www/html}
Expand Down
17 changes: 17 additions & 0 deletions docs/Development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Development of `brettt89/silverstripe-docker` images

This repository has been setup to use Github Actions to automatically test and release new builds using Git functionality. These instructions can be found in the `.github/` directory.

`develop.yml` contains Development tests which are run on every pull-request that contains changes to files in `src/`, `tests/` or `.github/`. These tests run a Silverstripe website (Both CMS 3 and CMS 4) on each image and confirms image is working as expected by executing a `dev/build` against the installation.

`deploy.yml` contains the Release process which is run when a new "tag" is created. Upon the tag being created, this workflow will perform a final Silverstripe CMS application test (Framework 4 only) on each Image before building all images across defined architectures (e.g. `amd64`, `arm64`). If these builds succeed, they are automatically pushed up to DockerHub as part of the CI/CD process.

## Making Changes

All changes should be submitted via Pull Requests to ensure development tests are executed for any changes made. This ensures that full test suite is executed against your changes before any release is made.

## Creating Releases

Releases can be triggerred by creation of a new tag/release on the repository. These tags/releases should *only* be created on the `master` branch for continuity.

>NOTE: The Release process will ignore tags that have `/` characters in them (E.g. The tag `3.1.2/beta` would be ignored).
Loading

0 comments on commit 50d2451

Please sign in to comment.