Skip to content

Merge pull request #7 from jwtwallet/6-attest-build-artifacts-and-bun… #39

Merge pull request #7 from jwtwallet/6-attest-build-artifacts-and-bun…

Merge pull request #7 from jwtwallet/6-attest-build-artifacts-and-bun… #39

Workflow file for this run

name: Build and Push Docker Image
on:
push:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
name: Build and push image
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Docker Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Lowercase repository name
run: echo "REPOSITORY_NAME=$(echo ${{ github.repository }} | awk '{print tolower($0)}')" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.REPOSITORY_NAME }}
- name: Build and push
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=ghcr.io/${{ env.REPOSITORY_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max
env:
HUSKY: 0
- 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:
name: Merge digests
runs-on: ubuntu-latest
needs:
- build
permissions:
contents: read
packages: write
id-token: write
attestations: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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: Lowercase repository name
run: echo "REPOSITORY_NAME=$(echo ${{ github.repository }} | awk '{print tolower($0)}')" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.REPOSITORY_NAME }}
- name: Login to GitHub Docker Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_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 'ghcr.io/${{ env.REPOSITORY_NAME }}@sha256:%s ' *)
- name: Inspect image
id: inspect
run: |
OUTPUT=$(docker buildx imagetools inspect ghcr.io/${{ env.REPOSITORY_NAME }}:${{ steps.meta.outputs.version }} --format "{{json .Manifest.Digest}}" | xargs)
echo "digest=$OUTPUT" >> $GITHUB_OUTPUT
- name: Attest Main Branch Builds
if: github.ref == 'refs/heads/main'
uses: actions/attest-build-provenance@v1
id: attest
with:
subject-name: ghcr.io/${{ env.REPOSITORY_NAME }}
subject-digest: ${{ steps.inspect.outputs.digest }}
push-to-registry: true