From 470580e5f5104b512f17845296ff83e3c61a4bf6 Mon Sep 17 00:00:00 2001 From: Ricco Xie Date: Fri, 29 Sep 2023 17:49:52 +0800 Subject: [PATCH] fix: gh-76 build docker image release actions for multi-platforms. --- .github/workflows/docker-build-latest.yaml | 41 ----------- .github/workflows/docker-build-release.yaml | 77 ++++++++++++++++++--- .github/workflows/docker-build-test.yaml | 68 ++++++++++++++++-- 3 files changed, 129 insertions(+), 57 deletions(-) delete mode 100644 .github/workflows/docker-build-latest.yaml diff --git a/.github/workflows/docker-build-latest.yaml b/.github/workflows/docker-build-latest.yaml deleted file mode 100644 index b2d13cb..0000000 --- a/.github/workflows/docker-build-latest.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: docker-build-latest - -env: - dockerhub_repository: "riccoxie/meilisearch-ui" - dockerhub_tag: "dev" - -on: - push: - branches: - - main - -jobs: - dockerhub-build-push: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - platform: - - linux/amd64 - - linux/arm/v6 - - linux/arm/v7 - - linux/arm64 - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - push: true - platforms: ${{ matrix.platform }} - tags: ${{ env.dockerhub_repository }}:${{ env.dockerhub_tag }} \ No newline at end of file diff --git a/.github/workflows/docker-build-release.yaml b/.github/workflows/docker-build-release.yaml index ee4c6be..50c0379 100644 --- a/.github/workflows/docker-build-release.yaml +++ b/.github/workflows/docker-build-release.yaml @@ -1,14 +1,15 @@ name: docker-build-release -env: - dockerhub_repository: "riccoxie/meilisearch-ui" - on: release: types: [ published ] +env: + REGISTRY_IMAGE: riccoxie/meilisearch-ui + + jobs: - dockerhub-build-push: + build: runs-on: ubuntu-latest strategy: fail-fast: false @@ -20,7 +21,16 @@ jobs: - linux/arm64 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: + latest + type=ref,event=tag + - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx @@ -30,16 +40,65 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push + - name: Build and push by digest + id: build uses: docker/build-push-action@v5 with: context: . platforms: ${{ matrix.platform }} - push: true - tags: ${{ env.dockerhub_repository }}:${{ github.event.release.tag_name }}, ${{ env.dockerhub_repository }}:latest + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + - 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@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: + latest + type=ref,event=tag + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Create manifest list and push + 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 ' *) + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} + - name: Update repo description uses: peter-evans/dockerhub-description@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{ env.dockerhub_repository }} \ No newline at end of file + repository: ${{ env.REGISTRY_IMAGE }} \ No newline at end of file diff --git a/.github/workflows/docker-build-test.yaml b/.github/workflows/docker-build-test.yaml index 0dd1afc..c0b0e18 100644 --- a/.github/workflows/docker-build-test.yaml +++ b/.github/workflows/docker-build-test.yaml @@ -1,8 +1,7 @@ name: docker-build-test env: - dockerhub_repository: "riccoxie/meilisearch-ui" - dockerhub_tag: "test" + REGISTRY_IMAGE: riccoxie/meilisearch-ui on: push: @@ -10,7 +9,7 @@ on: - test jobs: - dockerhub-build-push: + build: runs-on: ubuntu-latest strategy: fail-fast: false @@ -22,7 +21,15 @@ jobs: - linux/arm64 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=ref,event=branch + - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx @@ -32,10 +39,57 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push + - name: Build and push by digest + id: build uses: docker/build-push-action@v5 with: context: . - push: true platforms: ${{ matrix.platform }} - tags: ${{ env.dockerhub_repository }}:${{ env.dockerhub_tag }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + - 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@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=ref,event=branch + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Create manifest list and push + 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 ' *) + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}