Files
fluffy-pancake/.gitea/workflows/build.yml
T
2026-06-05 15:53:13 +00:00

162 lines
5.7 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 }}"
IMAGE_REGISTRY: "humocs-man.duckdns.org/${{ github.repository_owner }}"
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: |
echo "IMAGE_REGISTRY=${IMAGE_REGISTRY,,}" >> ${GITHUB_ENV}
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${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@v4
- name: Mount BTRFS for podman storage
id: container-storage-action
uses: ublue-os/container-storage-action@main
with:
target-dir: /var/lib/containers
mount-opts: compress-force=zstd:2
- name: Image Metadata
uses: docker/metadata-action@v5
id: metadata
with:
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.title=${{ env.IMAGE_NAME }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.version=${{ env.IMAGE_TAG }}.{{date 'YYYYMMDD'}}
containers.bootc=1
ostree.bootable=1
sep-tags: " "
sep-annotations: " "
- name: Cache buildah layers
uses: actions/cache@v4
with:
path: |
~/.cache/buildah
/tmp/.buildah-cache
key: ${{ runner.os }}-${{ github.workflow }}-${{ hashFiles('Containerfile', 'build/**', 'configs/**', 'scripts/**') }}-${{ github.ref }}
restore-keys: |
${{ runner.os }}-${{ github.workflow }}-${{ hashFiles('Containerfile', 'build/**', 'configs/**', 'scripts/**') }}-
${{ runner.os }}-${{ github.workflow }}-
- name: Build Image
id: build_image
uses: redhat-actions/buildah-build@v2
with:
containerfiles: |
./Containerfile
image: ${{ env.IMAGE_NAME }}
tags: ${{ env.IMAGE_TAG }}
labels: ${{ steps.metadata.outputs.labels }}
oci: true
- name: Rechunk with chunkah
run: |
set -euo pipefail
IMG="localhost/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}"
CHUNKED_IMG="localhost/${{ env.IMAGE_NAME }}-chunked:${{ env.IMAGE_TAG }}"
CONFIG=$(buildah inspect "$IMG" | jq -c .)
sudo rm -rf /tmp/.buildah-cache/* 2>/dev/null || true
CHUNKAH_CF=$(mktemp)
curl -sL https://github.com/coreos/chunkah/releases/download/v0.5.0/Containerfile.splitter -o "$CHUNKAH_CF"
buildah build --skip-unused-stages=false \
-f "$CHUNKAH_CF" \
--from "$IMG" \
--build-arg CHUNKAH_CONFIG_STR="$CONFIG" \
--build-arg "CHUNKAH_ARGS=--prune /sysroot/ --max-layers 128 --compressed --label ostree.commit- --label ostree.final-diffid- --label ostree.bootable=true --label containers.bootc=1" \
-t "$CHUNKED_IMG" \
.
rm -f "$CHUNKAH_CF" out.ociarchive
buildah rmi "$IMG"
for full_tag in ${{ steps.metadata.outputs.tags }}; do
tag_only="${full_tag##*:}"
buildah tag "$CHUNKED_IMG" "localhost/${{ env.IMAGE_NAME }}:${tag_only}"
done
buildah rmi "$CHUNKED_IMG"
- name: Login to Gitea Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: humocs-man.duckdns.org
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to Gitea Registry
id: push
if: github.event_name != 'pull_request'
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: ${{ steps.metadata.outputs.tags }}
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Cosign
uses: sigstore/cosign-installer@v3
if: github.event_name != 'pull_request'
- name: Sign container image
if: github.event_name != 'pull_request' && env.IS_TEST_BUILD == 'false'
run: |
cosign sign -y --tlog-upload=false --key env://COSIGN_PRIVATE_KEY "${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }}"
env:
COSIGN_EXPERIMENTAL: false
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}