|
17 | 17 | permissions: |
18 | 18 | contents: read |
19 | 19 | packages: write |
| 20 | + outputs: |
| 21 | + short-sha: ${{ steps.sha.outputs.short }} |
20 | 22 | steps: |
21 | 23 | - uses: actions/checkout@v4 |
22 | 24 |
|
| 25 | + - name: Compute short SHA |
| 26 | + id: sha |
| 27 | + run: echo "short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" |
| 28 | + |
23 | 29 | - name: Fetch CI secrets from Hanzo KMS |
24 | 30 | id: kms |
25 | 31 | env: |
|
46 | 52 | | jq -r '.secret.secretValue' |
47 | 53 | } |
48 | 54 |
|
49 | | - for name in DOCKERHUB_USERNAME DOCKERHUB_TOKEN DIGITALOCEAN_ACCESS_TOKEN; do |
| 55 | + for name in DOCKERHUB_USERNAME DOCKERHUB_TOKEN; do |
50 | 56 | val="$(fetch_secret "$name")" |
51 | 57 | [ -n "$val" ] && [ "$val" != "null" ] || { echo "::error::Missing KMS secret $name"; exit 1; } |
52 | 58 | echo "::add-mask::${val}" |
@@ -105,49 +111,43 @@ jobs: |
105 | 111 | needs: build |
106 | 112 | if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' |
107 | 113 | runs-on: ubuntu-latest |
| 114 | + permissions: |
| 115 | + contents: read |
108 | 116 | 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 |
125 | 125 |
|
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 |
131 | 130 |
|
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" |
134 | 136 |
|
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}" |
139 | 140 |
|
140 | | - - name: Configure kubectl (hanzo-k8s) |
141 | | - run: doctl kubernetes cluster kubeconfig save hanzo-k8s |
| 141 | + echo "--- Updated CR ---" |
| 142 | + cat "${CR}" |
142 | 143 |
|
143 | | - - name: Rolling update hanzo-sql |
| 144 | + - name: Commit and push to universe |
| 145 | + working-directory: universe |
144 | 146 | 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