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} - name: Determine image tag run: | BRANCH="${GITHUB_REF_NAME}" if [[ "$BRANCH" == "main" ]]; then echo "IMAGE_TAG=${DEFAULT_TAG}" >> ${GITHUB_ENV} echo "IS_TEST_BUILD=false" >> ${GITHUB_ENV} else SANITIZED=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9._-]/-/g' | head -c 50) echo "IMAGE_TAG=test-${SANITIZED}" >> ${GITHUB_ENV} echo "IS_TEST_BUILD=true" >> ${GITHUB_ENV} fi - name: Checkout uses: actions/checkout@v6 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Image Metadata id: metadata uses: docker/metadata-action@v6 with: images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=raw,value=${{ env.IMAGE_TAG }} type=raw,value=${{ env.IMAGE_TAG }}.{{date 'YYYYMMDD'}},enable=${{ env.IS_TEST_BUILD == 'false' }} type=raw,value={{date 'YYYYMMDD'}},enable=${{ env.IS_TEST_BUILD == 'false' }} type=sha,enable=${{ github.event_name == 'pull_request' }} type=ref,event=pr labels: | org.opencontainers.image.created={{date 'YYYY-MM-DDTHH:mm:ssZ'}} org.opencontainers.image.description=${{ env.IMAGE_DESC }} org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}/raw/commit/${{ github.sha }}/README.md org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}/src/commit/${{ github.sha }}/Containerfile 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.IMAGE_TAG }}.{{date 'YYYYMMDD'}} containers.bootc=1 ostree.bootable=1 - name: Login to Gitea Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v4 with: registry: ${{ env.REGISTRY_HOST }} username: ${{ github.repository_owner }} password: ${{ secrets.REGISTRY }} - name: Build and Push Image (Native OCI via Buildx) uses: docker/build-push-action@v7 id: build_image with: context: . file: ./Containerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} - name: Sign container image if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false' uses: sigstore/cosign-sign-action@v3.1.1 with: # Bild-Referenz ohne Tag, da die Action den Digest oder Tag separat trennt image-repository: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} image-tag: ${{ env.IMAGE_TAG }} # Authentifizierung für deine Gitea-Registry (wichtig, damit die Action das Image pushen darf) registry-username: ${{ github.repository_owner }} registry-password: ${{ secrets.REGISTRY }} # Deine Keys aus den Secrets geladen cosign-private-key: ${{ secrets.SIGNING_SECRET }} cosign-password: "" # Deine spezifischen Flags für den Gitea/bootc Legacy-Bypass: registry-referrers-api: 'legacy' cosign-tlog-upload: 'false' use-signing-config: 'false'