From bce791c2d60867d4cb377128b669df3e46522ac8 Mon Sep 17 00:00:00 2001 From: Bernd Busse Date: Thu, 6 Jun 2024 18:46:36 +0200 Subject: [PATCH] Add workflow to build and publish docker image --- .github/workflows/publish.yml | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..a9c7057 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,64 @@ +name: Create and publish Docker image + +# run every time a change is pushed to the `master` branch +on: + push: + branches: ['master'] + +# define container registry domain and docker image name to publish +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + if: github.repository_owner == 'cryptool-org' + + # permissions for code checkout and package push (granted to `GITHUB_TOKEN`) + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=false + tags: | + type=ref,event=branch + type=ref,event=tag + type=sha,prefix=git-,format=short + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v5 + with: + context: . + push: true + pull: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - 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