Skip to content

Commit

Permalink
Multi-platform builds using GitHub workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimstojkovic committed Sep 16, 2021
1 parent db76f85 commit 276a354
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 123 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/hooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ jobs:
matrix:
version: ['10.0', '11.0', '12.0', '13.0']
php: ['7.3']
archi: ['amd64']
variant: ['apache', 'fpm', 'fpm-alpine']

steps:
- name: Check Out Repo
uses: actions/checkout@v2

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

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

- name: Execute CI hooks
id: docker_hooks
run: |
cd images/${{ matrix.version }}/php${{ matrix.php }}-${{ matrix.variant }}-${{ matrix.archi }}
cd images/${{ matrix.version }}/php${{ matrix.php }}-${{ matrix.variant }}
./hooks/run
- name: Display docker images
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

name: Docker Image Push

on:
workflow_dispatch:
inputs:
version:
description: 'Image version to push (only specify one)'
required: true
default: '14.0'
platform:
description: 'Comma-separated list of platforms'
required: true
default: 'linux/arm/v7,linux/arm64,linux/386,/linux/amd64'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.3']
variant: ['apache', 'fpm', 'fpm-alpine']

steps:
- name: Checkout Repo
uses: actions/checkout@v2

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

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

- name: Execute push hook
id: docker_push_hook
env:
DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_PLATFORM: ${{ github.event.inputs.platform }}
run: |
cd images/${{ github.event.inputs.version }}/php${{ matrix.php }}-${{ matrix.variant }}
./hooks/run_push
67 changes: 23 additions & 44 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ branches:
before_install:
- env | sort
- export home=$(pwd)
- export travis_dir="${home}/images/${VERSION}/php${PHP_VERSION}-${VARIANT}-${ARCHI}"
- export TAG=${VERSION}-php${PHP_VERSION}-${VARIANT}-${ARCHI}
- export travis_dir="${home}/images/${VERSION}/php${PHP_VERSION}-${VARIANT}"
- export TAG=${VERSION}-php${PHP_VERSION}-${VARIANT}
- export VCS_REF=`git rev-parse --short HEAD`
- export BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
- export IMAGE_NAME=monogramm/docker-dolibarr:${TAG}
Expand Down Expand Up @@ -63,47 +63,26 @@ matrix:
# # Ref: https://docs.travis-ci.com/user/reference/osx
# osx_image: xcode11.3
allow_failures:
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=fpm-alpine ARCHI=i386
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=fpm-alpine ARCHI=amd64
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=fpm ARCHI=i386
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=fpm ARCHI=amd64
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=apache ARCHI=i386
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=apache ARCHI=amd64
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=fpm-alpine
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=fpm
- env: VERSION=develop PHP_VERSION=7.2 VARIANT=apache

env: # Environments
- VERSION=develop PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=i386
- VERSION=develop PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=amd64
- VERSION=develop PHP_VERSION=7.3 VARIANT=fpm ARCHI=i386
- VERSION=develop PHP_VERSION=7.3 VARIANT=fpm ARCHI=amd64
- VERSION=develop PHP_VERSION=7.3 VARIANT=apache ARCHI=i386
- VERSION=develop PHP_VERSION=7.3 VARIANT=apache ARCHI=amd64
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=i386
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=amd64
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=i386
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=amd64
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=i386
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=amd64
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=i386
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=amd64
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=i386
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=amd64
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=i386
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=amd64
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=i386
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=amd64
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=i386
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=amd64
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=i386
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=amd64
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=i386
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=amd64
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=i386
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=amd64
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=i386
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=amd64
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=i386
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=fpm-alpine ARCHI=amd64
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=i386
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=fpm ARCHI=amd64
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=i386
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=apache ARCHI=amd64
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=apache
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=fpm
- VERSION=14.0 PHP_VERSION=7.3 VARIANT=fpm-alpine
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=apache
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=fpm
- VERSION=13.0 PHP_VERSION=7.3 VARIANT=fpm-alpine
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=apache
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=fpm
- VERSION=12.0 PHP_VERSION=7.3 VARIANT=fpm-alpine
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=apache
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=fpm
- VERSION=11.0 PHP_VERSION=7.3 VARIANT=fpm-alpine
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=apache
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=fpm
- VERSION=10.0 PHP_VERSION=7.3 VARIANT=fpm-alpine
- VERSION=develop PHP_VERSION=7.3 VARIANT=apache
- VERSION=develop PHP_VERSION=7.3 VARIANT=fpm
- VERSION=develop PHP_VERSION=7.3 VARIANT=fpm-alpine
2 changes: 1 addition & 1 deletion template/Dockerfile.alpine.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM %%ARCHI%%/php:%%PHP_VERSION%%-%%VARIANT%%
FROM php:%%PHP_VERSION%%-%%VARIANT%%

