From 26f44fcc5b3e12cd8db31b27ec5a27310613c638 Mon Sep 17 00:00:00 2001 From: cytopia Date: Fri, 11 Feb 2022 13:36:51 +0100 Subject: [PATCH 1/7] Consolidate GH Action jobs --- .github/workflows/build.yml | 117 ++++------------------------------ .github/workflows/nightly.yml | 117 ++++------------------------------ Makefile | 55 +++++++++++++--- 3 files changed, 69 insertions(+), 220 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f36067..d0c6120 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,49 +48,9 @@ jobs: image: tonistiigi/binfmt:latest platforms: arm64 - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - - - name: Set variables - id: vars - run: | - - # Retrieve git info (tags, etc) - git fetch --all - - # Branch, Tag or Commit - GIT_TYPE="$( \ - curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ - | sh \ - | grep '^GIT_TYPE' \ - | sed 's|.*=||g' \ - )" - # Branch name, Tag name or Commit Hash - GIT_SLUG="$( \ - curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ - | sh \ - | grep '^GIT_NAME' \ - | sed 's|.*=||g' \ - )" - # Docker Tag - if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then - DOCKER_TAG="latest" - else - DOCKER_TAG="${GIT_SLUG}" - fi - - # Output - echo "GIT_TYPE=${GIT_TYPE}" - echo "GIT_SLUG=${GIT_SLUG}" - echo "DOCKER_TAG=${DOCKER_TAG}" - - # Export variable - # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files - echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV} - echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV} - echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV} - + - name: Set Docker tag + id: tag + uses: cytopia/docker-tags@v0.2 # ------------------------------------------------------------ # Build @@ -177,19 +137,11 @@ jobs: done; return 1; } - - # Output - echo "GIT_TYPE=${GIT_TYPE}" - echo "GIT_SLUG=${GIT_SLUG}" - echo "DOCKER_TAG=${DOCKER_TAG}" - - # Tag image - retry make tag TAG=${DOCKER_TAG} - docker images - - # Login and Push + # Login retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} - retry make push TAG=${DOCKER_TAG}-manifest-${ARCH##*/} + + # Push arch-specific image (for later manifest creation) + retry make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} RETRIES: 20 @@ -226,45 +178,9 @@ jobs: with: fetch-depth: 0 - - name: Set variables - id: vars - run: | - - # Retrieve git info (tags, etc) - git fetch --all - - # Branch, Tag or Commit - GIT_TYPE="$( \ - curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ - | sh \ - | grep '^GIT_TYPE' \ - | sed 's|.*=||g' \ - )" - # Branch name, Tag name or Commit Hash - GIT_SLUG="$( \ - curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ - | sh \ - | grep '^GIT_NAME' \ - | sed 's|.*=||g' \ - )" - # Docker Tag - if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then - DOCKER_TAG="latest" - else - DOCKER_TAG="${GIT_SLUG}" - fi - - # Output - echo "GIT_TYPE=${GIT_TYPE}" - echo "GIT_SLUG=${GIT_SLUG}" - echo "DOCKER_TAG=${DOCKER_TAG}" - - # Export variable - # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files - echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV} - echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV} - echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV} - + - name: Set Docker tag + id: tag + uses: cytopia/docker-tags@v0.2 # ------------------------------------------------------------ # Deploy @@ -283,23 +199,14 @@ jobs: done; return 1; } - - # Output - echo "GIT_TYPE=${GIT_TYPE}" - echo "GIT_SLUG=${GIT_SLUG}" - echo "DOCKER_TAG=${DOCKER_TAG}" - # Login retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} # Create manifest - docker manifest create \ - devilbox/php-fpm-8.2:${DOCKER_TAG} \ - --amend devilbox/php-fpm-8.2:${DOCKER_TAG}-manifest-amd64 \ - --amend devilbox/php-fpm-8.2:${DOCKER_TAG}-manifest-arm64 + retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="amd64 arm64" # Push manifest - docker manifest push devilbox/php-fpm-8.2:${DOCKER_TAG} + retry make manifest-push TAG=${{ steps.tag.outputs.docker-tag }} env: RETRIES: 20 PAUSE: 10 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index a6fa1e0..448c507 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -51,49 +51,9 @@ jobs: image: tonistiigi/binfmt:latest platforms: arm64 - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - - - name: Set variables - id: vars - run: | - - # Retrieve git info (tags, etc) - git fetch --all - - # Branch, Tag or Commit - GIT_TYPE="$( \ - curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ - | sh \ - | grep '^GIT_TYPE' \ - | sed 's|.*=||g' \ - )" - # Branch name, Tag name or Commit Hash - GIT_SLUG="$( \ - curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ - | sh \ - | grep '^GIT_NAME' \ - | sed 's|.*=||g' \ - )" - # Docker Tag - if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then - DOCKER_TAG="latest" - else - DOCKER_TAG="${GIT_SLUG}" - fi - - # Output - echo "GIT_TYPE=${GIT_TYPE}" - echo "GIT_SLUG=${GIT_SLUG}" - echo "DOCKER_TAG=${DOCKER_TAG}" - - # Export variable - # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files - echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV} - echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV} - echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV} - + - name: Set Docker tag + id: tag + uses: cytopia/docker-tags@v0.2 # ------------------------------------------------------------ # Build @@ -180,19 +140,11 @@ jobs: done; return 1; } - - # Output - echo "GIT_TYPE=${GIT_TYPE}" - echo "GIT_SLUG=${GIT_SLUG}" - echo "DOCKER_TAG=${DOCKER_TAG}" - - # Tag image - retry make tag TAG=${DOCKER_TAG} - docker images - - # Login and Push + # Login retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} - retry make push TAG=${DOCKER_TAG}-manifest-${ARCH##*/} + + # Push arch-specific image (for later manifest creation) + retry make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} RETRIES: 20 @@ -233,45 +185,9 @@ jobs: fetch-depth: 0 ref: ${{ matrix.refs }} - - name: Set variables - id: vars - run: | - - # Retrieve git info (tags, etc) - git fetch --all - - # Branch, Tag or Commit - GIT_TYPE="$( \ - curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ - | sh \ - | grep '^GIT_TYPE' \ - | sed 's|.*=||g' \ - )" - # Branch name, Tag name or Commit Hash - GIT_SLUG="$( \ - curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ - | sh \ - | grep '^GIT_NAME' \ - | sed 's|.*=||g' \ - )" - # Docker Tag - if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then - DOCKER_TAG="latest" - else - DOCKER_TAG="${GIT_SLUG}" - fi - - # Output - echo "GIT_TYPE=${GIT_TYPE}" - echo "GIT_SLUG=${GIT_SLUG}" - echo "DOCKER_TAG=${DOCKER_TAG}" - - # Export variable - # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files - echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV} - echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV} - echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV} - + - name: Set Docker tag + id: tag + uses: cytopia/docker-tags@v0.2 # ------------------------------------------------------------ # Deploy @@ -290,23 +206,14 @@ jobs: done; return 1; } - - # Output - echo "GIT_TYPE=${GIT_TYPE}" - echo "GIT_SLUG=${GIT_SLUG}" - echo "DOCKER_TAG=${DOCKER_TAG}" - # Login retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} # Create manifest - docker manifest create \ - devilbox/php-fpm-8.2:${DOCKER_TAG} \ - --amend devilbox/php-fpm-8.2:${DOCKER_TAG}-manifest-amd64 \ - --amend devilbox/php-fpm-8.2:${DOCKER_TAG}-manifest-arm64 + retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="amd64 arm64" # Push manifest - docker manifest push devilbox/php-fpm-8.2:${DOCKER_TAG} + retry make manifest-push TAG=${{ steps.tag.outputs.docker-tag }} env: RETRIES: 20 PAUSE: 10 diff --git a/Makefile b/Makefile index 5e3706a..79f420e 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,6 @@ endif # Docker configuration # ------------------------------------------------------------------------------------------------- -.PHONY: build rebuild test tag pull login push enter - DIR = . FILE = Dockerfile IMAGE = devilbox/php-fpm-8.2 @@ -20,13 +18,19 @@ NO_CACHE = # ------------------------------------------------------------------------------------------------- # Default Target # ------------------------------------------------------------------------------------------------- - +.PHONY: help help: @echo "lint Lint project files and repository" + @echo @echo "build Build Docker image" @echo "rebuild Build Docker image without cache" + @echo + @echo "manifest-create Create multi-arch manifest" + @echo "manifest-push Push multi-arch manifest" + @echo @echo "test Test built Docker image" @echo "update-readme Update README.md with PHP modules" + @echo @echo "tag [TAG=...] Retag Docker image" @echo "login USER=... PASS=... Login to Docker hub" @echo "push [TAG=...] Push Docker image to Docker hub" @@ -35,9 +39,10 @@ help: # ------------------------------------------------------------------------------------------------- # Lint Targets # ------------------------------------------------------------------------------------------------- -# +.PHONY: lint lint: lint-workflow +.PHONY: lint-workflow lint-workflow: @\ GIT_CURR_MAJOR="$$( git tag | sort -V | tail -1 | sed 's|\.[0-9]*$$||g' )"; \ @@ -59,22 +64,44 @@ lint-workflow: # ------------------------------------------------------------------------------------------------- # Build Targets # ------------------------------------------------------------------------------------------------- - +.PHONY: build build: - docker buildx build --output type=docker --platform=$(ARCH) $(NO_CACHE) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) + docker build --platform=$(ARCH) $(NO_CACHE) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR) +.PHONY: rebuild rebuild: NO_CACHE=--no-cache rebuild: pull-base-image rebuild: build # ------------------------------------------------------------------------------------------------- -# Test Targets +# Manifest Targets # ------------------------------------------------------------------------------------------------- +.PHONY: manifest-create +manifest-create: + @echo "docker manifest create \ + $(IMAGE):$(TAG) \ + $$( echo $(ARCH) | sed 's/,/ /g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1##*/}"' -- )" \ + | sed 's/\s\s*/ /g' \ + | sed 's/--/\\\n --/g' + @echo "docker manifest create \ + $(IMAGE):$(TAG) \ + $$( echo $(ARCH) | sed 's/,/ /g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1##*/}"' -- )" \ + | bash + +.PHONY: manifest-push +manifest-push: + docker manifest push $(IMAGE):$(TAG) + +# ------------------------------------------------------------------------------------------------- +# Test Targets +# ------------------------------------------------------------------------------------------------- +.PHONY: test test: ./tests/test.sh $(IMAGE) $(ARCH) +.PHONY: update-readme update-readme: cat "./README.md" \ | perl -0 -pe "s/.*/\n$$(./tests/get-modules.sh $(IMAGE) $(ARCH))\n/s" \ @@ -85,24 +112,32 @@ update-readme: # ------------------------------------------------------------------------------------------------- # Deploy Targets # ------------------------------------------------------------------------------------------------- - +.PHONY: tag tag: docker tag $(IMAGE) $(IMAGE):$(TAG) +.PHONY: login login: yes | docker login --username $(USER) --password $(PASS) +.PHONY: push push: @$(MAKE) tag TAG=$(TAG) docker push $(IMAGE):$(TAG) +.PHONY: push-arch +push-arch: + $(MAKE) tag TAG=$(TAG)-manifest-$(subst linux/,,$(ARCH)) + docker push $(IMAGE):$(TAG)-manifest-$(subst linux/,,$(ARCH)) + # ------------------------------------------------------------------------------------------------- # Helper Targets # ------------------------------------------------------------------------------------------------- - +.PHONY: enter enter: - docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=bash $(ARG) $(IMAGE) + docker run --rm --platform=$(ARCH) -it --entrypoint=bash $(ARG) $(IMAGE) +.PHONY: pull-base-image pull-base-image: @docker pull $(shell grep FROM Dockerfile | sed 's/^FROM\s*//g';) From 08a646a3f00b15337bb9c9ef4108f25088f0e773 Mon Sep 17 00:00:00 2001 From: cytopia Date: Fri, 11 Feb 2022 13:39:25 +0100 Subject: [PATCH 2/7] Fix typos --- .github/workflows/build.yml | 4 ++-- .github/workflows/nightly.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d0c6120..afd89ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: - name: Set Docker tag id: tag - uses: cytopia/docker-tags@v0.2 + uses: cytopia/docker-tag@v0.2 # ------------------------------------------------------------ # Build @@ -180,7 +180,7 @@ jobs: - name: Set Docker tag id: tag - uses: cytopia/docker-tags@v0.2 + uses: cytopia/docker-tag@v0.2 # ------------------------------------------------------------ # Deploy diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 448c507..e10bfde 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -33,7 +33,7 @@ jobs: - 'linux/arm64' refs: - 'master' - - '0.2' + - '0.3' steps: # ------------------------------------------------------------ @@ -53,7 +53,7 @@ jobs: - name: Set Docker tag id: tag - uses: cytopia/docker-tags@v0.2 + uses: cytopia/docker-tag@v0.2 # ------------------------------------------------------------ # Build @@ -173,7 +173,7 @@ jobs: - '8.2' refs: - 'master' - - '0.2' + - '0.3' steps: # ------------------------------------------------------------ @@ -187,7 +187,7 @@ jobs: - name: Set Docker tag id: tag - uses: cytopia/docker-tags@v0.2 + uses: cytopia/docker-tag@v0.2 # ------------------------------------------------------------ # Deploy From 3821ad3ebf88fcfa622ee05b51290265d9d0ed6e Mon Sep 17 00:00:00 2001 From: cytopia Date: Fri, 11 Feb 2022 14:04:04 +0100 Subject: [PATCH 3/7] Use login action --- .github/workflows/build.yml | 23 ++++++++++++++--------- .github/workflows/nightly.yml | 23 ++++++++++++++--------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index afd89ce..cec8cb4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: - name: Set Docker tag id: tag - uses: cytopia/docker-tag@v0.2 + uses: cytopia/docker-tag@v0.3 # ------------------------------------------------------------ # Build @@ -123,6 +123,12 @@ jobs: # ------------------------------------------------------------ # Deploy # ------------------------------------------------------------ + - name: Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Publish architecture images (only repo owner) run: | retry() { @@ -137,10 +143,6 @@ jobs: done; return 1; } - # Login - retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} - - # Push arch-specific image (for later manifest creation) retry make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} @@ -180,11 +182,17 @@ jobs: - name: Set Docker tag id: tag - uses: cytopia/docker-tag@v0.2 + uses: cytopia/docker-tag@v0.3 # ------------------------------------------------------------ # Deploy # ------------------------------------------------------------ + - name: Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Publish final multi-arch image (only repo owner) run: | retry() { @@ -199,9 +207,6 @@ jobs: done; return 1; } - # Login - retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} - # Create manifest retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="amd64 arm64" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index e10bfde..937125e 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -53,7 +53,7 @@ jobs: - name: Set Docker tag id: tag - uses: cytopia/docker-tag@v0.2 + uses: cytopia/docker-tag@v0.3 # ------------------------------------------------------------ # Build @@ -126,6 +126,12 @@ jobs: # ------------------------------------------------------------ # Deploy # ------------------------------------------------------------ + - name: Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Publish architecture images (only repo owner) run: | retry() { @@ -140,10 +146,6 @@ jobs: done; return 1; } - # Login - retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} - - # Push arch-specific image (for later manifest creation) retry make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} @@ -187,11 +189,17 @@ jobs: - name: Set Docker tag id: tag - uses: cytopia/docker-tag@v0.2 + uses: cytopia/docker-tag@v0.3 # ------------------------------------------------------------ # Deploy # ------------------------------------------------------------ + - name: Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Publish final multi-arch image (only repo owner) run: | retry() { @@ -206,9 +214,6 @@ jobs: done; return 1; } - # Login - retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }} - # Create manifest retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="amd64 arm64" From 775eb81aff83f0e216600cf30e4521c3039b7ab0 Mon Sep 17 00:00:00 2001 From: cytopia Date: Fri, 11 Feb 2022 15:40:47 +0100 Subject: [PATCH 4/7] Support more architectures --- .github/workflows/build.yml | 7 +++++-- .github/workflows/nightly.yml | 7 +++++-- Makefile | 8 ++++---- README.md | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cec8cb4..dba7520 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,6 +32,9 @@ jobs: arch: - 'linux/amd64' - 'linux/arm64' + - 'linux/386' + - 'linux/arm/v7' + - 'linux/arm/v6' steps: # ------------------------------------------------------------ @@ -46,7 +49,7 @@ jobs: uses: docker/setup-qemu-action@v1 with: image: tonistiigi/binfmt:latest - platforms: arm64 + platforms: all - name: Set Docker tag id: tag @@ -208,7 +211,7 @@ jobs: return 1; } # Create manifest - retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="amd64 arm64" + retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="linux/amd64 linux/arm64 linux/386 linux/arm/v7 linux/arm/v6" # Push manifest retry make manifest-push TAG=${{ steps.tag.outputs.docker-tag }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 937125e..51a69a0 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -31,6 +31,9 @@ jobs: arch: - 'linux/amd64' - 'linux/arm64' + - 'linux/386' + - 'linux/arm/v7' + - 'linux/arm/v6' refs: - 'master' - '0.3' @@ -49,7 +52,7 @@ jobs: uses: docker/setup-qemu-action@v1 with: image: tonistiigi/binfmt:latest - platforms: arm64 + platforms: all - name: Set Docker tag id: tag @@ -215,7 +218,7 @@ jobs: return 1; } # Create manifest - retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="amd64 arm64" + retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="linux/amd64 linux/arm64 linux/386 linux/arm/v7 linux/arm/v6" # Push manifest retry make manifest-push TAG=${{ steps.tag.outputs.docker-tag }} diff --git a/Makefile b/Makefile index 79f420e..68169ce 100644 --- a/Makefile +++ b/Makefile @@ -81,12 +81,12 @@ rebuild: build manifest-create: @echo "docker manifest create \ $(IMAGE):$(TAG) \ - $$( echo $(ARCH) | sed 's/,/ /g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1##*/}"' -- )" \ + $$( echo $(ARCH) | sed 's/,/ /g' | sed 's|/|-|g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1}"' -- )" \ | sed 's/\s\s*/ /g' \ | sed 's/--/\\\n --/g' @echo "docker manifest create \ $(IMAGE):$(TAG) \ - $$( echo $(ARCH) | sed 's/,/ /g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1##*/}"' -- )" \ + $$( echo $(ARCH) | sed 's/,/ /g' | sed 's|/|-|g' | xargs -n1 sh -c 'printf -- " --amend $(IMAGE):$(TAG)-manifest-$${1}"' -- )" \ | bash .PHONY: manifest-push @@ -127,8 +127,8 @@ push: .PHONY: push-arch push-arch: - $(MAKE) tag TAG=$(TAG)-manifest-$(subst linux/,,$(ARCH)) - docker push $(IMAGE):$(TAG)-manifest-$(subst linux/,,$(ARCH)) + $(MAKE) tag TAG=$(TAG)-manifest-$(subst /,-,$(ARCH)) + docker push $(IMAGE):$(TAG)-manifest-$(subst /,-,$(ARCH)) # ------------------------------------------------------------------------------------------------- diff --git a/README.md b/README.md index ead74d9..3e99af0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![](https://images.microbadger.com/badges/image/devilbox/php-fpm-8.2.svg)](https://microbadger.com/images/devilbox/php-fpm-8.2 "php-fpm-8.2") [![License](https://img.shields.io/badge/license-MIT-%233DA639.svg)](https://opensource.org/licenses/MIT) -**Supported Architectures:** AMD64, ARM64 +**Available Architectures:** `amd64`, `arm64`, `386`, `arm/v7`, `arm/v6` This repository will provide you a fully functional PHP-FPM 8.2 Docker image built from [official sources](https://github.com/php/php-src) nightly. It provides the base for [Devilbox PHP-FPM Docker images](https://github.com/devilbox/docker-php-fpm). From 7a545358240a5c76b3d990fdfd189ff8823de70a Mon Sep 17 00:00:00 2001 From: cytopia Date: Fri, 11 Feb 2022 17:54:54 +0100 Subject: [PATCH 5/7] Simplify CI --- .github/workflows/build.yml | 141 ++++++++++------------------------ .github/workflows/nightly.yml | 139 ++++++++++----------------------- tests/test.sh | 5 ++ 3 files changed, 88 insertions(+), 197 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dba7520..cd76bc5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ on: jobs: # ----------------------------------------------------------------------------------------------- - # Job: BUILD + # Job (1/2): BUILD # ----------------------------------------------------------------------------------------------- build: name: "[ PHP-${{ matrix.version }} (${{ matrix.arch }}) ]" @@ -40,18 +40,18 @@ jobs: # ------------------------------------------------------------ # Setup repository # ------------------------------------------------------------ - - name: Checkout repository + - name: "[SETUP] Checkout repository" uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Set up QEMU + - name: "[SETUP] Setup QEMU environment" uses: docker/setup-qemu-action@v1 with: image: tonistiigi/binfmt:latest platforms: all - - name: Set Docker tag + - name: "[SETUP] Determine Docker tag" id: tag uses: cytopia/docker-tag@v0.3 @@ -59,98 +59,52 @@ jobs: # Build # ------------------------------------------------------------ - name: Build - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - retry make build ARCH=${ARCH} + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make build ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} - RETRIES: 20 - PAUSE: 10 # ------------------------------------------------------------ # Test # ------------------------------------------------------------ - - name: Test Docker Image - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - retry make test ARCH=${ARCH} + - name: "[TEST] Docker Image" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make test ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} - RETRIES: 20 - PAUSE: 10 - - name: Test Repository Readme - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - retry make update-readme ARCH=${ARCH} - git diff --quiet || { echo "Build Changes"; git diff; git status; false; } + - name: "[TEST] Update README" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make update-readme ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} - RETRIES: 20 - PAUSE: 10 + - name: "[TEST] Verify README" + run: | + git diff --quiet || { echo "Build Changes"; git diff; git status; false; } # ------------------------------------------------------------ # Deploy # ------------------------------------------------------------ - - name: Login + - name: "[DEPLOY] Login" uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Publish architecture images (only repo owner) - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - retry make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH} + - name: "[DEPLOY] Publish architecture image (only repo owner)" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} - RETRIES: 20 - PAUSE: 10 # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id && ( @@ -162,7 +116,7 @@ jobs: ) # ----------------------------------------------------------------------------------------------- - # Job: DEPLOY + # Job (2/2): DEPLOY # ----------------------------------------------------------------------------------------------- deploy: needs: [build] @@ -178,46 +132,35 @@ jobs: # ------------------------------------------------------------ # Setup repository # ------------------------------------------------------------ - - name: Checkout repository + - name: "[SETUP] Checkout repository" uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Set Docker tag + - name: "[SETUP] Determine Docker tag" id: tag uses: cytopia/docker-tag@v0.3 # ------------------------------------------------------------ # Deploy # ------------------------------------------------------------ - - name: Login + - name: "[DEPLOY] Login" uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Publish final multi-arch image (only repo owner) - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - # Create manifest - retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="linux/amd64 linux/arm64 linux/386 linux/arm/v7 linux/arm/v6" - - # Push manifest - retry make manifest-push TAG=${{ steps.tag.outputs.docker-tag }} - env: - RETRIES: 20 - PAUSE: 10 + - name: "[DEPLOY] Create Docker manifest" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6" + + - name: "[DEPLOY] Publish Docker manifest (only repo owner)" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make manifest-push TAG=${{ steps.tag.outputs.docker-tag }} # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id && ( diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 51a69a0..eead512 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -42,19 +42,19 @@ jobs: # ------------------------------------------------------------ # Setup repository # ------------------------------------------------------------ - - name: Checkout repository + - name: "[SETUP] Checkout repository" uses: actions/checkout@v2 with: fetch-depth: 0 ref: ${{ matrix.refs }} - - name: Set up QEMU + - name: "[SETUP] Setup QEMU environment" uses: docker/setup-qemu-action@v1 with: image: tonistiigi/binfmt:latest platforms: all - - name: Set Docker tag + - name: "[SETUP] Determine Docker tag" id: tag uses: cytopia/docker-tag@v0.3 @@ -62,98 +62,52 @@ jobs: # Build # ------------------------------------------------------------ - name: Build - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - retry make build ARCH=${ARCH} + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make build ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} - RETRIES: 20 - PAUSE: 10 # ------------------------------------------------------------ # Test # ------------------------------------------------------------ - - name: Test Docker Image - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - retry make test ARCH=${ARCH} + - name: "[TEST] Docker Image" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make test ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} - RETRIES: 20 - PAUSE: 10 - - name: Test Repository Readme - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - retry make update-readme ARCH=${ARCH} - git diff --quiet || { echo "Build Changes"; git diff; git status; false; } + - name: "[TEST] Update README" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make update-readme ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} - RETRIES: 20 - PAUSE: 10 + - name: "[TEST] Verify README" + run: | + git diff --quiet || { echo "Build Changes"; git diff; git status; false; } # ------------------------------------------------------------ # Deploy # ------------------------------------------------------------ - - name: Login + - name: "[DEPLOY] Login" uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Publish architecture images (only repo owner) - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - retry make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH} + - name: "[DEPLOY] Publish architecture image (only repo owner)" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${ARCH} env: ARCH: ${{ matrix.arch }} - RETRIES: 20 - PAUSE: 10 # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id && ( @@ -165,7 +119,7 @@ jobs: ) # ----------------------------------------------------------------------------------------------- - # Job: DEPLOY + # Job (2/2): DEPLOY # ----------------------------------------------------------------------------------------------- deploy: needs: [build] @@ -184,47 +138,36 @@ jobs: # ------------------------------------------------------------ # Setup repository # ------------------------------------------------------------ - - name: Checkout repository + - name: "[SETUP] Checkout repository" uses: actions/checkout@v2 with: fetch-depth: 0 ref: ${{ matrix.refs }} - - name: Set Docker tag + - name: "[SETUP] Determine Docker tag" id: tag uses: cytopia/docker-tag@v0.3 # ------------------------------------------------------------ # Deploy # ------------------------------------------------------------ - - name: Login + - name: "[DEPLOY] Login" uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Publish final multi-arch image (only repo owner) - run: | - retry() { - for n in $(seq ${RETRIES}); do - echo "[${n}/${RETRIES}] ${*}"; - if eval "${*}"; then - echo "[SUCC] ${n}/${RETRIES}"; - return 0; - fi; - sleep ${PAUSE}; - echo "[FAIL] ${n}/${RETRIES}"; - done; - return 1; - } - # Create manifest - retry make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="linux/amd64 linux/arm64 linux/386 linux/arm/v7 linux/arm/v6" - - # Push manifest - retry make manifest-push TAG=${{ steps.tag.outputs.docker-tag }} - env: - RETRIES: 20 - PAUSE: 10 + - name: "[DEPLOY] Create Docker manifest" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make manifest-create TAG=${{ steps.tag.outputs.docker-tag }} ARCH="linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6" + + - name: "[DEPLOY] Publish Docker manifest (only repo owner)" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make manifest-push TAG=${{ steps.tag.outputs.docker-tag }} # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id && ( diff --git a/tests/test.sh b/tests/test.sh index 0711ba5..778213e 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -7,5 +7,10 @@ set -o pipefail IMAGE="${1:-devilbox/php-fpm-8.2}" ARCH="${2:-linux/amd64}" +echo +echo "\$ docker run --rm --platform ${ARCH} --entrypoint=php ${IMAGE} -v | grep -E '^PHP 8\.2'" docker run --rm --platform "${ARCH}" --entrypoint=php "${IMAGE}" -v | grep -E '^PHP 8\.2' + +echo +echo "\$ docker run --rm --platform ${ARCH} --entrypoint=php-fpm ${IMAGE} -v | grep -E '^PHP 8\.2'" docker run --rm --platform "${ARCH}" --entrypoint=php-fpm "${IMAGE}" -v | grep -E '^PHP 8\.2' From d8ba5fb2258dfd29176ae16c76d6bb749fdb38d0 Mon Sep 17 00:00:00 2001 From: cytopia Date: Fri, 11 Feb 2022 17:58:18 +0100 Subject: [PATCH 6/7] Fix linting --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 68169ce..4a413b2 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ lint-workflow: GIT_CURR_MAJOR="$$( git tag | sort -V | tail -1 | sed 's|\.[0-9]*$$||g' )"; \ GIT_CURR_MINOR="$$( git tag | sort -V | tail -1 | sed 's|^[0-9]*\.||g' )"; \ GIT_NEXT_TAG="$${GIT_CURR_MAJOR}.$$(( GIT_CURR_MINOR + 1 ))"; \ - grep 'refs:' -A 100 .github/workflows/nightly.yml \ + grep 'refs:' -A 20 .github/workflows/nightly.yml \ | grep '^ -' \ | grep -v master \ | while read -r i; do \ From dba1ac04bc88aa33828efa1095a0942c999567f6 Mon Sep 17 00:00:00 2001 From: cytopia Date: Fri, 11 Feb 2022 18:54:30 +0100 Subject: [PATCH 7/7] Reduce duplicate CI jobs --- .github/workflows/build.yml | 2 - .github/workflows/contributor.yml | 90 +++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/contributor.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd76bc5..05c01da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,8 +10,6 @@ name: build # When to run # ------------------------------------------------------------------------------------------------- on: - # Runs on Pull Requests - pull_request: # Runs on Push push: diff --git a/.github/workflows/contributor.yml b/.github/workflows/contributor.yml new file mode 100644 index 0000000..2570bfa --- /dev/null +++ b/.github/workflows/contributor.yml @@ -0,0 +1,90 @@ +--- + +# ------------------------------------------------------------------------------------------------- +# Job Name +# ------------------------------------------------------------------------------------------------- +name: build + + +# ------------------------------------------------------------------------------------------------- +# When to run +# ------------------------------------------------------------------------------------------------- +on: + # Runs on Pull Requests + pull_request: + + +jobs: + + # ----------------------------------------------------------------------------------------------- + # Job (1/2): BUILD + # ----------------------------------------------------------------------------------------------- + build: + name: "[ PHP-${{ matrix.version }} (${{ matrix.arch }}) ]" + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + version: + - '8.2' + arch: + - 'linux/amd64' + - 'linux/arm64' + - 'linux/386' + - 'linux/arm/v7' + - 'linux/arm/v6' + # Only run for forks (contributor) + if: ${{ github.event.pull_request.head.repo.fork }} + steps: + + # ------------------------------------------------------------ + # Setup repository + # ------------------------------------------------------------ + - name: "[SETUP] Checkout repository" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: "[SETUP] Setup QEMU environment" + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: "[SETUP] Determine Docker tag" + id: tag + uses: cytopia/docker-tag@v0.3 + + # ------------------------------------------------------------ + # Build + # ------------------------------------------------------------ + - name: Build + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make build ARCH=${ARCH} + env: + ARCH: ${{ matrix.arch }} + + # ------------------------------------------------------------ + # Test + # ------------------------------------------------------------ + - name: "[TEST] Docker Image" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make test ARCH=${ARCH} + env: + ARCH: ${{ matrix.arch }} + + - name: "[TEST] Update README" + uses: cytopia/shell-command-retry-action@v0.1 + with: + command: | + make update-readme ARCH=${ARCH} + env: + ARCH: ${{ matrix.arch }} + + - name: "[TEST] Verify README" + run: | + git diff --quiet || { echo "Build Changes"; git diff; git status; false; }