Files
workflows/.gitea/workflows/docker-kubernetes.yaml

137 lines
4.5 KiB
YAML

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
type: boolean
webhook_url:
description: Webhook to call after build is completed
type: string
outputs:
images:
value: ${{ jobs.build.outputs.images }}
env:
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 }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set timestamp and release version
run: |
echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
git fetch --prune --unshallow --tags --force
echo "RELEASE_VERSION=$(git describe --always --dirty='--modified')" >> $GITHUB_ENV
cat $GITHUB_ENV
- name: Login to registry
uses: docker/login-action@v3
with:
registry: git.huizinga.dev
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install kustomize
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
uses: https://github.com/fluxcd/flux2/action@main
with:
version: v2.5.0
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
tags: |
type=edge
type=ref,event=branch
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
- name: Bake containers
id: bake
uses: docker/bake-action@v6
with:
files: |
./docker-bake.hcl
cwd://${{ steps.meta.outputs.bake-file }}
push: true
sbom: true
provenance: mode=max
env:
TAG_BASE: ${{ env.OCI_REPO }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}
- name: Output images
id: images
run: |
METADATA='${{ steps.bake.outputs.metadata }}'
IMAGES=$(echo ${METADATA} | jq 'map_values((."image.name" | split(",|:";""))[0] + "@" + ."containerimage.digest")')
echo images=${IMAGES} >> $GITHUB_OUTPUT
# TODO: Move this into docker-bake.hcl
- name: Generate CRDs
if: inputs.generate_crds == true
run: |
docker run --rm ${{ env.OCI_REPO }}@${{ steps.build.outputs.imageid }} /crdgen > ./manifests/crds.yaml
- name: Kustomize manifests
if: inputs.push_manifests == true
run: |
# TODO: Fix this
./kustomize build ./manifests | sed "s/\${DIGEST}/${{ steps.build.outputs.digest }}/" > ./manifests.yaml
- name: Push manifests
if: inputs.push_manifests == true
run: |
flux push artifact oci://${{ env.OCI_REPO }}/manifests:${{ gitea.head_ref || gitea.ref_name }} \
--path="./manifests.yaml" \
--source="$(git config --get remote.origin.url)" \
--revision="$(git rev-parse HEAD)" \
$(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 /')
- name: Call webhook
if: inputs.webhook_url != ''
run: |
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 }}