Files
fluffy-pancake/.gitea/workflows/build.yml
T
2026-06-06 11:04:43 +02:00

120 lines
4.3 KiB
YAML

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: |
# Extrahiert die reine Domain/Host (inkl. Port, falls vorhanden) aus der Gitea-URL
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@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Image Metadata
uses: docker/metadata-action@v5
id: metadata
with:
images: ${{ env.REGISTRY_HOST }}/${{ github.repository }}
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@v3
with:
registry: ${{ env.REGISTRY_HOST }}
username: ${{ github.repository_owner }}
password: ${{ secrets.REGISTRY }}
- name: Build and Push Image
uses: docker/build-push-action@v6
id: build_image
with:
context: .
file: ./Containerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
- name: Install envsubst dependencies
if: github.event_name != 'pull_request'
run: |
sudo apt-get update && sudo apt-get install -y gettext
- name: Install Cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v4.1.2
- name: Sign container image
if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false'
run: |
DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' humocs-man.duckdns.org/humocs-man/fluffy-pancake:stable)
cosign sign -y \
--key env://COSIGN_PRIVATE_KEY \
"$DIGEST"
env:
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
COSIGN_PASSWORD: ""