# Install the packages we need
# Install the PHP extensions we need
Expand Down
2 changes: 1 addition & 1 deletion template/Dockerfile.debian.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM %%ARCHI%%/php:%%PHP_VERSION%%-%%VARIANT%%
FROM php:%%PHP_VERSION%%-%%VARIANT%%

# Install the packages we need
# Install the PHP extensions we need
Expand Down
1 change: 0 additions & 1 deletion template/docker-compose.apache.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ services:
context: ./
dockerfile: Dockerfile
args:
- TAG=${TAG}
- VCS_REF=${VCS_REF}
- BUILD_DATE=${BUILD_DATE}
image: ${IMAGE_NAME}
Expand Down
1 change: 0 additions & 1 deletion template/docker-compose.fpm.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ services:
context: ./
dockerfile: Dockerfile
args:
- TAG=${TAG}
- VCS_REF=${VCS_REF}
- BUILD_DATE=${BUILD_DATE}
image: ${IMAGE_NAME}
Expand Down
4 changes: 2 additions & 2 deletions template/hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# https://docs.docker.com/docker-hub/builds/advanced/
# https://microbadger.com/labels

docker build \
--build-arg "TAG=${DOCKER_TAG}" \
docker buildx build \
--build-arg "VCS_REF=$(git rev-parse --short HEAD)" \
--build-arg "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--load \
-f "$DOCKERFILE_PATH" \
-t "$IMAGE_NAME" .
9 changes: 7 additions & 2 deletions template/hooks/post_push
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
if [ -f ./.dockertags ]; then
for tag in $(cat ./.dockertags); do
if [ ! "${tag}" = "${DOCKER_TAG}" ]; then
docker tag "$IMAGE_NAME" "$DOCKER_REPO:$tag"
docker push "$DOCKER_REPO:$tag"
docker buildx build \
--build-arg "VCS_REF=$(git rev-parse --short HEAD)" \
--build-arg "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--platform "$DOCKER_PLATFORM" \
--push \
-f "$DOCKERFILE_PATH" \
-t "$DOCKER_REPO:$tag" .
fi
done
fi
Expand Down
2 changes: 1 addition & 1 deletion template/hooks/pre_push
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# https://docs.docker.com/docker-hub/builds/advanced/

if [ -n "${DOCKER_PASSWORD}" ] && [ -n "${DOCKER_REGISTRY}" ]; then
docker login -u "${DOCKER_LOGIN}" -p "${DOCKER_PASSWORD}" "${DOCKER_REGISTRY}"
echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_LOGIN}" --password-stdin "${DOCKER_REGISTRY}"
fi
3 changes: 3 additions & 0 deletions template/hooks/pre_test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if [ ! -f '.env' ]; then
mv .env.tmp .env
fi

export VCS_REF=$(git rev-parse --short HEAD)
export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

#echo 'Preparing persisted data...'
#mkdir -p "${APP_HOME:-/srv/dolibarr}"
#chown 777 "${APP_HOME:-/srv/dolibarr}"
34 changes: 34 additions & 0 deletions template/hooks/run_push
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Custom script to run locally DockerHub hooks
# See documentation for details:
# https://docs.docker.com/docker-hub/builds/advanced/

echo "Custom script to run locally DockerHub hooks..."
set -e

export SOURCE_BRANCH
SOURCE_BRANCH=$(git rev-parse --abbrev-ref HEAD)
export SOURCE_COMMIT
SOURCE_COMMIT=$(git rev-parse --short HEAD)
export COMMIT_MSG
COMMIT_MSG=$(git log -1 --format=%s)

export DOCKER_REPO=monogramm/docker-dolibarr
export DOCKERFILE_PATH=Dockerfile
export DOCKER_TAG=${VARIANT}
export IMAGE_NAME=${DOCKER_REPO}:${DOCKER_TAG}

# Execute hooks in given order
IFS=',' read -ra STEPS <<< "${1:-push}"
for step in "${STEPS[@]}"
do
for hook in "pre_${step}" "${step}" "post_${step}"; do
if [ -f "./hooks/${hook}" ]; then
echo "Executing ${hook} hook..."
"./hooks/${hook}"
fi
done
done

echo "DockerHub hooks finished"
122 changes: 54 additions & 68 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ variants=(
fpm-alpine
)

archis=(
amd64
#arm32v5
#arm32v6
#arm32v7
#arm64v8
i386
#ppc64le
)

min_version='10.0'
dockerLatest='13.0'

Expand Down Expand Up @@ -73,69 +63,65 @@ for latest in "${latests[@]}"; do
for php_version in "${php_versions[@]}"; do

for variant in "${variants[@]}"; do

for archi in "${archis[@]}"; do
# Create the version+php_version+variant directory with a Dockerfile.
dir="images/$version/php$php_version-$variant-$archi"
if [ -d "$dir" ]; then
continue
fi
echo "generating $latest [$version] php$php_version-$variant-$archi"
mkdir -p "$dir"

