Compare commits

..

2 Commits

Author SHA1 Message Date
876a16d430 Add image digest as output 2025-08-23 01:51:00 +02:00
49ab52b9d4 Make uploading manifests optional 2025-08-23 01:50:58 +02:00

View File

@@ -3,26 +3,29 @@ name: Build and deploy
on: on:
workflow_call: workflow_call:
inputs: inputs:
push_manifests: generate_crds:
description: Push manifest files to OCI repository description: Runs a binary called gencrd in the docker container and writes the output to ./manifests/crds.yaml
default: true type: boolean
upload_manifests:
description: Upload manifest files to OCI repository
type: boolean type: boolean
webhook_url: webhook_url:
description: Webhook to call after build is completed description: Webhook to call after build is completed
type: string type: string
outputs: outputs:
images: digest:
value: ${{ jobs.build.outputs.images }} description: Digest of the build docker container
value: ${{ jobs.build.outputs.digest }}
env: env:
OCI_REPO: git.huizinga.dev/${{ gitea.repository_owner}}/${{gitea.event.repository.name}} OCI_REPO: git.huizinga.dev/dreaded_x/${{ gitea.event.repository.name}}
jobs: jobs:
build: build:
name: Build container and manifests name: Build container and manifests
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
images: ${{ steps.images.outputs.images }} digest: ${{ steps.build.outputs.digest }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -45,12 +48,12 @@ jobs:
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Install kustomize - name: Install kustomize
if: inputs.push_manifests == 'true' if: inputs.upload_manifests == true
run: | run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
- name: Setup Flux CLI - name: Setup Flux CLI
if: inputs.push_manifests == 'true' if: inputs.upload_manifests == true
uses: https://github.com/fluxcd/flux2/action@main uses: https://github.com/fluxcd/flux2/action@main
with: with:
version: v2.5.0 version: v2.5.0
@@ -59,6 +62,7 @@ jobs:
id: meta id: meta
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: ${{ env.OCI_REPO }}
tags: | tags: |
type=edge type=edge
type=ref,event=branch type=ref,event=branch
@@ -66,38 +70,35 @@ jobs:
type=semver,pattern=v{{major}}.{{minor}} type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}} type=semver,pattern=v{{major}}
- name: Bake containers - name: Build container
id: bake id: build
uses: docker/bake-action@v6 uses: docker/build-push-action@v6
with: with:
files: | context: .
./docker-bake.hcl
cwd://${{ steps.meta.outputs.bake-file }}
push: true push: true
sbom: true sbom: true
provenance: mode=max provenance: mode=max
tags: ${{ steps.meta.outputs.tags }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
"RELEASE_VERSION=${{ env.RELEASE_VERSION }}"
env: env:
TAG_BASE: ${{ env.OCI_REPO }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }} SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}
- name: Output images - name: Generate CRDs
id: images if: inputs.generate_crds == true
run: | run: |
METADATA='${{ steps.bake.outputs.metadata }}' docker run --rm ${{ env.OCI_REPO }}@${{ steps.build.outputs.imageid }} /crdgen > ./manifests/crds.yaml
IMAGES=$(echo ${METADATA} | jq 'map_values((."image.name" | select(. != null) | split(",|:";""))[0] + "@" + ."containerimage.digest")')
echo images=${IMAGES} >> $GITHUB_OUTPUT
- name: Kustomize manifests - name: Kustomize manifests
if: inputs.push_manifests == 'true' if: inputs.upload_manifests == true
run: | run: |
curl -L https://github.com/hairyhenderson/gomplate/releases/download/v4.3.3/gomplate_linux-amd64 -o gomplate ./kustomize build ./manifests | sed "s/\${DIGEST}/${{ steps.build.outputs.digest }}/" > ./manifests.yaml
chmod +x ./gomplate
echo ${{ steps.images.outputs.images }} > ./images.json
./kustomize build ./manifests | ./gomplate --context images="file://${PWD}/images.json" > ./manifests.yaml
- name: Push manifests - name: Push manifests
if: inputs.push_manifests == 'true' if: inputs.upload_manifests == true
run: | run: |
flux push artifact oci://${{ env.OCI_REPO }}/manifests:${{ gitea.head_ref || gitea.ref_name }} \ flux push artifact oci://${{ env.OCI_REPO }}/manifests:${{ gitea.head_ref || gitea.ref_name }} \
--path="./manifests.yaml" \ --path="./manifests.yaml" \
@@ -106,9 +107,24 @@ jobs:
$(echo "${{ steps.meta.outputs.labels }}" | sed -e 's/^/-a /') $(echo "${{ steps.meta.outputs.labels }}" | sed -e 's/^/-a /')
flux tag artifact oci://${{ env.OCI_REPO }}/manifests:${{ gitea.head_ref || gitea.ref_name }} \ flux tag artifact oci://${{ env.OCI_REPO }}/manifests:${{ gitea.head_ref || gitea.ref_name }} \
$(echo "${{ steps.meta.outputs.tags }}" | sed -e 's/^/--tag /') $(echo "${{ steps.meta.outputs.tags }}" | sed -e 's/^.*:/--tag /')
- name: Call webhook - name: Call webhook
if: inputs.webhook_url != '' if: inputs.webhook_url != ''
run: | run: |
curl ${{ inputs.webhook_url }} || true curl ${{ inputs.webhook_url }}
- name: Notify build status
if: failure()
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
# TODO: Escaping issues need to be solved first
# format: markdown
message: |
🚨 *BUILD FAILED!*
${{ gitea.repository }} (#${{ gitea.run_number }})
[${{ gitea.ref_name }}@sha1:${{ gitea.sha }}]
> ${{ gitea.event.head_commit.message }}