1414 mode :
1515 description : " Run mode"
1616 required : true
17- default : preflight
17+ default : deploy
1818 type : choice
1919 options :
2020 - preflight
2121 - deploy
2222
2323env :
24- RUN_MODE : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.mode || 'preflight' }}
24+ RUN_MODE : ${{ github.event_name == 'push' && 'deploy' || github.event_name == ' workflow_dispatch' && github.event.inputs.mode || 'preflight' }}
2525 WERF_ENV : " production"
2626 WERF_REPO : " ghcr.io/${{ github.repository_owner }}/werfio-guides"
2727 WERF_STAGES_STORAGE : " ghcr.io/werf/werfio-guides-stages"
2828 WERF_SET_ACTIVE_RELEASE : " global.active_release=2"
2929 WERFIO_GITHUB_TOKEN : " ${{ secrets.API_TOKEN }}"
30- VAULT_ADDR : " https://seguro.flant.com"
31- VAULT_ROLE : " werf-web"
32- RU_KUBECONFIG_SECRET_PATH : " projects/data/b454e6aa-39f0-45f4-aa7c-a9465ab154cb/KUBE_CONFIG_RU"
3330
3431jobs :
3532 converge-ru :
@@ -59,74 +56,39 @@ jobs:
5956 - name : Install werf
6057 uses : werf/actions/install@v2
6158
62- - name : Request GitHub OIDC token
63- id : oidc
64- run : |
65- set -euo pipefail
66- oidc_token="$({ curl -fsSL \
67- -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
68- "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=github-access-aud"; } | jq -r '.value')"
69-
70- if [[ -z "$oidc_token" || "$oidc_token" == "null" ]]; then
71- echo "Failed to get GitHub OIDC token" >&2
72- exit 1
73- fi
74-
75- echo "::add-mask::$oidc_token"
76- echo "token=$oidc_token" >> "$GITHUB_OUTPUT"
77-
78- - name : Login to Seguro
79- id : seguro
80- run : |
81- set -euo pipefail
82- vault_token="$({ curl -fsSL \
83- -X POST \
84- -H 'Content-Type: application/json' \
85- "$VAULT_ADDR/v1/auth/github/login" \
86- -d "{\"role\":\"$VAULT_ROLE\",\"jwt\":\"${{ steps.oidc.outputs.token }}\"}"; } | jq -r '.auth.client_token')"
87-
88- if [[ -z "$vault_token" || "$vault_token" == "null" ]]; then
89- echo "Failed to get Vault token from Seguro" >&2
90- exit 1
91- fi
92-
93- echo "::add-mask::$vault_token"
94- echo "token=$vault_token" >> "$GITHUB_OUTPUT"
95-
96- - name : Read RU kubeconfig from Seguro
59+ - name : Import RU kubeconfig from Seguro
60+ id : secrets
61+ uses : hashicorp/vault-action@v2
62+ with :
63+ url : https://seguro.flant.com
64+ path : github
65+ role : werf-web
66+ method : jwt
67+ jwtGithubAudience : github-access-aud
68+ exportEnv : true
69+ secrets : |
70+ projects/data/b454e6aa-39f0-45f4-aa7c-a9465ab154cb/KUBE_CONFIG_RU kube.config | RU_KUBECONFIG_RAW
71+
72+ - name : Normalize RU kubeconfig
9773 id : ru_kubeconfig
9874 run : |
9975 set -euo pipefail
10076
101- response="$(curl -fsSL -H "X-Vault-Token: ${{ steps.seguro.outputs.token }}" "$VAULT_ADDR/v1/$RU_KUBECONFIG_SECRET_PATH")"
102- field_count="$(printf '%s' "$response" | jq -r '.data.data | keys | length')"
77+ secret_value="${RU_KUBECONFIG_RAW:-}"
10378
104- if [[ "$field_count" == "0" || "$field_count" == "null " ]]; then
79+ if [[ -z "$secret_value " ]]; then
10580 echo "RU kubeconfig secret is empty" >&2
10681 exit 1
10782 fi
10883
109- if [[ "$field_count" -ne 1 ]]; then
110- echo "Expected exactly one field in RU kubeconfig secret, got: $(printf '%s' "$response" | jq -r '.data.data | keys | join(", ")')" >&2
111- exit 1
112- fi
113-
114- secret_key="$(printf '%s' "$response" | jq -r '.data.data | keys[0]')"
115- secret_value="$(printf '%s' "$response" | jq -r --arg k "$secret_key" '.data.data[$k]')"
116-
117- if [[ -z "$secret_value" || "$secret_value" == "null" ]]; then
118- echo "RU kubeconfig secret field '$secret_key' is empty" >&2
119- exit 1
120- fi
121-
12284 if printf '%s' "$secret_value" | base64 -d >/tmp/ru-kubeconfig-decoded 2>/dev/null && grep -q '^apiVersion:' /tmp/ru-kubeconfig-decoded; then
12385 kubeconfig_base64="$secret_value"
12486 else
12587 kubeconfig_base64="$(printf '%s' "$secret_value" | base64 | tr -d '\n')"
12688 fi
12789
12890 echo "::add-mask::$kubeconfig_base64"
129- echo "field=$secret_key " >> "$GITHUB_OUTPUT"
91+ echo "field=kube.config " >> "$GITHUB_OUTPUT"
13092 echo "kubeconfig_base64=$kubeconfig_base64" >> "$GITHUB_OUTPUT"
13193
13294 - name : Check RU cluster access
@@ -174,6 +136,10 @@ jobs:
174136 echo "Secret github-werfio exists in werfio-production"
175137 else
176138 echo "Secret github-werfio is missing in werfio-production"
139+ if [[ "$RUN_MODE" == "deploy" ]]; then
140+ echo "Deploy mode requires github-werfio to exist in werfio-production" >&2
141+ exit 1
142+ fi
177143 echo "This is acceptable for preflight, but deploy will fail until the secret is created."
178144 fi
179145
@@ -195,7 +161,7 @@ jobs:
195161 grep '^kind:' /tmp/werf-render-ru.yaml | sort | uniq -c | cat
196162
197163 - name : Deploy RU to new cluster
198- if : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.mode == 'deploy' }}
164+ if : ${{ github.event_name == 'push' || (github.event_name == ' workflow_dispatch' && github.event.inputs.mode == 'deploy') }}
199165 run : |
200166 . $(werf ci-env github --as-file)
201167 werf converge --set global.targetCluster=ru
@@ -215,14 +181,14 @@ jobs:
215181 - Event: ${{ github.event_name }}
216182 - Mode: $RUN_MODE
217183 - Target cluster mode: ru
218- - Seguro role: $VAULT_ROLE
219- - Secret path: $RU_KUBECONFIG_SECRET_PATH
184+ - Seguro role: werf-web
185+ - Secret path: projects/data/b454e6aa-39f0-45f4-aa7c-a9465ab154cb/KUBE_CONFIG_RU
220186 - Secret field used: ${{ steps.ru_kubeconfig.outputs.field }}
221187 - Helm switch: global.targetCluster=ru
222188
223- If mode is preflight, no converge was executed .
189+ On push to branch `chore/prod-split-ru-eu`, this workflow performs a real RU deploy .
224190 Missing namespace is allowed if the token can create namespaces.
225- Missing imagePullSecret is reported but does not fail preflight .
191+ Missing imagePullSecret is allowed only for preflight and blocks deploy .
226192 Current old production cluster was not modified by this workflow.
227193 EOF
228194
@@ -232,3 +198,4 @@ jobs:
232198
233199
234200
201+
0 commit comments