Compare commits

..

2 Commits

Author SHA1 Message Date
bbc713b423 Setup caching 2025-11-17 17:18:26 +01:00
08d091ac23 Use Docker bake to build targets 2025-11-17 17:18:26 +01:00

View File

@@ -3,6 +3,9 @@ name: Build and deploy
on:
workflow_call:
inputs:
generate_crds:
description: Runs a binary called gencrd in the docker container and writes the output to ./manifests/crds.yaml
type: boolean
push_manifests:
description: Push manifest files to OCI repository
default: true
@@ -11,18 +14,19 @@ on:
description: Webhook to call after build is completed
type: string
outputs:
images:
value: ${{ jobs.build.outputs.images }}
metadata:
description: Digest of the build docker container
value: ${{ jobs.build.outputs.metadata }}
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:
build:
name: Build container and manifests
runs-on: ubuntu-latest
outputs:
images: ${{ steps.images.outputs.images }}
metadata: ${{ steps.build.outputs.metadata }}
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -45,12 +49,12 @@ jobs:
uses: docker/setup-buildx-action@v3
- name: Install kustomize
if: inputs.push_manifests == 'true'
if: inputs.push_manifests == true
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
- name: Setup Flux CLI
if: inputs.push_manifests == 'true'
if: inputs.push_manifests == true
uses: https://github.com/fluxcd/flux2/action@main
with:
version: v2.5.0
@@ -67,12 +71,15 @@ jobs:
type=semver,pattern=v{{major}}
- name: Bake containers
id: bake
id: build
uses: docker/bake-action@v6
with:
files: |
./docker-bake.hcl
cwd://${{ steps.meta.outputs.bake-file }}
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
push: true
sbom: true
provenance: mode=max
@@ -81,23 +88,18 @@ jobs:
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}
- name: Output images
id: images
- name: Generate CRDs
if: inputs.generate_crds == true
run: |
METADATA='${{ steps.bake.outputs.metadata }}'
IMAGES=$(echo ${METADATA} | jq 'map_values((."image.name" | select(. != null) | split(",|:";""))[0] + "@" + ."containerimage.digest")')
echo images=${IMAGES} >> $GITHUB_OUTPUT
docker run --rm ${{ env.OCI_REPO }}@${{ steps.build.outputs.imageid }} /crdgen > ./manifests/crds.yaml
- name: Kustomize manifests
if: inputs.push_manifests == 'true'
if: inputs.push_manifests == true
run: |
curl -L https://github.com/hairyhenderson/gomplate/releases/download/v4.3.3/gomplate_linux-amd64 -o gomplate
chmod +x ./gomplate
echo ${{ steps.images.outputs.images }} > ./images.json
./kustomize build ./manifests | ./gomplate --context images="file://${PWD}/images.json" > ./manifests.yaml
./kustomize build ./manifests | sed "s/\${DIGEST}/${{ steps.build.outputs.digest }}/" > ./manifests.yaml
- name: Push manifests
if: inputs.push_manifests == 'true'
if: inputs.push_manifests == true
run: |
flux push artifact oci://${{ env.OCI_REPO }}/manifests:${{ gitea.head_ref || gitea.ref_name }} \
--path="./manifests.yaml" \
@@ -106,9 +108,24 @@ jobs:
$(echo "${{ steps.meta.outputs.labels }}" | sed -e 's/^/-a /')
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
if: inputs.webhook_url != ''
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 }}