# Copy the files
template="template/Dockerfile.${base[$variant]}.template"
cp "$template" "$dir/Dockerfile"
cp "template/entrypoint.sh" "$dir/entrypoint.sh"

cp -r "template/hooks" "$dir/"
cp -r "template/test" "$dir/"
cp "template/.env" "$dir/.env"
cp "template/.dockerignore" "$dir/.dockerignore"
cp "template/docker-compose.${compose[$variant]}.test.yml" "$dir/docker-compose.test.yml"

if [ -n "${conf[$variant]}" ] && [ -d "template/${conf[$variant]}" ]; then
cp -r "template/${conf[$variant]}" "$dir/${conf[$variant]}"
# Create the version+php_version+variant directory with a Dockerfile.
dir="images/$version/php$php_version-$variant"
if [ -d "$dir" ]; then
continue
fi
echo "generating $latest [$version] php$php_version-$variant"
mkdir -p "$dir"

# Copy the files
template="template/Dockerfile.${base[$variant]}.template"
cp "$template" "$dir/Dockerfile"
cp "template/entrypoint.sh" "$dir/entrypoint.sh"

cp -r "template/hooks" "$dir/"
cp -r "template/test" "$dir/"
cp "template/.env" "$dir/.env"
cp "template/.dockerignore" "$dir/.dockerignore"
cp "template/docker-compose.${compose[$variant]}.test.yml" "$dir/docker-compose.test.yml"

if [ -n "${conf[$variant]}" ] && [ -d "template/${conf[$variant]}" ]; then
cp -r "template/${conf[$variant]}" "$dir/${conf[$variant]}"
fi

# Replace the variables.
sed -ri -e '
s/%%PHP_VERSION%%/'"$php_version"'/g;
s/%%VARIANT%%/'"$variant"'/g;
s/%%VERSION%%/'"$latest"'/g;
s/%%CMD%%/'"${cmd[$variant]}"'/g;
' "$dir/Dockerfile"

sed -ri -e '
s|DOCKER_TAG=.*|DOCKER_TAG='"$version"'|g;
s|DOCKER_REPO=.*|DOCKER_REPO='"$dockerRepo"'|g;
' "$dir/hooks/run"

# Create a list of "alias" tags for DockerHub post_push
if [ "$version" = "$dockerLatest" ]; then
if [ "$variant" = 'apache' ]; then
echo "$latest-$variant $version-$variant $variant $latest $version latest " > "$dir/.dockertags"
else
echo "$latest-$variant $version-$variant $variant " > "$dir/.dockertags"
fi

# Replace the variables.
sed -ri -e '
s/%%PHP_VERSION%%/'"$php_version"'/g;
s/%%VARIANT%%/'"$variant"'/g;
s/%%ARCHI%%/'"$archi"'/g;
s/%%VERSION%%/'"$latest"'/g;
s/%%CMD%%/'"${cmd[$variant]}"'/g;
' "$dir/Dockerfile"

sed -ri -e '
s|DOCKER_TAG=.*|DOCKER_TAG='"$version"'|g;
s|DOCKER_REPO=.*|DOCKER_REPO='"$dockerRepo"'|g;
' "$dir/hooks/run"

# Create a list of "alias" tags for DockerHub post_push
if [ "$version" = "$dockerLatest" ]; then
if [ "$variant" = 'apache' ]; then
echo "$latest-$variant $version-$variant $variant $latest $version latest " > "$dir/.dockertags"
else
echo "$latest-$variant $version-$variant $variant " > "$dir/.dockertags"
fi
else
if [ "$variant" = 'apache' ]; then
echo "$latest-$variant $version-$variant $latest $version " > "$dir/.dockertags"
else
if [ "$variant" = 'apache' ]; then
echo "$latest-$variant $version-$variant $latest $version " > "$dir/.dockertags"
else
echo "$latest-$variant $version-$variant " > "$dir/.dockertags"
fi
echo "$latest-$variant $version-$variant " > "$dir/.dockertags"
fi
fi

# Add Travis-CI env var
travisEnv='\n - VERSION='"$version"' PHP_VERSION='"$php_version"' VARIANT='"$variant"' ARCHI='"$archi$travisEnv"
# Add Travis-CI env var
travisEnv="$travisEnv"'\n - VERSION='"$version"' PHP_VERSION='"$php_version"' VARIANT='"$variant"

if [[ $1 == 'build' ]]; then
tag="$version-$php_version-$variant"
echo "Build Dockerfile for ${tag}"
docker build -t "${dockerRepo}:${tag}" "$dir"
fi
done
if [[ $1 == 'build' ]]; then
tag="$version-$php_version-$variant"
echo "Build Dockerfile for ${tag}"
docker build -t "${dockerRepo}:${tag}" "$dir"
fi

done

Expand Down

0 comments on commit 276a354

Please sign in to comment.