From f49543e7529d454a5581b40a176fe34f948c45f2 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Thu, 20 Mar 2025 01:47:36 +0100 Subject: [PATCH] Improve workflow and generate CRDs --- .dockerignore | 4 ++ .gitea/workflows/build.yaml | 82 ++++++++++++++++++------------------ .pre-commit-config.yaml | 1 + manifests/deployment.yaml | 2 +- manifests/kustomization.yaml | 1 + 5 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c579be0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +* +!queries +!src +!Cargo.* diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 2534ad5..1c47dbe 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -9,24 +9,12 @@ on: jobs: build: - name: Build container + name: Build container and manifests runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: git.huizinga.dev/dreaded_x/${{ gitea.event.repository.name}} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=sha - - name: Login to registry uses: docker/login-action@v3 with: @@ -34,20 +22,8 @@ jobs: username: ${{ gitea.actor }} password: ${{ secrets.REGISTRY_TOKEN }} - - name: Build and push Docker image - uses: https://github.com/docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - manifests: - name: Publish manifests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Install kustomize run: | @@ -58,26 +34,50 @@ jobs: with: version: v2.5.0 - - name: Login to registry - uses: docker/login-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 with: - registry: git.huizinga.dev - username: ${{ gitea.actor }} - password: ${{ secrets.REGISTRY_TOKEN }} + images: git.huizinga.dev/dreaded_x/${{ gitea.event.repository.name}} + tags: | + type=edge + type=ref,event=branch + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} - # TODO: Generate and include crds - - name: Generate manifets + - name: Build and export to docker + id: build + uses: docker/build-push-action@v6 + with: + context: . + load: true + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate CRDs run: | - ./kustomize build ./manifests | sed "s/\${SHA_SHORT}/$(git rev-parse --short HEAD)/" > ./app.yaml + docker run --rm ${{ steps.build.outputs.imageid }} crdgen > ./manifests/crds.yaml + + - name: Push container + uses: docker/build-push-action@v6 + id: push + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Kustomize manifests + run: | + ./kustomize build ./manifests | sed "s/\${DIGEST}/${{ steps.push.outputs.digest }}/" > ./manifests.yaml - name: Push manifests run: | - flux push artifact oci://git.huizinga.dev/dreaded_x/${{ gitea.event.repository.name }}/manifests:sha-$(git rev-parse --short HEAD) \ - --path="./app.yaml" \ + flux push artifact oci://git.huizinga.dev/dreaded_x/${{ gitea.event.repository.name }}/manifests:latest \ + --path="./manifests.yaml" \ --source="$(git config --get remote.origin.url)" \ - --revision="$(git branch --show-current)@sha1:$(git rev-parse HEAD)" + --revision="$(git branch --show-current)@sha1:$(git rev-parse HEAD)" \ + $(echo "${{ steps.meta.outputs.labels }}" | sed -e 's/^/-a /') - - name: Tag manifests - run: | flux tag artifact oci://git.huizinga.dev/dreaded_x/${{ gitea.event.repository.name }}/manifests:sha-$(git rev-parse --short HEAD) \ - --tag latest + $(echo k${{ steps.meta.outputs.tags }}" | sed -e 's/^.*:/--tag /') diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d75dab1..0bd36bd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,6 +4,7 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer + - id: check-yaml - id: check-toml - id: check-added-large-files - id: check-merge-conflict diff --git a/manifests/deployment.yaml b/manifests/deployment.yaml index 7b63296..9f71a4a 100644 --- a/manifests/deployment.yaml +++ b/manifests/deployment.yaml @@ -21,7 +21,7 @@ spec: securityContext: {} containers: - name: lldap-controller - image: git.huizinga.dev/dreaded_x/lldap-controller:sha-${SHA_SHORT} + image: git.huizinga.dev/dreaded_x/lldap-controller@${DIGEST} imagePullPolicy: IfNotPresent securityContext: {} resources: diff --git a/manifests/kustomization.yaml b/manifests/kustomization.yaml index c40ff6d..a02d6c5 100644 --- a/manifests/kustomization.yaml +++ b/manifests/kustomization.yaml @@ -2,6 +2,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namespace: lldap resources: + - ./crds.yaml - ./service-account.yaml - ./cluster-role.yaml - ./cluster-role-binding.yaml