Skip to content

Commit 4fb03ac

Browse files
committed
feat: migrate deploy to GitOps pattern — stop kubectl set image
- Deploy job now sparse-checkouts universe repo + updates CR tag with yq - Commits as hanzo-bot, operator reconciles the change - Removes direct K8s cluster access from CI (no DIGITALOCEAN_ACCESS_TOKEN) - Gated on needs: build + branch protection
1 parent 0aa45b6 commit 4fb03ac

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

.github/workflows/deploy.yml

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ jobs:
1717
permissions:
1818
contents: read
1919
packages: write
20+
outputs:
21+
short-sha: ${{ steps.sha.outputs.short }}
2022
steps:
2123
- uses: actions/checkout@v4
2224

25+
- name: Compute short SHA
26+
id: sha
27+
run: echo "short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
28+
2329
- name: Fetch CI secrets from Hanzo KMS
2430
id: kms
2531
env:
@@ -46,7 +52,7 @@ jobs:
4652
| jq -r '.secret.secretValue'
4753
}
4854
49-
for name in DOCKERHUB_USERNAME DOCKERHUB_TOKEN DIGITALOCEAN_ACCESS_TOKEN; do
55+
for name in DOCKERHUB_USERNAME DOCKERHUB_TOKEN; do
5056
val="$(fetch_secret "$name")"
5157
[ -n "$val" ] && [ "$val" != "null" ] || { echo "::error::Missing KMS secret $name"; exit 1; }
5258
echo "::add-mask::${val}"
@@ -105,49 +111,43 @@ jobs:
105111
needs: build
106112
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
107113
runs-on: ubuntu-latest
114+
permissions:
115+
contents: read
108116
steps:
109-
- name: Fetch deploy secrets from Hanzo KMS
110-
id: kms
111-
env:
112-
KMS_CLIENT_ID: ${{ secrets.KMS_CLIENT_ID }}
113-
KMS_CLIENT_SECRET: ${{ secrets.KMS_CLIENT_SECRET }}
114-
run: |
115-
set -euo pipefail
116-
KMS_URL="${KMS_URL:-https://kms.hanzo.ai}"
117-
118-
ACCESS_TOKEN="$(
119-
curl -fsS -X POST "${KMS_URL}/api/v1/auth/universal-auth/login" \
120-
-H "Content-Type: application/json" \
121-
-d "$(jq -nc --arg cid "$KMS_CLIENT_ID" --arg cs "$KMS_CLIENT_SECRET" \
122-
'{clientId: $cid, clientSecret: $cs}')" \
123-
| jq -r '.accessToken'
124-
)"
117+
- name: Checkout universe repo
118+
uses: actions/checkout@v4
119+
with:
120+
repository: hanzoai/universe
121+
token: ${{ secrets.GH_PAT }}
122+
path: universe
123+
sparse-checkout: |
124+
infra/k8s/hanzo-operator/crs/sql.yaml
125125
126-
DO_TOKEN="$(
127-
curl -fsS "${KMS_URL}/api/v3/secrets/raw/DIGITALOCEAN_ACCESS_TOKEN?workspaceSlug=gitops&environment=prod&secretPath=/ci&viewSecretValue=true&include_imports=true" \
128-
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
129-
| jq -r '.secret.secretValue'
130-
)"
126+
- name: Install yq
127+
run: |
128+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
129+
sudo chmod +x /usr/local/bin/yq
131130
132-
echo "::add-mask::${DO_TOKEN}"
133-
echo "do_token=${DO_TOKEN}" >> "$GITHUB_OUTPUT"
131+
- name: Update SQL CR image tag
132+
working-directory: universe
133+
run: |
134+
TAG="${{ needs.build.outputs.short-sha }}"
135+
CR="infra/k8s/hanzo-operator/crs/sql.yaml"
134136
135-
- name: Install doctl
136-
uses: digitalocean/action-doctl@v2
137-
with:
138-
token: ${{ steps.kms.outputs.do_token }}
137+
echo "Updating ${CR} image tag to ${TAG}"
138+
yq -i '.spec.image.tag = "'"${TAG}"'"' "${CR}"
139+
yq -i '.spec.image.pullPolicy = "IfNotPresent"' "${CR}"
139140
140-
- name: Configure kubectl (hanzo-k8s)
141-
run: doctl kubernetes cluster kubeconfig save hanzo-k8s
141+
echo "--- Updated CR ---"
142+
cat "${CR}"
142143
143-
- name: Rolling update hanzo-sql
144+
- name: Commit and push to universe
145+
working-directory: universe
144146
run: |
145-
# Update both clusters if StatefulSets exist
146-
for ss in hanzo-sql sql; do
147-
if kubectl -n hanzo get statefulset/${ss} &>/dev/null; then
148-
kubectl -n hanzo set image statefulset/${ss} \
149-
sql=ghcr.io/hanzoai/sql:latest
150-
kubectl -n hanzo rollout status statefulset/${ss} --timeout=120s
151-
break
152-
fi
153-
done
147+
TAG="${{ needs.build.outputs.short-sha }}"
148+
git config user.name "hanzo-bot"
149+
git config user.email "bot@hanzo.ai"
150+
git add infra/k8s/hanzo-operator/crs/sql.yaml
151+
git diff --cached --quiet && { echo "No changes to commit"; exit 0; }
152+
git commit -m "deploy(sql): update image tag to ${TAG}"
153+
git push origin main

0 commit comments

Comments
 (0)