148 lines
5.5 KiB
YAML
148 lines
5.5 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"
|
|
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
|
|
|
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
|
|
env:
|
|
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
|
|
BUILDAH_ISOLATION: chroot
|
|
STORAGE_DRIVER: vfs
|
|
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: Install Buildah
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y buildah fuse-overlayfs
|
|
|
|
- name: Configure Buildah Storage
|
|
run: |
|
|
mkdir -p ~/.config/containers
|
|
echo -e '[storage]\ndriver = "vfs"\n[storage.options]\nmount_program = "/usr/bin/fuse-overlayfs"' > ~/.config/containers/storage.conf
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- 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: Generate Tags
|
|
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
|
|
id: metadata
|
|
uses: docker/metadata-action@v6
|
|
with:
|
|
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
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 }}
|
|
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.IMAGE_TAG }}.{{date 'YYYYMMDD'}}
|
|
containers.bootc=1
|
|
ostree.bootable=1
|
|
|
|
- name: Build Image (Buildah)
|
|
id: build_image
|
|
uses: redhat-actions/buildah-build@v2
|
|
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 }}
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.REGISTRY }}
|
|
|
|
- name: Install Cosign
|
|
if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false'
|
|
uses: sigstore/cosign-installer@v4.1.2
|
|
|
|
- name: Sign container image (Pure Digest)
|
|
if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false'
|
|
env:
|
|
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
|
|
COSIGN_PASSWORD: ""
|
|
run: |
|
|
echo "${{ secrets.REGISTRY }}" | cosign login "${{ env.REGISTRY_HOST }}" -u "${{ github.repository_owner }}" --password-stdin
|
|
DIGEST="${{ steps.push_image.outputs.digest }}"
|
|
IMAGE_REF="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${DIGEST}"
|
|
echo "Signiere exklusiv via Digest: ${IMAGE_REF}"
|
|
cosign sign -y \
|
|
--key env://COSIGN_PRIVATE_KEY \
|
|
--use-signing-config=false \
|
|
--new-bundle-format=false \
|
|
--tlog-upload=false \
|
|
--registry-referrers-mode=legacy \
|
|
"${IMAGE_REF}"
|
|
|
|
- name: Post-Build Cleanup
|
|
if: always()
|
|
run: |
|
|
echo "Führe Smart Cleanup durch..."
|
|
buildah rm $(buildah containers -q) >/dev/null 2>&1 || true
|
|
buildah rmi $(buildah images -f "dangling=true" -q) >/dev/null 2>&1 || true
|
|
echo "Speicherplatz bereinigt." |