diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e8491cb..572e2e1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,5 @@ name: Release + on: release: types: [prereleased, released] @@ -6,13 +7,22 @@ on: jobs: build: 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@v4 - - name: Set env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - name: Echo - run: echo "releasing:${{ env.RELEASE_VERSION }}" + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.REGISTRY_IMAGE }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub @@ -26,15 +36,61 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.TOKEN }} - - name: Build and push + - name: Build and push by digest + id: build uses: docker/build-push-action@v5 with: context: . - platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: true - tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/localfilesharing:latest - ${{ secrets.DOCKERHUB_USERNAME }}/localfilesharing:${{ env.RELEASE_VERSION }} - ghcr.io/${{ secrets.DOCKERHUB_USERNAME }}/localfilesharing:latest - ghcr.io/${{ secrets.DOCKERHUB_USERNAME }}/localfilesharing:${{ env.RELEASE_VERSION }} + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ secrets.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: ${{ secrets.REGISTRY_IMAGE }} + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.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 '${{ secrets.REGISTRY_IMAGE }}@sha256:%s ' *) + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ secrets.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ No newline at end of file