.gitea/workflows/build.yml aktualisiert

buildah-refactoring
This commit is contained in:
2026-06-14 19:30:05 +00:00
parent 6d3087bc61
commit 825cc3795d
+37 -46
View File
@@ -12,6 +12,8 @@ env:
IMAGE_DESC: "Custom Fedora bootc image" IMAGE_DESC: "Custom Fedora bootc image"
IMAGE_NAME: "${{ github.event.repository.name }}" IMAGE_NAME: "${{ github.event.repository.name }}"
DEFAULT_TAG: "stable" DEFAULT_TAG: "stable"
# Erzwingt die Verwendung von Node 24 für alle JavaScript-Actions
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }} group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
@@ -21,20 +23,16 @@ jobs:
build_push: build_push:
name: Build and push image name: Build and push image
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
permissions: permissions:
contents: read contents: read
packages: write packages: write
id-token: write id-token: write
steps: steps:
- name: Prepare environment - name: Prepare environment
run: | run: |
# Extrahiert die reine Domain/Host aus der Gitea-URL
REGISTRY_HOST=$(echo "${{ github.server_url }}" | awk -F/ '{print $3}') REGISTRY_HOST=$(echo "${{ github.server_url }}" | awk -F/ '{print $3}')
OWNER_LOWER="${{ github.repository_owner }}" OWNER_LOWER="${{ github.repository_owner }}"
NAME_LOWER="${{ env.IMAGE_NAME }}" NAME_LOWER="${{ env.IMAGE_NAME }}"
echo "REGISTRY_HOST=${REGISTRY_HOST}" >> ${GITHUB_ENV} echo "REGISTRY_HOST=${REGISTRY_HOST}" >> ${GITHUB_ENV}
echo "IMAGE_REGISTRY=${REGISTRY_HOST}/${OWNER_LOWER,,}" >> ${GITHUB_ENV} echo "IMAGE_REGISTRY=${REGISTRY_HOST}/${OWNER_LOWER,,}" >> ${GITHUB_ENV}
echo "IMAGE_NAME=${NAME_LOWER,,}" >> ${GITHUB_ENV} echo "IMAGE_NAME=${NAME_LOWER,,}" >> ${GITHUB_ENV}
@@ -52,22 +50,26 @@ jobs:
fi fi
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v4
- name: Set up Docker Buildx - name: Generate Tags
uses: docker/setup-buildx-action@v4 id: generate_tags
run: |
TAGS="${{ env.IMAGE_TAG }}"
if [[ "${{ env.IS_TEST_BUILD }}" == "false" ]]; then
DATE_TAG=$(date +'%Y%m%d')
TAGS="${TAGS} ${{ env.IMAGE_TAG }}.${DATE_TAG} ${DATE_TAG}"
fi
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
TAGS="pr-${{ github.event.pull_request.number }} sha-${GITHUB_SHA::7}"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
- name: Image Metadata - name: Image Metadata
id: metadata id: metadata
uses: docker/metadata-action@v6 uses: docker/metadata-action@v6
with: with:
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} 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: | labels: |
org.opencontainers.image.created={{date 'YYYY-MM-DDTHH:mm:ssZ'}} org.opencontainers.image.created={{date 'YYYY-MM-DDTHH:mm:ssZ'}}
org.opencontainers.image.description=${{ env.IMAGE_DESC }} org.opencontainers.image.description=${{ env.IMAGE_DESC }}
@@ -80,30 +82,28 @@ jobs:
containers.bootc=1 containers.bootc=1
ostree.bootable=1 ostree.bootable=1
- name: Login to Gitea Container Registry - name: Build Image (Buildah)
if: github.event_name != 'pull_request' id: build_image
uses: docker/login-action@v4 uses: redhat-actions/buildah-build@v2
with: with:
context: .
containerfiles: ./Containerfile
image: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{ steps.generate_tags.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
oci: true
- name: Push to Registry
id: push_image
if: github.event_name != 'pull_request'
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ env.REGISTRY_HOST }} registry: ${{ env.REGISTRY_HOST }}
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.REGISTRY }} password: ${{ secrets.REGISTRY }}
- name: Build and Push Image (Docker Buildx)
uses: docker/build-push-action@v7
id: build_image
with:
context: .
file: ./Containerfile
push: ${{ github.event_name != 'pull_request' }}
no-cache: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
- name: Install envsubst dependencies
if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false'
run: |
sudo apt-get update && sudo apt-get install -y gettext
- name: Install Cosign - name: Install Cosign
if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false' if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false'
uses: sigstore/cosign-installer@v4.1.2 uses: sigstore/cosign-installer@v4.1.2
@@ -114,13 +114,9 @@ jobs:
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }} COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
COSIGN_PASSWORD: "" COSIGN_PASSWORD: ""
run: | run: |
# Cosign an der Gitea-Registry anmelden
echo "${{ secrets.REGISTRY }}" | cosign login "${{ env.REGISTRY_HOST }}" -u "${{ github.repository_owner }}" --password-stdin echo "${{ secrets.REGISTRY }}" | cosign login "${{ env.REGISTRY_HOST }}" -u "${{ github.repository_owner }}" --password-stdin
DIGEST="${{ steps.push_image.outputs.digest }}"
# Den exakten Digest direkt aus dem Buildx-Output ziehen
DIGEST="${{ steps.build_image.outputs.digest }}"
IMAGE_REF="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${DIGEST}" IMAGE_REF="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${DIGEST}"
echo "Signiere exklusiv via Digest: ${IMAGE_REF}" echo "Signiere exklusiv via Digest: ${IMAGE_REF}"
cosign sign -y \ cosign sign -y \
--key env://COSIGN_PRIVATE_KEY \ --key env://COSIGN_PRIVATE_KEY \
@@ -133,12 +129,7 @@ jobs:
- name: Post-Build Cleanup - name: Post-Build Cleanup
if: always() if: always()
run: | run: |
echo "Führe serverseitige Tiefenreinigung durch..." echo "Führe Smart Cleanup durch..."
buildah rm $(buildah containers -q) >/dev/null 2>&1 || true
# 1. Löscht ungenutzte Zwischenschritte und temporäre Volumes buildah rmi $(buildah images -f "dangling=true" -q) >/dev/null 2>&1 || true
docker system prune -f --volumes echo "Speicherplatz bereinigt."
# 2. Killt den BuildKit-Cache komplett (Verhindert das unbemerktes Zumüllen des VPS)
docker builder prune -af
echo "VPS-Speicherplatz erfolgreich bereinigt!"