diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5c3e962753..76e8ab7d0e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,13 +13,24 @@ on: - cron: "0 0 * * 0" jobs: - docker: - name: Docker Build and Push - runs-on: ubuntu-22.04 + build: + name: Build + runs-on: ${{ matrix.build.OS }} + strategy: + fail-fast: false + matrix: + build: + - { PLATFORM: linux/amd64, OS: ubuntu-22.04 } + - { PLATFORM: linux/arm64, OS: macos-14 } steps: - name: Checkout uses: actions/checkout@v4 + - name: Prepare + run: | + platform=${{ matrix.build.PLATFORM }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -27,13 +38,6 @@ jobs: images: | orhunp/git-cliff ghcr.io/${{ github.repository_owner }}/git-cliff/git-cliff - tags: | - type=schedule - type=ref,event=branch - type=ref,event=pr - type=sha - type=raw,value=latest - type=semver,pattern={{version}} - name: Set up Docker Buildx id: buildx @@ -62,25 +66,95 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - id: docker_build + - name: Build and push by digest + id: build uses: docker/build-push-action@v6 with: context: ./ file: ./Dockerfile + platforms: ${{ matrix.build.PLATFORM }} builder: ${{ steps.buildx.outputs.name }} - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - sbom: true - provenance: true labels: ${{ steps.meta.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache + outputs: type=image,name=orhunp/git-cliff,name=ghcr.io/${{ github.repository_owner }}/git-cliff/git-cliff,push-by-digest=${{ github.event_name != 'pull_request' }},name-canonical=true + sbom: true + provenance: true + + - name: Export digest + run: | + digest="${{ steps.build.outputs.digest }}" + mkdir -p /tmp/digests + touch "/tmp/digests/${digest#sha256:}" + cat "/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 + + merge: + name: Merge + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + needs: + - build + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + orhunp/git-cliff + ghcr.io/${{ github.repository_owner }}/git-cliff/git-cliff + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=sha + type=raw,value=latest + type=semver,pattern={{version}} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests + shell: bash + run: | + for image in orhunp/git-cliff ghcr.io/${{ github.repository_owner }}/git-cliff/git-cliff; do + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf "${image}@sha256:%s " *) + done + + - name: Inspect image + shell: bash + run: | + for image in orhunp/git-cliff ghcr.io/${{ github.repository_owner }}/git-cliff/git-cliff; do + docker buildx imagetools inspect "${image}:${{ steps.meta.outputs.version }}" + done - name: Scan the image uses: anchore/sbom-action@v0 with: image: ghcr.io/${{ github.repository_owner }}/git-cliff/git-cliff - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/Dockerfile b/Dockerfile index 6175d2360f..3e74c888c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ COPY --from=planner /app/recipe.json recipe.json ENV CARGO_NET_GIT_FETCH_WITH_CLI=true RUN cargo chef cook --release --recipe-path recipe.json COPY . . -RUN cargo build --release --locked --no-default-features --features github --features gitlab --features bitbucket +RUN cargo build --verbose --release --locked --no-default-features --features github --features gitlab --features bitbucket RUN rm -f target/release/deps/git_cliff* FROM debian:buster-slim as runner