Skip to content

Commit 07e05b3

Browse files
authored
fix: Make workflows to use variables from environment instead of workflow (#89)
* fix: Make workflows to use variables from environment instead of workflow * fix: Allow force deployment to k8s, even if not supported
1 parent 2d49c12 commit 07e05b3

File tree

4 files changed

+57
-78
lines changed

4 files changed

+57
-78
lines changed

.github/workflows/deploy-and-e2e.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ jobs:
7777
run: |
7878
stack_hash=$(echo -n "$stack" | sha256sum | head -c 8)
7979
stack_id=$((16#$stack_hash))
80-
if [[ ! -f infrastructure/.kube ]];
81-
then
80+
if [[ -n "$runtime" && "$runtime" != "none" ]]; then
81+
runtime="$runtime"
82+
elif [[ ! -f infrastructure/.kube ]]; then
8283
echo "Repository is not compatible with kubernetes"
8384
runtime="docker"
84-
elif [[ -n "$runtime" && "$runtime" != "none" ]]; then
85-
runtime="$runtime"
8685
elif (( stack_id % 2 == 0 )); then
8786
runtime="k8s"
8887
else

.github/workflows/k8s-deploy.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ jobs:
115115
116116
reset-data:
117117
if: ${{ inputs.reset }}
118-
# name: Reset environment (k8s)
119-
# run-name: "Reset environment (core: ${{ inputs.core-image-tag }})
120118
needs: deploy
121119
uses: ./.github/workflows/k8s-reset-data.yml
122120
with:
121+
namespace: "opencrvs-${{ inputs.environment }}"
123122
environment: ${{ inputs.environment }}
124-
core-image-tag: ${{ inputs.core-image-tag }}
125123
secrets: inherit
Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,90 @@
1-
name: Reset environment (k8s)
2-
run-name: "Reset environment (core: ${{ inputs.core-image-tag }})"
1+
name: Reset environment
2+
run-name: "Reset ${{ inputs.environment }} environment (namespace: ${{ inputs.namespace }})"
33
# FIXME:
44
# - replace sleep 30 with kubectl wait for job completion
5+
# - only environment variable is required, namespace could be build as "opencrvs-<environment>"
6+
# but namespace is more natural way for kubernetes
57
on:
68
workflow_dispatch:
79
inputs:
8-
core-image-tag:
9-
description: "Core image tag"
10+
namespace:
11+
description: "Target namespace"
1012
required: true
11-
default: "develop"
12-
type: string
13+
type: string
1314
environment:
1415
description: "Target environment"
1516
required: true
16-
default: "demo"
17-
type: choice
18-
options:
19-
- dev
20-
- demo
17+
type: string
2118
workflow_call:
2219
inputs:
23-
core-image-tag:
20+
namespace:
2421
type: string
2522
environment:
2623
type: string
2724
jobs:
2825
reset:
26+
environment: ${{ inputs.environment }}
2927
env:
30-
ENV: ${{ inputs.environment }}
31-
CORE_IMAGE_TAG: ${{ inputs.core-image-tag }}
32-
runs-on: [self-hosted]
28+
namespace: ${{ inputs.namespace }}
29+
runs-on:
30+
- self-hosted
3331
steps:
34-
# FYI: Repository is needed only due to single file: infrastructure/dev/dependenciess/values.yaml
35-
- name: Checkout repo
36-
uses: actions/checkout@v4
37-
- name: Update k8s-env/opencrvs/values.yaml
38-
run: |
39-
sed -i -e "s#{{STACK}}#${ENV}#g" k8s-env/opencrvs/values.yaml
32+
- name: Get helm release values
33+
run: helm get values opencrvs -n ${namespace} > ${namespace}.yaml
4034
- name: Cleanup environment
4135
run: |
42-
kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true data-cleanup
43-
helm template -f k8s-env/opencrvs/values.yaml \
36+
kubectl delete job -n ${namespace} --ignore-not-found=true data-cleanup
37+
helm template -f ${namespace}.yaml \
4438
--set data_cleanup.enabled=true \
45-
--set image.tag="$CORE_IMAGE_TAG" \
46-
--namespace opencrvs-${ENV} \
39+
--namespace ${namespace} \
4740
-s templates/data-cleanup-job.yaml \
48-
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f -
41+
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -
4942
sleep 30;
50-
kubectl logs job/data-cleanup -f --all-containers=true -n opencrvs-${ENV} || true
51-
kubectl wait --for=condition=complete job/data-cleanup -n opencrvs-${ENV} --timeout=600s;
52-
kubectl delete pod -n opencrvs-${ENV} -lapp=events;
53-
kubectl wait --for=condition=ready pod -n opencrvs-${ENV} -lapp=events;
43+
kubectl logs job/data-cleanup -f --all-containers=true -n ${namespace} || true
44+
kubectl wait --for=condition=complete job/data-cleanup -n ${namespace} --timeout=600s;
45+
kubectl delete pod -n ${namespace} -lapp=events;
46+
kubectl wait --for=condition=ready pod -n ${namespace} -lapp=events;
5447
- name: Re-run postgres on-deploy
5548
run: |
56-
kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true postgres-on-deploy;
57-
helm template -f k8s-env/opencrvs/values.yaml \
49+
kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-deploy;
50+
helm template -f ${namespace}.yaml \
5851
-s templates/postgres-on-update.yaml \
59-
--set image.tag="$CORE_IMAGE_TAG" \
60-
--namespace opencrvs-${ENV} \
61-
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f -;
52+
--namespace ${namespace} \
53+
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -;
6254
sleep 30;
63-
kubectl logs job/postgres-on-deploy -f --all-containers=true -n opencrvs-${ENV};
64-
kubectl wait --for=condition=complete job/postgres-on-deploy -n opencrvs-${ENV} --timeout=600s;
55+
kubectl logs job/postgres-on-deploy -f --all-containers=true -n ${namespace};
56+
kubectl wait --for=condition=complete job/postgres-on-deploy -n ${namespace} --timeout=600s;
6557
- name: Migration
6658
run: |
67-
kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true data-migration
68-
helm template -f k8s-env/opencrvs/values.yaml \
59+
kubectl delete job -n ${namespace} --ignore-not-found=true data-migration
60+
helm template -f ${namespace}.yaml \
6961
-s templates/data-migration-job.yaml \
70-
--set image.tag="$CORE_IMAGE_TAG" \
71-
--namespace opencrvs-${ENV} \
72-
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f -
62+
--namespace ${namespace} \
63+
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -
7364
sleep 30;
74-
kubectl logs job/data-migration -f -n opencrvs-${ENV} || true
75-
kubectl wait --for=condition=complete job/data-migration -n opencrvs-${ENV} --timeout=600s;
65+
kubectl logs job/data-migration -f -n ${namespace} || true
66+
kubectl wait --for=condition=complete job/data-migration -n ${namespace} --timeout=600s;
7667
- name: Re-run postgres on-deploy
7768
run: |
78-
kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true postgres-on-deploy;
79-
helm template -f k8s-env/opencrvs/values.yaml \
69+
kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-deploy;
70+
helm template -f ${namespace}.yaml \
8071
-s templates/postgres-on-update.yaml \
81-
--set image.tag="$CORE_IMAGE_TAG" \
82-
--namespace opencrvs-${ENV} \
83-
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f -;
72+
--namespace ${namespace} \
73+
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -;
8474
sleep 30;
85-
kubectl logs job/postgres-on-deploy -f --all-containers=true -n opencrvs-${ENV};
86-
kubectl wait --for=condition=complete job/postgres-on-deploy -n opencrvs-${ENV} --timeout=600s;
75+
kubectl logs job/postgres-on-deploy -f --all-containers=true -n ${namespace};
76+
kubectl wait --for=condition=complete job/postgres-on-deploy -n ${namespace} --timeout=600s;
8777
- name: Seeding data
8878
run: |
89-
kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true data-seed
90-
kubectl delete pod -n opencrvs-${ENV} -lapp=events;
91-
kubectl wait --for=condition=ready pod -n opencrvs-${ENV} -lapp=events;
92-
helm template -f k8s-env/opencrvs/values.yaml \
79+
kubectl delete job -n ${namespace} --ignore-not-found=true data-seed
80+
kubectl delete pod -n ${namespace} -lapp=events;
81+
kubectl wait --for=condition=ready pod -n ${namespace} -lapp=events;
82+
helm template -f ${namespace}.yaml \
9383
--set data_seed.enabled=true \
94-
--set image.tag="$CORE_IMAGE_TAG" \
95-
--namespace opencrvs-${ENV} \
84+
--namespace ${namespace} \
9685
-s templates/data-seed-job.yaml \
97-
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait -f -
86+
oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait -f -
9887
sleep 30;
99-
kubectl logs job/data-seed -f -n opencrvs-${ENV} || true
100-
kubectl wait --for=condition=complete job/data-seed -n opencrvs-${ENV} --timeout=600s;
101-
kubectl delete pod -n opencrvs-${ENV} -lapp=events;
88+
kubectl logs job/data-seed -f -n ${namespace} || true
89+
kubectl wait --for=condition=complete job/data-seed -n ${namespace} --timeout=600s;
90+
kubectl delete pod -n ${namespace} -lapp=events;

.github/workflows/k8s-seed-data.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
name: Seed data (k8s)
2-
run-name: Seed data to ${{ inputs.environment }} core=${{ inputs.core-image-tag }}
2+
run-name: Seed data to ${{ inputs.environment }}
33
on:
44
workflow_dispatch:
5-
inputs:
6-
core-image-tag:
7-
description: "Core image tag"
8-
required: true
9-
default: "develop"
10-
type: string
5+
inputs:
116
environment:
127
description: "Target environment"
138
required: true
@@ -18,9 +13,7 @@ on:
1813
environment:
1914
required: true
2015
type: string
21-
core-image-tag:
22-
required: true
23-
type: string
16+
2417
jobs:
2518
seed:
2619
env:

0 commit comments

Comments
 (0)