From 4ef6a22e28d04ff42499f95f04a3a93e03364eea Mon Sep 17 00:00:00 2001 From: Mathias Bergqvist Date: Mon, 20 Apr 2026 21:36:22 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20add=20CD=20workflow=20(buildctl=20?= =?UTF-8?q?=E2=86=92=20Gitea=20registry=20=E2=86=92=20infra=20repo=20updat?= =?UTF-8?q?e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/cd.yml | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .gitea/workflows/cd.yml diff --git a/.gitea/workflows/cd.yml b/.gitea/workflows/cd.yml new file mode 100644 index 0000000..c6f160e --- /dev/null +++ b/.gitea/workflows/cd.yml @@ -0,0 +1,57 @@ +name: cd + +on: + push: + branches: [main] + +jobs: + deploy: + name: Build and deploy + needs: [check] + runs-on: self-hosted + env: + SERVICE: supervisor + IMAGE: gitea.d-ma.be/mathias/supervisor + INFRA_REPO: git@gitea.d-ma.be:mathias/infra.git + BUILDKIT_HOST: unix:///run/buildkit/buildkitd.sock + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build and push image + run: | + IMAGE_TAG="${{ github.sha }}" + echo "Building ${IMAGE}:${IMAGE_TAG}" + buildctl --addr "${BUILDKIT_HOST}" build \ + --frontend dockerfile.v0 \ + --local context=. \ + --local dockerfile=. \ + --opt build-arg:VERSION="${IMAGE_TAG}" \ + --output "type=image,name=${IMAGE}:${IMAGE_TAG},push=true" + echo "Built and pushed ${IMAGE}:${IMAGE_TAG}" + + - name: Update infra repo + run: | + IMAGE_TAG="${{ github.sha }}" + mkdir -p ~/.ssh + echo "${{ secrets.INFRA_DEPLOY_KEY }}" > ~/.ssh/infra_deploy_key + chmod 600 ~/.ssh/infra_deploy_key + ssh-keyscan gitea.d-ma.be >> ~/.ssh/known_hosts 2>/dev/null + + GIT_SSH_COMMAND="ssh -i ~/.ssh/infra_deploy_key -o IdentitiesOnly=yes" \ + git clone "${INFRA_REPO}" /tmp/infra-update + + cd /tmp/infra-update + sed -i "s|gitea.d-ma.be/mathias/supervisor:.*|gitea.d-ma.be/mathias/supervisor:${IMAGE_TAG}|" \ + "k3s/apps/${SERVICE}/deployment.yaml" + + git config user.email "cd-bot@d-ma.be" + git config user.name "CD Bot" + git add "k3s/apps/${SERVICE}/deployment.yaml" + git commit -m "chore(deploy): ${SERVICE} → ${IMAGE_TAG}" + GIT_SSH_COMMAND="ssh -i ~/.ssh/infra_deploy_key -o IdentitiesOnly=yes" \ + git push + + rm -rf /tmp/infra-update + rm ~/.ssh/infra_deploy_key + echo "Infra repo updated: ${SERVICE} → ${IMAGE_TAG}"