diff --git a/.github/workflows/hooks.yml b/.github/workflows/hooks.yml index 1437a9d..03740c0 100644 --- a/.github/workflows/hooks.yml +++ b/.github/workflows/hooks.yml @@ -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 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..fea23c4 --- /dev/null +++ b/.github/workflows/push.yml @@ -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 diff --git a/.travis.yml b/.travis.yml index 41bbd67..9ac21e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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} @@ -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 diff --git a/template/Dockerfile.alpine.template b/template/Dockerfile.alpine.template index a3c44c3..0c077c5 100644 --- a/template/Dockerfile.alpine.template +++ b/template/Dockerfile.alpine.template @@ -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 diff --git a/template/Dockerfile.debian.template b/template/Dockerfile.debian.template index 383a092..1cd4d77 100644 --- a/template/Dockerfile.debian.template +++ b/template/Dockerfile.debian.template @@ -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 diff --git a/template/docker-compose.apache.test.yml b/template/docker-compose.apache.test.yml index d4728e0..ec96a5d 100644 --- a/template/docker-compose.apache.test.yml +++ b/template/docker-compose.apache.test.yml @@ -35,7 +35,6 @@ services: context: ./ dockerfile: Dockerfile args: - - TAG=${TAG} - VCS_REF=${VCS_REF} - BUILD_DATE=${BUILD_DATE} image: ${IMAGE_NAME} diff --git a/template/docker-compose.fpm.test.yml b/template/docker-compose.fpm.test.yml index 428bbae..9e03541 100644 --- a/template/docker-compose.fpm.test.yml +++ b/template/docker-compose.fpm.test.yml @@ -35,7 +35,6 @@ services: context: ./ dockerfile: Dockerfile args: - - TAG=${TAG} - VCS_REF=${VCS_REF} - BUILD_DATE=${BUILD_DATE} image: ${IMAGE_NAME} diff --git a/template/hooks/build b/template/hooks/build index d236947..94a32e8 100755 --- a/template/hooks/build +++ b/template/hooks/build @@ -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" . diff --git a/template/hooks/post_push b/template/hooks/post_push index b0aa55b..3223a1c 100755 --- a/template/hooks/post_push +++ b/template/hooks/post_push @@ -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 diff --git a/template/hooks/pre_push b/template/hooks/pre_push index 33d1f87..e9bb0c6 100755 --- a/template/hooks/pre_push +++ b/template/hooks/pre_push @@ -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 diff --git a/template/hooks/pre_test b/template/hooks/pre_test index a7936aa..0bbb213 100755 --- a/template/hooks/pre_test +++ b/template/hooks/pre_test @@ -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}" diff --git a/template/hooks/run_push b/template/hooks/run_push new file mode 100644 index 0000000..c2c86d3 --- /dev/null +++ b/template/hooks/run_push @@ -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" diff --git a/update.sh b/update.sh index 5c6e44b..d8a8365 100755 --- a/update.sh +++ b/update.sh @@ -31,16 +31,6 @@ variants=( fpm-alpine ) -archis=( - amd64 - #arm32v5 - #arm32v6 - #arm32v7 - #arm64v8 - i386 - #ppc64le -) - min_version='10.0' dockerLatest='13.0' @@ -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