ops: improve ci by attesting build #48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker Image | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
attestations: write | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ghcr.io/${{ github.repository }} | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Nix | |
uses: cachix/install-nix-action@v30 | |
- name: Build Docker image | |
run: nix build .#docker | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push Docker image to GitHub Container Registry | |
id: push | |
run: | | |
docker load < result | |
docker tag drawbu.dev ${{ env.IMAGE_NAME }} | |
docker push ${{ env.IMAGE_NAME }} | |
digest=$(docker image inspect ${{ env.IMAGE_NAME }} \ | |
| nix run nixpkgs#jq -- --raw-output '.[].RepoDigests[]' \ | |
| cut -d@ -f2) | |
echo "digest=$digest" >> "$GITHUB_OUTPUT" | |
- name: Attest | |
uses: actions/attest-build-provenance@v1 | |
id: attest | |
with: | |
subject-name: ${{ env.IMAGE_NAME }} | |
subject-digest: ${{ steps.push.outputs.digest }} | |
push-to-registry: true |