name: Build container image on: pull_request: branches: - main schedule: - cron: '05 12 * * 2,5' workflow_dispatch: env: IMAGE_DESC: "Custom Fedora bootc image" IMAGE_NAME: "${{ github.event.repository.name }}" DEFAULT_TAG: "stable" concurrency: group: ${{ github.workflow }}-${{ github.ref || github.run_id }} cancel-in-progress: true jobs: build_push: name: Build and push image runs-on: ubuntu-24.04 permissions: contents: read packages: write id-token: write steps: - name: Prepare environment run: | REGISTRY_HOST=$(echo "${{ github.server_url }}" | awk -F/ '{print $3}') OWNER_LOWER="${{ github.repository_owner }}" NAME_LOWER="${{ env.IMAGE_NAME }}" echo "REGISTRY_HOST=${REGISTRY_HOST}" >> ${GITHUB_ENV} echo "IMAGE_REGISTRY=${REGISTRY_HOST}/${OWNER_LOWER,,}" >> ${GITHUB_ENV} echo "IMAGE_NAME=${NAME_LOWER,,}" >> ${GITHUB_ENV} # Aktuelles Tagesdatum direkt von der Runner-VM beziehen (UTC) echo "DATE_TAG=$(date -u +'%Y%m%d')" >> ${GITHUB_ENV} echo "BUILD_DATE_ISO=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> ${GITHUB_ENV} - name: Checkout uses: actions/checkout@v7.0.1 # Generiert die auth.json dynamisch im configs/ Ordner aus Template & Secret - name: Prepare Registry Auth File env: AUTH_BASE64: ${{ secrets.READONLY_AUTH_BASE64 }} run: | sed "s|READONLY_TOKEN_PLACEHOLDER|${AUTH_BASE64}|g" configs/auth.json.template > configs/auth.json - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4.3.0 - name: Image Metadata id: metadata uses: docker/metadata-action@v6.2.0 with: images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=raw,value=${{ env.DEFAULT_TAG }},enable=${{ github.ref_name == 'main' }} type=raw,value=${{ env.DEFAULT_TAG }}.${{ env.DATE_TAG }},enable=${{ github.ref_name == 'main' }} type=raw,value=${{ env.DATE_TAG }},enable=${{ github.ref_name == 'main' }} type=raw,value=test-{{branch}},enable=${{ github.ref_name != 'main' && github.event_name != 'pull_request' }} type=ref,event=pr,prefix=test-pr- labels: | org.opencontainers.image.created=${{ env.BUILD_DATE_ISO }} org.opencontainers.image.description=${{ env.IMAGE_DESC }} org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }} org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} org.opencontainers.image.title=${{ env.IMAGE_NAME }} org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }} org.opencontainers.image.vendor=${{ github.repository_owner }} org.opencontainers.image.version=${{ env.DEFAULT_TAG }}.${{ env.DATE_TAG }} containers.bootc=1 ostree.bootable=1 - name: Login to Gitea Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v4.6.0 with: registry: ${{ env.REGISTRY_HOST }} username: ${{ github.repository_owner }} password: ${{ secrets.REGISTRY }} - name: Build and Push Image (Docker Buildx) uses: docker/build-push-action@v7.3.0 id: build_image with: context: . file: ./Containerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} oci-mediatypes: true compression: zstd # Aktiviert die Chunk-Map für zstd:chunked Range-Requests build-args: | BUILDKIT_OCI_MEDIATYPE=true output: type=registry,push=${{ github.event_name != 'pull_request' }},oci-mediatypes=true,compression=zstd,compression-args=binary-path=/usr/bin/go-zstd-chunked - name: Install envsubst dependencies if: github.event_name != 'pull_request' && github.ref_name == 'main' run: | sudo apt-get update && sudo apt-get install -y gettext - name: Install Cosign if: github.event_name != 'pull_request' && github.ref_name == 'main' uses: sigstore/cosign-installer@v4.1.2 - name: Sign container image if: github.event_name != 'pull_request' && github.ref_name == 'main' env: COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }} COSIGN_PASSWORD: "" run: | echo "${{ secrets.REGISTRY }}" | cosign login "${{ env.REGISTRY_HOST }}" -u "${{ github.repository_owner }}" --password-stdin IMAGE_REF="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build_image.outputs.digest }}" echo "Signiere Manifest via Direct Digest: ${IMAGE_REF}" cosign sign -y \ --key env://COSIGN_PRIVATE_KEY \ --recursive \ --use-signing-config=false \ --new-bundle-format=false \ --registry-referrers-mode=legacy \ "${IMAGE_REF}" - name: Post-Build Cleanup if: always() run: | echo "Lösche erzeugte Auth-Datei..." rm -f configs/auth.json echo "Leere Buildx-internen Cache..." docker buildx prune -a -f || true