From 5cececaf9496d2d6f553b60f3a9a81370ee39e07 Mon Sep 17 00:00:00 2001 From: Tanner Wright Date: Mon, 25 May 2026 15:04:50 -0600 Subject: [PATCH] seperate build and deploy --- .../{kaniko-build => build}/action.yaml | 0 .../actions/{kaniko-build => build}/build.sh | 29 --------------- .gitea/actions/deploy/action.yaml | 19 ++++++++++ .gitea/actions/deploy/deploy.sh | 35 +++++++++++++++++++ 4 files changed, 54 insertions(+), 29 deletions(-) rename .gitea/actions/{kaniko-build => build}/action.yaml (100%) rename .gitea/actions/{kaniko-build => build}/build.sh (70%) create mode 100644 .gitea/actions/deploy/action.yaml create mode 100644 .gitea/actions/deploy/deploy.sh diff --git a/.gitea/actions/kaniko-build/action.yaml b/.gitea/actions/build/action.yaml similarity index 100% rename from .gitea/actions/kaniko-build/action.yaml rename to .gitea/actions/build/action.yaml diff --git a/.gitea/actions/kaniko-build/build.sh b/.gitea/actions/build/build.sh similarity index 70% rename from .gitea/actions/kaniko-build/build.sh rename to .gitea/actions/build/build.sh index ab5f741..9a00a0f 100644 --- a/.gitea/actions/kaniko-build/build.sh +++ b/.gitea/actions/build/build.sh @@ -97,32 +97,3 @@ while true; do sleep 5 done -# Update k8s manifests -echo "=== Updating manifests ===" -K8S_DIR=$(mktemp -d) -git clone --depth=1 "https://${GIT_USERNAME}:${GITEA_TOKEN}@gitea.saltysoup.dev/tanner/k8s.git" "${K8S_DIR}" -sed -i "s|gitea.saltysoup.dev/tanner/${IMAGE}:.*|gitea.saltysoup.dev/tanner/${IMAGE}:${GITHUB_SHA}|g" \ - "${K8S_DIR}/apps/${APP_DIR}/deployment.yaml" -git -C "${K8S_DIR}" config user.email "ci@saltysoup.dev" -git -C "${K8S_DIR}" config user.name "CI Bot" -git -C "${K8S_DIR}" add "apps/${APP_DIR}/deployment.yaml" -if git -C "${K8S_DIR}" diff --staged --quiet; then - echo "Manifest already at ${GITHUB_SHA}, skipping commit" -else - git -C "${K8S_DIR}" commit -m "ci: ${IMAGE} → ${GITHUB_SHA:0:8}" - git -C "${K8S_DIR}" push -fi -rm -rf "${K8S_DIR}" - -# Trigger ArgoCD refresh immediately -echo "=== Triggering deploy ===" -kubectl annotate application ${APP_DIR} -n argocd argocd.argoproj.io/refresh=normal --overwrite - -# Wait for ArgoCD to apply the new image SHA to the deployment spec -until kubectl get deployment ${APP_DIR} -n hungry -o jsonpath='{.spec.template.spec.containers[0].image}' 2>/dev/null | grep -q "${GITHUB_SHA}"; do - sleep 3 -done - -# Watch the rollout to completion -echo "=== Watching rollout ===" -kubectl rollout status deployment/${APP_DIR} -n hungry --timeout=5m diff --git a/.gitea/actions/deploy/action.yaml b/.gitea/actions/deploy/action.yaml new file mode 100644 index 0000000..e2e3864 --- /dev/null +++ b/.gitea/actions/deploy/action.yaml @@ -0,0 +1,19 @@ +name: Deploy +description: Updates the k8s manifest with the new image SHA and waits for ArgoCD to roll it out +inputs: + repo: + description: Gitea repository name (used to derive the image and app directory) + required: true + image: + description: Image name in the registry (defaults to repo name) + required: false + default: '' +runs: + using: composite + steps: + - name: Update manifest and deploy + shell: sh + env: + REPO: ${{ inputs.repo }} + IMAGE: ${{ inputs.image }} + run: sh ${{ github.action_path }}/deploy.sh diff --git a/.gitea/actions/deploy/deploy.sh b/.gitea/actions/deploy/deploy.sh new file mode 100644 index 0000000..81486b2 --- /dev/null +++ b/.gitea/actions/deploy/deploy.sh @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +IMAGE=${IMAGE:-$REPO} +APP_DIR=$(echo "${IMAGE}" | tr '_' '-') + +# Update k8s manifests +echo "=== Updating manifests ===" +K8S_DIR=$(mktemp -d) +git clone --depth=1 "https://${GIT_USERNAME}:${GITEA_TOKEN}@gitea.saltysoup.dev/tanner/k8s.git" "${K8S_DIR}" +sed -i "s|gitea.saltysoup.dev/tanner/${IMAGE}:.*|gitea.saltysoup.dev/tanner/${IMAGE}:${GITHUB_SHA}|g" \ + "${K8S_DIR}/apps/${APP_DIR}/deployment.yaml" +git -C "${K8S_DIR}" config user.email "ci@saltysoup.dev" +git -C "${K8S_DIR}" config user.name "CI Bot" +git -C "${K8S_DIR}" add "apps/${APP_DIR}/deployment.yaml" +if git -C "${K8S_DIR}" diff --staged --quiet; then + echo "Manifest already at ${GITHUB_SHA}, skipping commit" +else + git -C "${K8S_DIR}" commit -m "ci: ${IMAGE} → ${GITHUB_SHA:0:8}" + git -C "${K8S_DIR}" push +fi +rm -rf "${K8S_DIR}" + +# Trigger ArgoCD refresh immediately +echo "=== Triggering deploy ===" +kubectl annotate application ${APP_DIR} -n argocd argocd.argoproj.io/refresh=normal --overwrite + +# Wait for ArgoCD to apply the new image SHA to the deployment spec +until kubectl get deployment ${APP_DIR} -n hungry -o jsonpath='{.spec.template.spec.containers[0].image}' 2>/dev/null | grep -q "${GITHUB_SHA}"; do + sleep 3 +done + +# Watch the rollout to completion +echo "=== Watching rollout ===" +kubectl rollout status deployment/${APP_DIR} -n hungry --timeout=5m