From 9f0642621f0987bdf43276788179a093c0eac79d Mon Sep 17 00:00:00 2001 From: Jun Kurihara Date: Tue, 25 Jul 2023 02:24:25 +0900 Subject: [PATCH] fix github actions fix github actions fix github actions fix github actions env --- .github/workflows/docker_build_push.yml | 99 +++++++++++++++++++++---- 1 file changed, 83 insertions(+), 16 deletions(-) diff --git a/.github/workflows/docker_build_push.yml b/.github/workflows/docker_build_push.yml index 1176777..83d3d99 100644 --- a/.github/workflows/docker_build_push.yml +++ b/.github/workflows/docker_build_push.yml @@ -6,6 +6,9 @@ on: - main - develop +env: + REGISTRY_IMAGE: jqtype/rpxy + jobs: build_and_push: runs-on: ubuntu-latest @@ -15,8 +18,6 @@ jobs: platform: - linux/amd64 - linux/arm64 - env: - IMAGE_NAME: rpxy steps: - name: Checkout @@ -27,6 +28,12 @@ jobs: - name: GitHub Environment run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY_IMAGE }} + - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -39,18 +46,20 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Release build and push + - name: Release build and push by digest if: ${{ env.BRANCH == 'main' }} uses: docker/build-push-action@v4 with: context: . push: true tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest + ${{ env.REGISTRY_IMAGE }}:latest file: ./docker/Dockerfile - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=${{ matrix.platform }}-latest + cache-to: type=gha,mode=max,scope=${{ matrix.platform }}-latest platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true - name: Release build and push slim if: ${{ env.BRANCH == 'main' }} @@ -59,14 +68,16 @@ jobs: context: . push: true tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:slim, ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest-slim + ${{ env.REGISTRY_IMAGE }}:slim, ${{ env.REGISTRY_IMAGE }}:latest-slim build-contexts: | messense/rust-musl-cross:amd64-musl=docker-image://messense/rust-musl-cross:x86_64-musl messense/rust-musl-cross:arm64-musl=docker-image://messense/rust-musl-cross:aarch64-musl file: ./docker/Dockerfile.slim - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=${{ matrix.platform }}-latest-slim + cache-to: type=gha,mode=max,scope=${{ matrix.platform }}-latest-slim platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true - name: Nightly build and push if: ${{ env.BRANCH == 'develop' }} @@ -75,24 +86,80 @@ jobs: context: . push: true tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:nightly + ${{ env.REGISTRY_IMAGE }}:nightly file: ./docker/Dockerfile - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=${{ matrix.platform }}-nightly + cache-to: type=gha,mode=max,scope=${{ matrix.platform }}-nightly platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true - - name: Release build and push slim + - name: Nightly build and push slim if: ${{ env.BRANCH == 'develop' }} uses: docker/build-push-action@v4 with: context: . push: true tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:nightly-slim + ${{ env.REGISTRY_IMAGE }}:nightly-slim build-contexts: | messense/rust-musl-cross:amd64-musl=docker-image://messense/rust-musl-cross:x86_64-musl messense/rust-musl-cross:arm64-musl=docker-image://messense/rust-musl-cross:aarch64-musl file: ./docker/Dockerfile.slim - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=${{ matrix.platform }}-nightly-slim + cache-to: type=gha,mode=max,scope=${{ matrix.platform }}-nightly-slim platforms: ${{ matrix.platform }} + 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_and_push + 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@v2 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY_IMAGE }} + - + name: Login to Docker Hub + uses: docker/login-action@v2 + 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 }}