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

Add support for multi-arch images built with GHA (7.4) #134

Merged
merged 2 commits into from
Aug 19, 2021
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
78 changes: 78 additions & 0 deletions .github/workflows/buildx_and_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Docker multiarch publish

on: push

env:
REPOSITORY: moodle-php-apache
DOCKERHUB_OWNER: moodlehq
GH_OWNER: moodlehq

jobs:
Build:
# Completely avoid forks to try this workflow.
if: github.repository_owner == 'moodlehq'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

# Calculate the tags to be pussed to the registries.
- name: Calculate image tag names
id: calculatetags
uses: docker/metadata-action@v3
with:
images: |
${{ env.DOCKERHUB_OWNER }}/${{ env.REPOSITORY }}
ghcr.io/${{ env.GH_OWNER }}/${{ env.REPOSITORY }}
flavor: |
latest=false
tags: |
type=raw,value={{branch}}
type=match,pattern=(\d+.\d+),value={{branch}}

# https://github.com/docker/setup-qemu-action#usage
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

# https://github.com/marketplace/actions/docker-setup-buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

# https://github.com/docker/login-action#docker-hub
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# https://github.com/docker/login-action#github-container-registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}

# https://github.com/docker/build-push-action#multi-platform-image
- name: Build and push to Docker Hub and Github registries
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.calculatetags.outputs.tags }}

# https://github.com/peter-evans/dockerhub-description
# It's horrible that we need to use password here instead of PAT, because
# that's only available via CLI what defeats 2FA. Anyway, we need to
# auto-update the description, so using it (till available via PAT).
# Link: https://github.com/peter-evans/dockerhub-description/issues/10
# Note that we only update the description with the master branch version.
- name: Set Docker Hub description from README.md
if: github.ref == 'refs/heads/master'
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.DOCKERHUB_OWNER }}/${{ env.REPOSITORY }}
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM php:7.4-apache-buster

# So we can use it anywhere for conditional stuff. Keeping BC with old (non-buildkit, builders)
ARG TARGETPLATFORM
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
RUN echo "Building for ${TARGETPLATFORM}"

ADD root/ /
# Fix the original permissions of /tmp, the PHP default upload tmp dir.
RUN chmod 777 /tmp && chmod +t /tmp
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@ A Moodle PHP environment configured for Moodle development based on [Official PH

For a complete list of supported versions, look to the [master README](https://github.com/moodlehq/moodle-php-apache/tree/master).

# Example usage
## Example usage
The following command will expose the current working directory on port 8080:
```bash
$ docker run --name web0 -p 8080:80 -v $PWD:/var/www/html moodlehq/moodle-php-apache:7.1
```

# Features

## Features
* Preconfigured with all php extensions required for Moodle development and all database drivers
* Serves wwroot configured at /var/www/html/
* Verified by [automated tests](https://travis-ci.com/moodlehq/moodle-php-apache)

# Directories
* For PHP 7.3 and up, both `linux/amd64` and `linux/arm64` images are being built. Note that `linux/arm64` doesn't support the sqlsrv and oci extensions yet. Other than that, both architectures work exactly the same.
* Verified by [automated tests](https://travis-ci.com/moodlehq/moodle-php-apache).
* Autobuilt from GHA, on push.

## Directories
To faciliate testing and easy setup the following directories are created and owned by www-data by default:

* `/var/www/moodledata`
* `/var/www/phpunitdata`
* `/var/www/behatdata`
* `/var/www/behatfaildumps`


# See also
## See also
This container is part of a set of containers for Moodle development, see also:

* [moodle-docker](https://github.com/moodlehq/moodle-docker) a docker-composer based set of tools to get Moodle development running with zero configuration
* [moodle-db-mssql](https://github.com/moodlehq/moodle-db-mssql) Microsoft SQL Server for Linux configured for Moodle development
* [moodle-db-oracle](https://github.com/moodlehq/moodle-db-oracle) Oracle XE configured for Moodle development
15 changes: 0 additions & 15 deletions hooks/post_push

This file was deleted.

5 changes: 5 additions & 0 deletions root/tmp/setup/oci8-extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then
echo "oracle extension not available for ${TARGETPLATFORM} architecture, skipping"
exit 0
fi

echo "Downloading oracle files"
curl https://download.oracle.com/otn_software/linux/instantclient/19600/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip \
-o /tmp/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip
Expand Down
8 changes: 6 additions & 2 deletions root/tmp/setup/php-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/inclu
docker-php-ext-install -j$(nproc) gd

# LDAP.
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/
docker-php-ext-configure ldap
docker-php-ext-install -j$(nproc) ldap

# Memcached, MongoDB, Redis, APCu, igbinary, solr, uuid
Expand All @@ -72,7 +72,11 @@ echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini
# Install Microsoft dependencies for sqlsrv.
# (kept apart for clarity, still need to be run here
# before some build packages are deleted)
/tmp/setup/sqlsrv-extension.sh
if [[ ${TARGETPLATFORM} == "linux/amd64" ]]; then
/tmp/setup/sqlsrv-extension.sh
else
echo "sqlsrv extension not available for ${TARGETPLATFORM} architecture, skipping"
fi

# Keep our image size down..
pecl clear-cache
Expand Down