From ba3af31ca3e42bbb30a3736575e062432f62a98d Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:21:40 +0200 Subject: [PATCH 01/13] setup policy files and add to kustomization --- .github/workflows/preview-deploy.yml | 67 ++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 500d030..08ab1e0 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -52,10 +52,12 @@ jobs: echo "configmap_name=$configmap_name" >> $GITHUB_OUTPUT shell: bash - - name: Update the apps in deployment file and service file with branch names + - name: Update the apps in deployment, service, backend_policy & health_check_policy files with branch names run: |- sed -i "s/branch-name/$preview_branch_name/g" "preview_deploy/deployment.yaml" sed -i "s/branch-name/$preview_branch_name/g" "preview_deploy/service.yaml" + sed -i "s/branch-name/$preview_branch_name/g" "preview_deploy/backend_policy.yaml" + sed -i "s/branch-name/$preview_branch_name/g" "preview_deploy/health_check_policy.yaml" env: preview_branch_name: ${{ inputs.preview_branch_name }} shell: bash @@ -67,7 +69,7 @@ jobs: current_configmap_name: ${{ steps.get_configmap.outputs.configmap_name }} shell: bash - - name: Update the image tag in deploymet file + - name: Update the image tag in deployment file run: |- sed -i "s/tag-name/$image_tag/g" "preview_deploy/deployment.yaml" env: @@ -88,6 +90,22 @@ jobs: path: preview_deploy/service.yaml - name: Echo service file run: echo "${{ steps.service_file.outputs.content }}" + shell: bash + - name: Read backend policy file + id: backend_policy_file + uses: juliangruber/read-file-action@v1 + with: + path: preview_deploy/backend_policy.yaml + - name: Echo backend policy file + run: echo "${{ steps.backend_policy_file.outputs.content }}" + shell: bash + - name: Read health check policy file + id: health_check_policy_file + uses: juliangruber/read-file-action@v1 + with: + path: preview_deploy/health_check_policy.yaml + - name: Echo health check policy file + run: echo "${{ steps.health_check_policy_file.outputs.content }}" shell: bash - name: "Checkout dashboard-frontend k8s manifests" uses: actions/checkout@v3 @@ -100,13 +118,21 @@ jobs: cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} touch $preview_branch_name-deployment.yaml touch $preview_branch_name-service.yaml + touch $preview_branch_name-backend_policy.yaml + touch $preview_branch_name-health_check_policy.yaml cat /dev/null > $preview_branch_name-deployment.yaml cat /dev/null > $preview_branch_name-service.yaml + cat /dev/null > $preview_branch_name-backend_policy.yaml + cat /dev/null > $preview_branch_name-health_check_policy.yaml echo -e "$deployment_file" >> $preview_branch_name-deployment.yaml echo -e "$service_file" >> $preview_branch_name-service.yaml + echo -e "$backend_policy_file" >> $preview_branch_name-backend_policy.yaml + echo -e "$health_check_policy_file" >> $preview_branch_name-health_check_policy.yaml env: service_file: ${{ steps.service_file.outputs.content }} deployment_file: ${{ steps.deployment_file.outputs.content }} + backend_policy_file: ${{ steps.backend_policy_file.outputs.content }} + health_check_policy_file: ${{ steps.health_check_policy_file.outputs.content }} preview_branch_name: ${{ inputs.preview_branch_name }} K8S_ENV_NAME: development shell: bash @@ -126,26 +152,51 @@ jobs: preview_service_file=$preview_branch_name-service.yaml yq -i '.resources += env(preview_service_file)' kustomization.yaml else echo "Entries found for $preview_branch_name-service.yaml. No action required." + fi + check_backend_policy_file=$(preview_backend_policy_file=$preview_branch_name-backend_policy.yaml yq '(.resources[] | select (test(env(preview_backend_policy_file)))' kustomization.yaml) + if [[ -z $check_backend_policy_file ]];then + echo "Entries Not found for $preview_branch_name-backend_policy.yaml. Adding Entry for $preview_branch_name-backend_policy.yaml." + preview_backend_policy_file=$preview_branch_name-backend_policy.yaml yq -i '.resources += env(preview_backend_policy_file)' kustomization.yaml + else + echo "Entries found for $preview_branch_name-backend_policy.yaml. No action required." + fi + check_health_check_policy_file=$(preview_health_check_policy_file=$preview_branch_name-health_check_policy.yaml yq '(.resources[] | select (test(env(preview_health_check_policy_file)))' kustomization.yaml) + if [[ -z $check_health_check_policy_file ]];then + echo "Entries Not found for $preview_branch_name-health_check_policy.yaml. Adding Entry for $preview_branch_name-health_check_policy.yaml." + preview_health_check_policy_file=$preview_branch_name-health_check_policy.yaml yq -i '.resources += env(preview_health_check_policy_file)' kustomization.yaml + else + echo "Entries found for $preview_branch_name-health_check_policy.yaml. No action required." fi env: K8S_ENV_NAME: development preview_branch_name: ${{ inputs.preview_branch_name }} shell: bash - - - name: Update the ingress file of the preview environment path + + - name: Update the ingress and http-route files of the preview environment path run: |- cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} preview_path=$preview_branch_name - check_path=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' ingress-patch.yaml) - if [[ -z $check_path ]]; then + check_path_ingress=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' ingress-patch.yaml) + if [[ -z $check_path_ingress ]]; then echo "No Entries found /$preview_branch_name in ingress path. Adding the required path." preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0].http.paths +=[{"path":env(preview_path),"pathType": "Prefix","backend": {"service": {"name":env(preview_service),"port":{"number":3000}}}}]' ingress-patch.yaml else echo "Entries found for /$preview_branch_name in path ingress.yaml. No action required." - fi + fi + + check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) + if [[ -z $check_path_route ]]; then + echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." + preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0].matches += [{"path": {"type": "PathPrefix", "value": "/"}, "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000}]}]' http_route.yaml + else + echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." + fi + git config --local user.email "86783263+ultimateai-bot@users.noreply.github.com" git add $preview_branch_name-deployment.yaml git add $preview_branch_name-service.yaml + git add $preview_branch_name-backend_policy.yaml + git add $preview_branch_name-health_check_policy.yaml git config --local user.name "ultimateai-bot" git commit -m "Adding $preview_branch_name-deployment.yaml file with ${IMAGE_NAME}:${TAGS} & $preview_branch_name-service.yaml file" -a git push ${REMOTE_REPO} HEAD:main --force @@ -154,4 +205,4 @@ jobs: K8S_ENV_NAME: development preview_branch_name: ${{ inputs.preview_branch_name }} TAGS: ${{ inputs.image_tag }} - shell: bash \ No newline at end of file + shell: bash \ No newline at end of file From 66ff5860c76cf7627be0ef1cf6b51455e82d2733 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:07:02 +0200 Subject: [PATCH 02/13] modify query to update http_route file --- .github/workflows/preview-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 08ab1e0..36be5f2 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -187,7 +187,7 @@ jobs: check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0].matches += [{"path": {"type": "PathPrefix", "value": "/"}, "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000}]}]' http_route.yaml + preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules[0] += [{"matches":[{"path": {"type": "PathPrefix", "value": env(preview_path)}}], "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000}]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi From c24ac8bd5ca05bfcf806d252571e79e3203abf19 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:59:18 +0200 Subject: [PATCH 03/13] amend http_route shell command --- .github/workflows/preview-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 36be5f2..1fff240 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -187,7 +187,7 @@ jobs: check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules[0] += [{"matches":[{"path": {"type": "PathPrefix", "value": env(preview_path)}}], "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000}]}]' http_route.yaml + preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0] += [{"matches":[{"path": {"type": "PathPrefix", "value": env(preview_path)}}], "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000}]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi From 6fcb7f85863ba24cfb0f65592cd0a97c61dc62a5 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:43:31 +0200 Subject: [PATCH 04/13] fix index out of range error --- .github/workflows/preview-deploy.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 1fff240..84219bf 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -187,7 +187,10 @@ jobs: check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0] += [{"matches":[{"path": {"type": "PathPrefix", "value": env(preview_path)}}], "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000}]}]' http_route.yaml + preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i ' + .spec.rules |= (if . == null then [] else . end) | + .spec.rules[0] |= (if . == null then {} else . end) | + .spec.rules.[0] += [{"matches":[{"path": {"type": "PathPrefix", "value": env(preview_path)}}], "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000}]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi From 295acd78f4f8d25ad5897336177276cdae870614 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:24:06 +0200 Subject: [PATCH 05/13] fix parsing error --- .github/workflows/preview-deploy.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 84219bf..df01d75 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -187,10 +187,7 @@ jobs: check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i ' - .spec.rules |= (if . == null then [] else . end) | - .spec.rules[0] |= (if . == null then {} else . end) | - .spec.rules.[0] += [{"matches":[{"path": {"type": "PathPrefix", "value": env(preview_path)}}], "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000}]}]' http_route.yaml + preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules |= (if . == null then [] else . end) | .spec.rules[0] |= (if . == null then {} else . end) | .spec.rules[0] += [{"matches":[{"path": {"type": "PathPrefix", "value": env(preview_path)}}], "backendRefs": [{"kind": "Service", "name": strenv(preview_service), "port": 3000}]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi From a4c27910bb8884cec9706087fc9c33ab478796c7 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:48:40 +0200 Subject: [PATCH 06/13] fix parsing error --- .github/workflows/preview-deploy.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index df01d75..4c791e3 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -187,11 +187,10 @@ jobs: check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules |= (if . == null then [] else . end) | .spec.rules[0] |= (if . == null then {} else . end) | .spec.rules[0] += [{"matches":[{"path": {"type": "PathPrefix", "value": env(preview_path)}}], "backendRefs": [{"kind": "Service", "name": strenv(preview_service), "port": 3000}]}]' http_route.yaml + preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules |= (if . == null then [] else . end) | .spec.rules[0] |= (if . == null then {} else . end) | .spec.rules[0] += [{"matches":[{"path": {"type": "PathPrefix", "value":strenv(preview_path)}}], "backendRefs": [{"kind": "Service", "name":strenv(preview_service), "port": 3000}]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi - git config --local user.email "86783263+ultimateai-bot@users.noreply.github.com" git add $preview_branch_name-deployment.yaml git add $preview_branch_name-service.yaml From 741245eb340ac9e29ad9d0320a65d81c15c1fbf6 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:05:00 +0200 Subject: [PATCH 07/13] fix parsing error --- .github/workflows/preview-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 4c791e3..25d0639 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -187,7 +187,7 @@ jobs: check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules |= (if . == null then [] else . end) | .spec.rules[0] |= (if . == null then {} else . end) | .spec.rules[0] += [{"matches":[{"path": {"type": "PathPrefix", "value":strenv(preview_path)}}], "backendRefs": [{"kind": "Service", "name":strenv(preview_service), "port": 3000}]}]' http_route.yaml + preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0] += [{"matches": ["path":{"type": "PathPrefix", "value": env(preview_path)}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi From d35b2947cb75a23fbac24b96794429f4a629f5e9 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:17:28 +0200 Subject: [PATCH 08/13] fix parsing error --- .github/workflows/preview-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 25d0639..5f1df3b 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -187,7 +187,7 @@ jobs: check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0] += [{"matches": ["path":{"type": "PathPrefix", "value": env(preview_path)}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml + preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi From 290b8db98efd1d82f6685556815ce0235eef1710 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:52:50 +0200 Subject: [PATCH 09/13] update preview path --- .github/workflows/preview-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 5f1df3b..e415f66 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -187,7 +187,7 @@ jobs: check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml + preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi From e944d1bb7634a6c83e1e439e687c10a8a2e81b27 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:27:52 +0200 Subject: [PATCH 10/13] disable ingress_patch update due to gateway migration --- .github/workflows/preview-deploy.yml | 34 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index e415f66..4e339f0 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -171,19 +171,35 @@ jobs: K8S_ENV_NAME: development preview_branch_name: ${{ inputs.preview_branch_name }} shell: bash + + # - name: Update the ingress file of the preview environment path + # run: |- + # cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} + # preview_path=$preview_branch_name + # check_path=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' ingress-patch.yaml) + # if [[ -z $check_path ]]; then + # echo "No Entries found /$preview_branch_name in ingress path. Adding the required path." + # preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0].http.paths +=[{"path":env(preview_path),"pathType": "Prefix","backend": {"service": {"name":env(preview_service),"port":{"number":3000}}}}]' ingress-patch.yaml + # else + # echo "Entries found for /$preview_branch_name in path ingress.yaml. No action required." + # fi + # git config --local user.email "86783263+ultimateai-bot@users.noreply.github.com" + # git add $preview_branch_name-deployment.yaml + # git add $preview_branch_name-service.yaml + # git config --local user.name "ultimateai-bot" + # git commit -m "Adding $preview_branch_name-deployment.yaml file with ${IMAGE_NAME}:${TAGS} & $preview_branch_name-service.yaml file" -a + # git push ${REMOTE_REPO} HEAD:main --force + # env: + # REMOTE_REPO: https://${{ secrets.repo_token }}@github.com/ultimateai/k8s-manifests.git + # K8S_ENV_NAME: development + # preview_branch_name: ${{ inputs.preview_branch_name }} + # TAGS: ${{ inputs.image_tag }} + # shell: bash - - name: Update the ingress and http-route files of the preview environment path + - name: Update the http-route file of the preview environment path run: |- cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} preview_path=$preview_branch_name - check_path_ingress=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' ingress-patch.yaml) - if [[ -z $check_path_ingress ]]; then - echo "No Entries found /$preview_branch_name in ingress path. Adding the required path." - preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0].http.paths +=[{"path":env(preview_path),"pathType": "Prefix","backend": {"service": {"name":env(preview_service),"port":{"number":3000}}}}]' ingress-patch.yaml - else - echo "Entries found for /$preview_branch_name in path ingress.yaml. No action required." - fi - check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." From d92ffddd67a38aca4c78139954bf84dab057213b Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:57:54 +0200 Subject: [PATCH 11/13] modify the check_path query --- .github/workflows/preview-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 4e339f0..55a0a95 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -200,7 +200,7 @@ jobs: run: |- cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} preview_path=$preview_branch_name - check_path_route=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' http_route.yaml) + check_path_route=$(yq '.. | select(has("value")) | select (.value == "*'$preview_path'")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml From 6e1c2e8848c92d6cefe6602281e89b359b18d2f4 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:20:33 +0200 Subject: [PATCH 12/13] cleanup of policy files for preview env --- .github/workflows/preview-cleanup.yml | 56 ++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/.github/workflows/preview-cleanup.yml b/.github/workflows/preview-cleanup.yml index 2e0b601..efb98fc 100644 --- a/.github/workflows/preview-cleanup.yml +++ b/.github/workflows/preview-cleanup.yml @@ -29,6 +29,8 @@ jobs: cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} rm -f $preview_branch_name-deployment.yaml rm -f $preview_branch_name-service.yaml + rm -f $preview_branch_name-backend_policy.yaml + rm -f $preview_branch_name-health_check_policy.yaml env: preview_branch_name: ${{inputs.preview_branch_name}} K8S_ENV_NAME: development @@ -50,22 +52,52 @@ jobs: else echo "Entries found for $preview_branch_name-service.yaml. Executing Cleanup" sed -i "/$preview_branch_name-service.yaml/d" kustomization.yaml + fi + check_backend_policy_file=$(preview_backend_policy_file=$preview_branch_name-backend_policy.yaml yq '(.resources[] | select (test(env(preview_backend_policy_file)))' kustomization.yaml) + if [[ -z $check_backend_policy_file ]];then + echo "No entries found for $preview_branch_name-backend_policy.yaml." + else + echo "Entries found for $preview_branch_name-backend_policy.yaml. Executing Cleanup" + sed -i "/$preview_branch_name-backend_policy.yaml/d" kustomization.yaml + fi + check_health_check_policy_file=$(preview_health_check_policy_file=$preview_branch_name-health_check_policy.yaml yq '(.resources[] | select (test(env(preview_health_check_policy_file)))' kustomization.yaml) + if [[ -z $check_health_check_policy_file ]];then + echo "No entries found for $preview_branch_name-health_check_policy.yaml." + else + echo "Entries found for $preview_branch_name-health_check_policy.yaml. Executing Cleanup" + sed -i "/$preview_branch_name-health_check_policy.yaml/d" kustomization.yaml fi env: K8S_ENV_NAME: development preview_branch_name: ${{inputs.preview_branch_name}} shell: bash - - name: Remove the preview path from ingress file + # - name: Remove the preview path from ingress file + # run: |- + # cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} + # preview_path=$preview_branch_name + # check_path=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' ingress-patch.yaml) + # if [[ -z $check_path ]]; then + # echo "No Entries found /$preview_branch_name in ingress path no action required" + # else + # echo "Entries found for /$preview_branch_name in path ingress.yaml. Doing the clean up" + # preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0].http.paths -=[{"path":env(preview_path),"pathType": "Prefix","backend": {"service": {"name":env(preview_service),"port":{"number":3000}}}}]' ingress-patch.yaml + # fi + # env: + # K8S_ENV_NAME: development + # preview_branch_name: ${{inputs.preview_branch_name}} + # shell: bash + + - name: Remove the preview path from http_route file run: |- cd frontend/dashboard-frontend/overlay/${K8S_ENV_NAME} preview_path=$preview_branch_name - check_path=$(yq '.. | select(has("path")) | select (.path == "*'$preview_path'*")' ingress-patch.yaml) - if [[ -z $check_path ]]; then - echo "No Entries found /$preview_branch_name in ingress path no action required" + check_path_route=$(yq '.. | select(has("value")) | select (.value == "*'$preview_path'")' http_route.yaml) + if [[ -z $check_path_route ]]; then + echo "No Entries found /$preview_branch_name in http_route path, no action required" else - echo "Entries found for /$preview_branch_name in path ingress.yaml. Doing the clean up" - preview_path=/$preview_branch_name/.* preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules.[0].http.paths -=[{"path":env(preview_path),"pathType": "Prefix","backend": {"service": {"name":env(preview_service),"port":{"number":3000}}}}]' ingress-patch.yaml + echo "Entries found for /$preview_branch_name in path http_route.yaml. Doing the clean up" + preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml fi env: K8S_ENV_NAME: development @@ -88,6 +120,18 @@ jobs: else echo "File $preview_branch_name-service.yaml not found. No action required." fi + if [ -e $preview_branch_name-backend_policy.yaml ]; then + echo "File $preview_branch_name-backend_policy.yaml found. Executing git rm for $preview_branch_name-backend_policy.yaml." + git rm $preview_branch_name-backend_policy.yaml + else + echo "File $preview_branch_name-backend_policy.yaml not found. No action required." + fi + if [ -e $preview_branch_name-health_check_policy.yaml ]; then + echo "File $preview_branch_name-health_check_policy.yaml found. Executing git rm for $preview_branch_name-health_check_policy.yaml." + git rm $preview_branch_name-health_check_policy.yaml + else + echo "File $preview_branch_name-health_check_policy.yaml not found. No action required." + fi git config --local user.name "ultimateai-bot" git commit -m "Doing the clean up for Preview Env for ${preview_branch_name}" -a || echo "Nothing to commit for ${preview_branch_name}, already cleaned!" >> $GITHUB_STEP_SUMMARY git push ${REMOTE_REPO} HEAD:main --force From 66c2cecd1e5538d6a3f99e25222543a7a8ef1422 Mon Sep 17 00:00:00 2001 From: Adekunle Johnson <68116479+kunle-johnson@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:48:11 +0200 Subject: [PATCH 13/13] correct typo --- .github/workflows/preview-cleanup.yml | 2 +- .github/workflows/preview-deploy.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-cleanup.yml b/.github/workflows/preview-cleanup.yml index efb98fc..6779a86 100644 --- a/.github/workflows/preview-cleanup.yml +++ b/.github/workflows/preview-cleanup.yml @@ -97,7 +97,7 @@ jobs: echo "No Entries found /$preview_branch_name in http_route path, no action required" else echo "Entries found for /$preview_branch_name in path http_route.yaml. Doing the clean up" - preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml + preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml fi env: K8S_ENV_NAME: development diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.yml index 55a0a95..6b46b1a 100644 --- a/.github/workflows/preview-deploy.yml +++ b/.github/workflows/preview-deploy.yml @@ -203,7 +203,7 @@ jobs: check_path_route=$(yq '.. | select(has("value")) | select (.value == "*'$preview_path'")' http_route.yaml) if [[ -z $check_path_route ]]; then echo "No Entries found /$preview_branch_name in http_route path. Adding the required path." - preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Sevice", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml + preview_path=/$preview_branch_name preview_service=dashboard-frontend-dev-$preview_branch_name-service yq -i '.spec.rules += [{"matches": [{"path":{"type": "PathPrefix", "value": env(preview_path)}}] , "backendRefs": [{"kind": "Service", "name": env(preview_service), "port": 3000 }]}]' http_route.yaml else echo "Entries found for /$preview_branch_name in path http_route.yaml. No action required." fi