build: update action versions and improve cache configuration in dock… #37
Workflow file for this run
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: 🐳 Docker CI/CD | |
on: [push] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
# Build and test the Docker image | |
tests: | |
name: 🧪 Tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 | |
- name: 📦 Cache Docker layers | |
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a | |
with: | |
path: tmp-cache | |
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }} | |
- name: 📦 Load cache | |
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de | |
with: | |
cache-map: | | |
{ | |
"tmp-cache": "/tmp/cache" | |
} | |
skip-extraction: ${{ steps.cache.outputs.cache-hit }} | |
- name: 🏗️ Build test stage | |
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 | |
with: | |
target: test | |
load: true | |
# Build and push the final image | |
push: | |
name: 🚀 Publish image | |
runs-on: ubuntu-latest | |
needs: tests | |
if: startsWith(github.ref, 'refs/tags/') | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 | |
- uses: docker/metadata-action@b53be03109c4ef6f6cc7aa545b84b17a7fe51c1e | |
id: meta | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: 🪪 Log in to the Container registry | |
uses: docker/login-action@7ca345011ac4304463197fac0e56eab1bc7e6af0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: 📦 Cache Docker layers | |
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a | |
with: | |
path: tmp-cache | |
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }} | |
- name: 📦 Load cache | |
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de | |
with: | |
cache-map: | | |
{ | |
"tmp-cache": "/tmp/cache" | |
} | |
skip-extraction: ${{ steps.cache.outputs.cache-hit }} | |
- name: 🏗️ Build final stage and release it! | |
id: push | |
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 | |
with: | |
target: final | |
push: true | |
annotations: ${{ steps.meta.outputs.annotations }} | |
labels: ${{ steps.meta.outputs.labels }} | |
tags: ${{ steps.meta.outputs.tags }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: 📎 Generate artifact attestation | |
uses: actions/attest-build-provenance@v1 | |
with: | |
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
subject-digest: ${{ steps.push.outputs.digest }} | |
push-to-registry: true |