From 001ee47e7a3ea8d7b3b4b182692865fa01763fec Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Tue, 29 Oct 2024 17:46:49 +0800 Subject: [PATCH 01/11] feat: try running arm64 build actions on macos-latest runner Signed-off-by: Yukai Huang --- .github/workflows/build-steps.yml | 65 ++++++++++++++++++++++++++++ .github/workflows/push-image.yml | 72 ++++++++----------------------- 2 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/build-steps.yml diff --git a/.github/workflows/build-steps.yml b/.github/workflows/build-steps.yml new file mode 100644 index 000000000..bead353eb --- /dev/null +++ b/.github/workflows/build-steps.yml @@ -0,0 +1,65 @@ +name: Build Steps + +on: + workflow_call: + inputs: + platform: + required: true + type: string + +jobs: + build: + runs-on: ${{ inputs.platform == 'linux/arm64' && 'macos-latest' || 'ubuntu-latest' }} + steps: + - + name: Prepare + run: | + echo "PLATFORM_PAIR=${{ inputs.platform//\//- }}" >> $GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v4 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./deployments/Dockerfile + platforms: ${{ inputs.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + build-args: | + RUNTIME=${{ github.event.inputs.runtime || 'hackmdio/runtime:16.20.2-35fe7e39' }} + BUILDPACK=${{ github.event.inputs.buildpack || 'hackmdio/buildpack:16.20.2-35fe7e39' }} + - + name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - + name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 0d46e9e88..c8eca1e03 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -18,73 +18,35 @@ env: REGISTRY_IMAGE: hackmdio/hackmd jobs: - build: + build-amd64: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - platform: - - linux/amd64 - - linux/arm64 steps: - - name: Prepare - run: | - platform=${{ matrix.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - - - name: Checkout - uses: actions/checkout@v4 + name: Set Platform Variable + run: echo "PLATFORM_PAIR=linux-amd64" >> $GITHUB_ENV - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 + name: Execute Build Steps + uses: ./.github/workflows/build-steps.yml with: - images: ${{ env.REGISTRY_IMAGE }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push by digest - id: build - uses: docker/build-push-action@v5 - with: - context: . - file: ./deployments/Dockerfile - platforms: ${{ matrix.platform }} - labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true - build-args: | - RUNTIME=${{ github.event.inputs.runtime || 'hackmdio/runtime:16.20.2-35fe7e39' }} - BUILDPACK=${{ github.event.inputs.buildpack || 'hackmdio/buildpack:16.20.2-35fe7e39' }} + platform: linux/amd64 + + build-arm64: + runs-on: macos-latest + steps: - - name: Export digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" + name: Set Platform Variable + run: echo "PLATFORM_PAIR=linux-arm64" >> $GITHUB_ENV - - name: Upload digest - uses: actions/upload-artifact@v4 + name: Execute Build Steps + uses: ./.github/workflows/build-steps.yml with: - name: digests-${{ env.PLATFORM_PAIR }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 + platform: linux/arm64 merge: runs-on: ubuntu-latest needs: - - build + - build-amd64 + - build-arm64 steps: - name: Download digests From 656b68803bb39227d9990a343c552bbcd524b008 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Tue, 29 Oct 2024 17:52:30 +0800 Subject: [PATCH 02/11] refactor: use correct name for extracted action Signed-off-by: Yukai Huang --- .../build-steps.yml => actions/build-steps/action.yml} | 0 .github/workflows/push-image.yml | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename .github/{workflows/build-steps.yml => actions/build-steps/action.yml} (100%) diff --git a/.github/workflows/build-steps.yml b/.github/actions/build-steps/action.yml similarity index 100% rename from .github/workflows/build-steps.yml rename to .github/actions/build-steps/action.yml diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index c8eca1e03..0752eb157 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -26,7 +26,7 @@ jobs: run: echo "PLATFORM_PAIR=linux-amd64" >> $GITHUB_ENV - name: Execute Build Steps - uses: ./.github/workflows/build-steps.yml + uses: ./.github/actions/build-steps with: platform: linux/amd64 @@ -38,7 +38,7 @@ jobs: run: echo "PLATFORM_PAIR=linux-arm64" >> $GITHUB_ENV - name: Execute Build Steps - uses: ./.github/workflows/build-steps.yml + uses: ./.github/actions/build-steps with: platform: linux/arm64 From c4f04e405017c08465396ee0878e0f4eca19f6a2 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Tue, 29 Oct 2024 18:03:05 +0800 Subject: [PATCH 03/11] fix: run checkout before reference local action Signed-off-by: Yukai Huang --- .github/workflows/push-image.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 0752eb157..cd0e7f2e4 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -21,6 +21,7 @@ jobs: build-amd64: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - name: Set Platform Variable run: echo "PLATFORM_PAIR=linux-amd64" >> $GITHUB_ENV @@ -33,6 +34,7 @@ jobs: build-arm64: runs-on: macos-latest steps: + - uses: actions/checkout@v4 - name: Set Platform Variable run: echo "PLATFORM_PAIR=linux-arm64" >> $GITHUB_ENV From 3921a0c59128ad3bfb2e640f1a91cb1698625313 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Tue, 29 Oct 2024 18:09:19 +0800 Subject: [PATCH 04/11] refactor: extract inputs Signed-off-by: Yukai Huang --- .github/actions/build-steps/action.yml | 19 ++++++++++++++----- .github/workflows/push-image.yml | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/actions/build-steps/action.yml b/.github/actions/build-steps/action.yml index bead353eb..737370670 100644 --- a/.github/actions/build-steps/action.yml +++ b/.github/actions/build-steps/action.yml @@ -6,13 +6,22 @@ on: platform: required: true type: string + registry_image: + required: true + type: string + runtime: + required: true + type: string + buildpack: + required: true + type: string jobs: build: runs-on: ${{ inputs.platform == 'linux/arm64' && 'macos-latest' || 'ubuntu-latest' }} steps: - - name: Prepare + name: Prepare Platform Environment run: | echo "PLATFORM_PAIR=${{ inputs.platform//\//- }}" >> $GITHUB_ENV - @@ -23,7 +32,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.REGISTRY_IMAGE }} + images: ${{ inputs.registry_image }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -45,10 +54,10 @@ jobs: file: ./deployments/Dockerfile platforms: ${{ inputs.platform }} labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + outputs: type=image,name=${{ inputs.registry_image }},push-by-digest=true,name-canonical=true,push=true build-args: | - RUNTIME=${{ github.event.inputs.runtime || 'hackmdio/runtime:16.20.2-35fe7e39' }} - BUILDPACK=${{ github.event.inputs.buildpack || 'hackmdio/buildpack:16.20.2-35fe7e39' }} + RUNTIME=${{ inputs.runtime }} + BUILDPACK=${{ inputs.buildpack }} - name: Export digest run: | diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index cd0e7f2e4..63ede2a61 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -30,6 +30,9 @@ jobs: uses: ./.github/actions/build-steps with: platform: linux/amd64 + registry_image: ${{ env.REGISTRY_IMAGE }} + runtime: ${{ github.event.inputs.runtime }} + buildpack: ${{ github.event.inputs.buildpack }} build-arm64: runs-on: macos-latest @@ -43,6 +46,9 @@ jobs: uses: ./.github/actions/build-steps with: platform: linux/arm64 + registry_image: ${{ env.REGISTRY_IMAGE }} + runtime: ${{ github.event.inputs.runtime }} + buildpack: ${{ github.event.inputs.buildpack }} merge: runs-on: ubuntu-latest From a74964f7d4a199fb135bdcf3e2659c0a2567c292 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 30 Oct 2024 19:50:16 +0800 Subject: [PATCH 05/11] fix: composite action structure Signed-off-by: Yukai Huang --- .github/actions/build-steps/action.yml | 112 ++++++++++++------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/.github/actions/build-steps/action.yml b/.github/actions/build-steps/action.yml index 737370670..3429d0185 100644 --- a/.github/actions/build-steps/action.yml +++ b/.github/actions/build-steps/action.yml @@ -16,59 +16,59 @@ on: required: true type: string -jobs: - build: - runs-on: ${{ inputs.platform == 'linux/arm64' && 'macos-latest' || 'ubuntu-latest' }} - steps: - - - name: Prepare Platform Environment - run: | - echo "PLATFORM_PAIR=${{ inputs.platform//\//- }}" >> $GITHUB_ENV - - - name: Checkout - uses: actions/checkout@v4 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ inputs.registry_image }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push by digest - id: build - uses: docker/build-push-action@v5 - with: - context: . - file: ./deployments/Dockerfile - platforms: ${{ inputs.platform }} - labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ inputs.registry_image }},push-by-digest=true,name-canonical=true,push=true - build-args: | - RUNTIME=${{ inputs.runtime }} - BUILDPACK=${{ inputs.buildpack }} - - - name: Export digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" - - - name: Upload digest - uses: actions/upload-artifact@v4 - with: - name: digests-${{ env.PLATFORM_PAIR }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 +runs: + using: composite + + steps: + - + name: Prepare Platform Environment + run: | + echo "PLATFORM_PAIR=${{ inputs.platform//\//- }}" >> $GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v4 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ inputs.registry_image }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./deployments/Dockerfile + platforms: ${{ inputs.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ inputs.registry_image }},push-by-digest=true,name-canonical=true,push=true + build-args: | + RUNTIME=${{ inputs.runtime }} + BUILDPACK=${{ inputs.buildpack }} + - + name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - + name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 From 455861eaf7ab06ae3462911cd62be8e7d70a8dfd Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 30 Oct 2024 19:53:29 +0800 Subject: [PATCH 06/11] fix: secrets referencing Signed-off-by: Yukai Huang --- .github/actions/build-steps/action.yml | 3 ++- .github/workflows/push-image.yml | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/actions/build-steps/action.yml b/.github/actions/build-steps/action.yml index 3429d0185..f60b11921 100644 --- a/.github/actions/build-steps/action.yml +++ b/.github/actions/build-steps/action.yml @@ -23,7 +23,8 @@ runs: - name: Prepare Platform Environment run: | - echo "PLATFORM_PAIR=${{ inputs.platform//\//- }}" >> $GITHUB_ENV + platform=${{ inputs.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 63ede2a61..a241ef6f0 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -33,6 +33,7 @@ jobs: registry_image: ${{ env.REGISTRY_IMAGE }} runtime: ${{ github.event.inputs.runtime }} buildpack: ${{ github.event.inputs.buildpack }} + secrets: inherit build-arm64: runs-on: macos-latest @@ -49,6 +50,7 @@ jobs: registry_image: ${{ env.REGISTRY_IMAGE }} runtime: ${{ github.event.inputs.runtime }} buildpack: ${{ github.event.inputs.buildpack }} + secrets: inherit merge: runs-on: ubuntu-latest From c2512cf1f73c9a9d0dec101fe22ccc3c0981d048 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 30 Oct 2024 20:02:22 +0800 Subject: [PATCH 07/11] fix: use reusable workflow instead of composite action Signed-off-by: Yukai Huang --- .github/actions/build-steps/action.yml | 117 +++++++++++++------------ .github/workflows/build-steps.yml | 74 ++++++++++++++++ .github/workflows/push-image.yml | 46 ++++------ 3 files changed, 150 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/build-steps.yml diff --git a/.github/actions/build-steps/action.yml b/.github/actions/build-steps/action.yml index f60b11921..2057d06f5 100644 --- a/.github/actions/build-steps/action.yml +++ b/.github/actions/build-steps/action.yml @@ -15,61 +15,64 @@ on: buildpack: required: true type: string + runs_on: + required: true + type: string -runs: - using: composite - - steps: - - - name: Prepare Platform Environment - run: | - platform=${{ inputs.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - - - name: Checkout - uses: actions/checkout@v4 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ inputs.registry_image }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push by digest - id: build - uses: docker/build-push-action@v5 - with: - context: . - file: ./deployments/Dockerfile - platforms: ${{ inputs.platform }} - labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ inputs.registry_image }},push-by-digest=true,name-canonical=true,push=true - build-args: | - RUNTIME=${{ inputs.runtime }} - BUILDPACK=${{ inputs.buildpack }} - - - name: Export digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" - - - name: Upload digest - uses: actions/upload-artifact@v4 - with: - name: digests-${{ env.PLATFORM_PAIR }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 +jobs: + build: + runs-on: ${{ inputs.runs_on }} + steps: + - + name: Prepare Platform Environment + run: | + platform=${{ inputs.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v4 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ inputs.registry_image }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./deployments/Dockerfile + platforms: ${{ inputs.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ inputs.registry_image }},push-by-digest=true,name-canonical=true,push=true + build-args: | + RUNTIME=${{ inputs.runtime }} + BUILDPACK=${{ inputs.buildpack }} + - + name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - + name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 diff --git a/.github/workflows/build-steps.yml b/.github/workflows/build-steps.yml new file mode 100644 index 000000000..7d8804abe --- /dev/null +++ b/.github/workflows/build-steps.yml @@ -0,0 +1,74 @@ +name: Build Steps + +on: + workflow_call: + inputs: + platform: + required: true + type: string + registry_image: + required: true + type: string + runtime: + required: true + type: string + buildpack: + required: true + type: string + +jobs: + build: + steps: + - + name: Prepare Platform Environment + run: | + platform=${{ inputs.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v4 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ inputs.registry_image }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./deployments/Dockerfile + platforms: ${{ inputs.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ inputs.registry_image }},push-by-digest=true,name-canonical=true,push=true + build-args: | + RUNTIME=${{ inputs.runtime }} + BUILDPACK=${{ inputs.buildpack }} + - + name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - + name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index a241ef6f0..7312dde76 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -19,38 +19,24 @@ env: jobs: build-amd64: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set Platform Variable - run: echo "PLATFORM_PAIR=linux-amd64" >> $GITHUB_ENV - - - name: Execute Build Steps - uses: ./.github/actions/build-steps - with: - platform: linux/amd64 - registry_image: ${{ env.REGISTRY_IMAGE }} - runtime: ${{ github.event.inputs.runtime }} - buildpack: ${{ github.event.inputs.buildpack }} - secrets: inherit + uses: ./.github/workflows/build-steps.yml + secrets: inherit + with: + platform: linux/amd64 + registry_image: ${{ env.REGISTRY_IMAGE }} + runtime: ${{ github.event.inputs.runtime }} + buildpack: ${{ github.event.inputs.buildpack }} + runs_on: ubuntu-latest build-arm64: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - - name: Set Platform Variable - run: echo "PLATFORM_PAIR=linux-arm64" >> $GITHUB_ENV - - - name: Execute Build Steps - uses: ./.github/actions/build-steps - with: - platform: linux/arm64 - registry_image: ${{ env.REGISTRY_IMAGE }} - runtime: ${{ github.event.inputs.runtime }} - buildpack: ${{ github.event.inputs.buildpack }} - secrets: inherit + uses: ./.github/workflows/build-steps.yml + secrets: inherit + with: + platform: linux/arm64 + registry_image: ${{ env.REGISTRY_IMAGE }} + runtime: ${{ github.event.inputs.runtime }} + buildpack: ${{ github.event.inputs.buildpack }} + runs_on: macos-latest merge: runs-on: ubuntu-latest From 215f02295b2522c49a910615b37522084d721dfd Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 30 Oct 2024 23:44:42 +0800 Subject: [PATCH 08/11] refactor: extract platform_pair to inputs Signed-off-by: Yukai Huang --- .github/actions/build-steps/action.yml | 10 ++++------ .github/workflows/push-image.yml | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/actions/build-steps/action.yml b/.github/actions/build-steps/action.yml index 2057d06f5..8cd5c2f1d 100644 --- a/.github/actions/build-steps/action.yml +++ b/.github/actions/build-steps/action.yml @@ -6,6 +6,9 @@ on: platform: required: true type: string + platform_pair: + required: true + type: string registry_image: required: true type: string @@ -23,11 +26,6 @@ jobs: build: runs-on: ${{ inputs.runs_on }} steps: - - - name: Prepare Platform Environment - run: | - platform=${{ inputs.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 @@ -72,7 +70,7 @@ jobs: name: Upload digest uses: actions/upload-artifact@v4 with: - name: digests-${{ env.PLATFORM_PAIR }} + name: digests-${{ inputs.platform_pair }} path: /tmp/digests/* if-no-files-found: error retention-days: 1 diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 7312dde76..5ac10bc97 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -23,6 +23,7 @@ jobs: secrets: inherit with: platform: linux/amd64 + platform_pair: linux_amd64 registry_image: ${{ env.REGISTRY_IMAGE }} runtime: ${{ github.event.inputs.runtime }} buildpack: ${{ github.event.inputs.buildpack }} @@ -33,6 +34,7 @@ jobs: secrets: inherit with: platform: linux/arm64 + platform_pair: linux_arm64 registry_image: ${{ env.REGISTRY_IMAGE }} runtime: ${{ github.event.inputs.runtime }} buildpack: ${{ github.event.inputs.buildpack }} From e9f97a784e05410f8b7c9496ae41087a7333fe16 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 30 Oct 2024 23:48:36 +0800 Subject: [PATCH 09/11] refactor: move registry_image to inputs Signed-off-by: Yukai Huang --- .github/workflows/push-image.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 5ac10bc97..cb528a0f7 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -13,9 +13,10 @@ on: description: 'Buildpack image' required: true default: 'hackmdio/buildpack:16.20.2-35fe7e39' - -env: - REGISTRY_IMAGE: hackmdio/hackmd + registry_image: + description: 'image name' + required: false + default: 'hackmdio/hackmd' jobs: build-amd64: @@ -24,7 +25,7 @@ jobs: with: platform: linux/amd64 platform_pair: linux_amd64 - registry_image: ${{ env.REGISTRY_IMAGE }} + registry_image: ${{ github.event.inputs.registry_image }} runtime: ${{ github.event.inputs.runtime }} buildpack: ${{ github.event.inputs.buildpack }} runs_on: ubuntu-latest @@ -35,7 +36,7 @@ jobs: with: platform: linux/arm64 platform_pair: linux_arm64 - registry_image: ${{ env.REGISTRY_IMAGE }} + registry_image: ${{ github.event.inputs.registry_image }} runtime: ${{ github.event.inputs.runtime }} buildpack: ${{ github.event.inputs.buildpack }} runs_on: macos-latest @@ -61,7 +62,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.REGISTRY_IMAGE }} + images: ${{ github.event.inputs.registry_image }} tags: | type=match,pattern=\d.\d.\d type=sha,prefix= @@ -76,8 +77,8 @@ jobs: working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + $(printf '${{ github.event.inputs.registry_image }}@sha256:%s ' *) - name: Inspect image run: | - docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} + docker buildx imagetools inspect ${{ github.event.inputs.registry_image }}:${{ steps.meta.outputs.version }} From e1f099bfd5abb160a83ab847c314838bd608cd85 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Thu, 31 Oct 2024 00:00:17 +0800 Subject: [PATCH 10/11] fix: remove duplicate build-steps/action.yml Signed-off-by: Yukai Huang --- .github/actions/build-steps/action.yml | 76 -------------------------- .github/workflows/build-steps.yml | 14 +++-- .github/workflows/push-image.yml | 2 +- 3 files changed, 9 insertions(+), 83 deletions(-) delete mode 100644 .github/actions/build-steps/action.yml diff --git a/.github/actions/build-steps/action.yml b/.github/actions/build-steps/action.yml deleted file mode 100644 index 8cd5c2f1d..000000000 --- a/.github/actions/build-steps/action.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: Build Steps - -on: - workflow_call: - inputs: - platform: - required: true - type: string - platform_pair: - required: true - type: string - registry_image: - required: true - type: string - runtime: - required: true - type: string - buildpack: - required: true - type: string - runs_on: - required: true - type: string - -jobs: - build: - runs-on: ${{ inputs.runs_on }} - steps: - - - name: Checkout - uses: actions/checkout@v4 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ inputs.registry_image }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push by digest - id: build - uses: docker/build-push-action@v5 - with: - context: . - file: ./deployments/Dockerfile - platforms: ${{ inputs.platform }} - labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ inputs.registry_image }},push-by-digest=true,name-canonical=true,push=true - build-args: | - RUNTIME=${{ inputs.runtime }} - BUILDPACK=${{ inputs.buildpack }} - - - name: Export digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" - - - name: Upload digest - uses: actions/upload-artifact@v4 - with: - name: digests-${{ inputs.platform_pair }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 diff --git a/.github/workflows/build-steps.yml b/.github/workflows/build-steps.yml index 7d8804abe..8cd5c2f1d 100644 --- a/.github/workflows/build-steps.yml +++ b/.github/workflows/build-steps.yml @@ -6,6 +6,9 @@ on: platform: required: true type: string + platform_pair: + required: true + type: string registry_image: required: true type: string @@ -15,15 +18,14 @@ on: buildpack: required: true type: string + runs_on: + required: true + type: string jobs: build: + runs-on: ${{ inputs.runs_on }} steps: - - - name: Prepare Platform Environment - run: | - platform=${{ inputs.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 @@ -68,7 +70,7 @@ jobs: name: Upload digest uses: actions/upload-artifact@v4 with: - name: digests-${{ env.PLATFORM_PAIR }} + name: digests-${{ inputs.platform_pair }} path: /tmp/digests/* if-no-files-found: error retention-days: 1 diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index cb528a0f7..2b63cc6bc 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -15,7 +15,7 @@ on: default: 'hackmdio/buildpack:16.20.2-35fe7e39' registry_image: description: 'image name' - required: false + required: true default: 'hackmdio/hackmd' jobs: From 7b6cb4c574fd91d091c67e8069ed5a29344b7d9e Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Thu, 31 Oct 2024 00:01:58 +0800 Subject: [PATCH 11/11] fix: remove setup qemu step Signed-off-by: Yukai Huang --- .github/workflows/build-steps.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build-steps.yml b/.github/workflows/build-steps.yml index 8cd5c2f1d..c560fbf54 100644 --- a/.github/workflows/build-steps.yml +++ b/.github/workflows/build-steps.yml @@ -35,9 +35,6 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ inputs.registry_image }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3