Skip to content

Merge pull request #78 from QuadcoreDevelopment/41-verwendung-validat… #7

Merge pull request #78 from QuadcoreDevelopment/41-verwendung-validat…

Merge pull request #78 from QuadcoreDevelopment/41-verwendung-validat… #7

name: Automatically create and publish a Docker image to GHCR on release tag
on:
push:
tags:
- frontend_v*.*.*
- backend_v*.*.*
env:
REGISTRY: ghcr.io
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract service name from tag
id: extract
run: |
TAG="${GITHUB_REF##*/}"
if [[ "$TAG" =~ ^(frontend|backend)_v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
SERVICE="${BASH_REMATCH[1]}"
echo "SERVICE=$SERVICE" >> $GITHUB_ENV
echo "IMAGE_NAME=${{ github.repository }}_${SERVICE}" >> $GITHUB_ENV
echo "CONTEXT=./$SERVICE" >> $GITHUB_ENV
else
echo "Tag format not recognized"
exit 1
fi
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
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.8.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Extract the semver from the tag that triggered this workflow
tags: type=semver,prefix=v,pattern={{version}},value={{tag}},match=v(\d.\d.\d)$
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ${{ env.CONTEXT }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# - name: Generate artifact attestation
# uses: actions/attest-build-provenance@v2
# with:
# subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
# subject-digest: ${{ steps.push.outputs.digest }}
# push-to-registry: true