From d84e27dc56cf0a1f43db0cf2a36b999bb43ab9ce Mon Sep 17 00:00:00 2001 From: Renat Gofman Date: Mon, 11 Jul 2022 03:58:47 -0700 Subject: [PATCH 1/8] add ci envs --- .github/workflows/deploy-k8s.yml | 6 +++++- .github/workflows/init.yml | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-k8s.yml b/.github/workflows/deploy-k8s.yml index 92ad1d2..52bcf23 100644 --- a/.github/workflows/deploy-k8s.yml +++ b/.github/workflows/deploy-k8s.yml @@ -4,6 +4,9 @@ on: KUBE_NAMESPACE: required: true type: string + ci_env: + required: true + type: string aws_region: required: true type: string @@ -61,7 +64,8 @@ jobs: shell: bash run: | cat .github/workflows/ci-properties.json - for i in `cat .github/workflows/ci-properties.json | jq -r .APP_ENV_VARS | jq -r 'keys[]'`; do params="${params} --from-literal=$i=$(cat .github/workflows/ci-properties.json | jq -r .APP_ENV_VARS.$i)"; done + for i in `cat .github/workflows/ci-properties.json | jq -r .APP_ENV_VARS | jq -r 'keys[]' || true`; do params="${params} --from-literal=$i=$(cat .github/workflows/ci-properties.json | jq -r .APP_ENV_VARS.$i)"; done + for i in `cat .github/workflows/ci-properties.json | jq -r .${{inputs.ci_env}}_ENV_VARS | jq -r 'keys[]' || true`; do params="${params} --from-literal=$i=$(cat .github/workflows/ci-properties.json | jq -r .${{inputs.ci_env}}_ENV_VARS.$i)"; done echo "ENV VARS from ci-properties.json: $params" echo "::set-output name=k8sparams::$params" diff --git a/.github/workflows/init.yml b/.github/workflows/init.yml index 53a61a9..789cb12 100644 --- a/.github/workflows/init.yml +++ b/.github/workflows/init.yml @@ -11,6 +11,8 @@ on: outputs: KUBE_NAMESPACE: value: ${{ jobs.init.outputs.k8s_namespace }} + ci_env: + value: ${{ jobs.init.outputs.ci_env }} image_name: value: ${{ jobs.init.outputs.image_name }} registry: @@ -53,9 +55,11 @@ jobs: run: | if [[ "${{ inputs.base_ref }}" == "${{ env.prod_branch }}" || "${{ inputs.ref }}" == "refs/heads/${{ env.prod_branch }}" ]]; then echo "::set-output name=k8s_namespace::production" + echo "::set-output name=ci_env::PROD" fi if [[ "${{ inputs.base_ref }}" == "${{ env.dev_branch }}" || "${{ inputs.ref }}" == "refs/heads/${{ env.dev_branch }}" ]]; then echo "::set-output name=k8s_namespace::test" + echo "::set-output name=ci_env::DEV" fi echo "::set-output name=image_name::${{ env.image_name }}" echo "::set-output name=registry::${{ env.registry }}" From 8ae66b5604fd66c911fe2d0d98a3fded7a65a693 Mon Sep 17 00:00:00 2001 From: Renat Gofman Date: Mon, 11 Jul 2022 04:24:57 -0700 Subject: [PATCH 2/8] add ci envs --- .github/workflows/init.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/init.yml b/.github/workflows/init.yml index 789cb12..4bf4668 100644 --- a/.github/workflows/init.yml +++ b/.github/workflows/init.yml @@ -45,7 +45,7 @@ jobs: shell: bash run: | for i in `cat .github/workflows/ci-properties.json | jq -r 'keys[]'`; do - if [[ $i != "APP_ENV_VARS" ]]; then + if [[ $i != "APP_ENV_VARS" && $i != "DEV_ENV_VARS" && $i != "PROD_ENV_VARS"]]; then echo "$i=$( cat .github/workflows/ci-properties.json | jq -r .$i)" >> $GITHUB_ENV fi done; From 6872388b9ce6bcb90f63356e4c03aabb8ca1f9c2 Mon Sep 17 00:00:00 2001 From: Renat Gofman Date: Mon, 11 Jul 2022 04:27:33 -0700 Subject: [PATCH 3/8] add ci envs --- .github/workflows/init.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/init.yml b/.github/workflows/init.yml index 4bf4668..5914445 100644 --- a/.github/workflows/init.yml +++ b/.github/workflows/init.yml @@ -45,8 +45,8 @@ jobs: shell: bash run: | for i in `cat .github/workflows/ci-properties.json | jq -r 'keys[]'`; do - if [[ $i != "APP_ENV_VARS" && $i != "DEV_ENV_VARS" && $i != "PROD_ENV_VARS"]]; then - echo "$i=$( cat .github/workflows/ci-properties.json | jq -r .$i)" >> $GITHUB_ENV + if [[ $i != "APP_ENV_VARS" & $i != "DEV_ENV_VARS" & $i != "PROD_ENV_VARS"]]; then + echo "$i=$( cat .github/workflows/ci-properties.json | jq -r .$i)" >> $GITHUB_ENV fi done; From 34f71e90cec35c0f4e268a56ede3e874bfd6ec61 Mon Sep 17 00:00:00 2001 From: Renat Gofman Date: Mon, 11 Jul 2022 04:29:41 -0700 Subject: [PATCH 4/8] add ci envs --- .github/workflows/init.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/init.yml b/.github/workflows/init.yml index 5914445..b51c804 100644 --- a/.github/workflows/init.yml +++ b/.github/workflows/init.yml @@ -45,7 +45,7 @@ jobs: shell: bash run: | for i in `cat .github/workflows/ci-properties.json | jq -r 'keys[]'`; do - if [[ $i != "APP_ENV_VARS" & $i != "DEV_ENV_VARS" & $i != "PROD_ENV_VARS"]]; then + if [[ $i != "APP_ENV_VARS" && $i != "DEV_ENV_VARS" && $i != "PROD_ENV_VARS" ]]; then echo "$i=$( cat .github/workflows/ci-properties.json | jq -r .$i)" >> $GITHUB_ENV fi done; From ab77a8d3628d714241baa74197008721bfa3e473 Mon Sep 17 00:00:00 2001 From: Renat Gofman Date: Mon, 11 Jul 2022 04:38:13 -0700 Subject: [PATCH 5/8] add ci envs --- .github/workflows/deploy-k8s.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-k8s.yml b/.github/workflows/deploy-k8s.yml index 52bcf23..83847c9 100644 --- a/.github/workflows/deploy-k8s.yml +++ b/.github/workflows/deploy-k8s.yml @@ -65,7 +65,8 @@ jobs: run: | cat .github/workflows/ci-properties.json for i in `cat .github/workflows/ci-properties.json | jq -r .APP_ENV_VARS | jq -r 'keys[]' || true`; do params="${params} --from-literal=$i=$(cat .github/workflows/ci-properties.json | jq -r .APP_ENV_VARS.$i)"; done - for i in `cat .github/workflows/ci-properties.json | jq -r .${{inputs.ci_env}}_ENV_VARS | jq -r 'keys[]' || true`; do params="${params} --from-literal=$i=$(cat .github/workflows/ci-properties.json | jq -r .${{inputs.ci_env}}_ENV_VARS.$i)"; done + echo "result: `cat .github/workflows/ci-properties.json | jq -r .${{ inputs.ci_env }}_ENV_VARS`" + for i in `cat .github/workflows/ci-properties.json | jq -r .${{ inputs.ci_env }}_ENV_VARS | jq -r 'keys[]' || true`; do params="${params} --from-literal=$i=$(cat .github/workflows/ci-properties.json | jq -r .${{ inputs.ci_env }}_ENV_VARS.$i)"; done echo "ENV VARS from ci-properties.json: $params" echo "::set-output name=k8sparams::$params" From 36b7c3deffdb6367dcae5222b08dea1d3064fa28 Mon Sep 17 00:00:00 2001 From: Renat Gofman Date: Mon, 11 Jul 2022 04:46:18 -0700 Subject: [PATCH 6/8] add ci envs --- .github/workflows/deploy-k8s.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-k8s.yml b/.github/workflows/deploy-k8s.yml index 83847c9..9d7e2a8 100644 --- a/.github/workflows/deploy-k8s.yml +++ b/.github/workflows/deploy-k8s.yml @@ -65,7 +65,7 @@ jobs: run: | cat .github/workflows/ci-properties.json for i in `cat .github/workflows/ci-properties.json | jq -r .APP_ENV_VARS | jq -r 'keys[]' || true`; do params="${params} --from-literal=$i=$(cat .github/workflows/ci-properties.json | jq -r .APP_ENV_VARS.$i)"; done - echo "result: `cat .github/workflows/ci-properties.json | jq -r .${{ inputs.ci_env }}_ENV_VARS`" + echo "result: ${{ inputs.ci_env }}_ENV_VARS" for i in `cat .github/workflows/ci-properties.json | jq -r .${{ inputs.ci_env }}_ENV_VARS | jq -r 'keys[]' || true`; do params="${params} --from-literal=$i=$(cat .github/workflows/ci-properties.json | jq -r .${{ inputs.ci_env }}_ENV_VARS.$i)"; done echo "ENV VARS from ci-properties.json: $params" echo "::set-output name=k8sparams::$params" From 13d5cdaba30ef801fbe97f7774a6c8f0894949fc Mon Sep 17 00:00:00 2001 From: Renat Gofman Date: Mon, 11 Jul 2022 04:55:12 -0700 Subject: [PATCH 7/8] add ci envs --- .github/workflows/init.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/init.yml b/.github/workflows/init.yml index b51c804..133422c 100644 --- a/.github/workflows/init.yml +++ b/.github/workflows/init.yml @@ -31,6 +31,7 @@ jobs: runs-on: ubuntu-latest outputs: k8s_namespace: ${{ steps.setvars.outputs.k8s_namespace }} + ci_env: ${{ steps.setvars.outputs.ci_env }} image_name: ${{ steps.setvars.outputs.image_name }} registry: ${{ steps.setvars.outputs.registry }} aws_region: ${{ steps.setvars.outputs.aws_region }} From 90a3cbf9b8a5937e6fc609d00b555e3015dcca46 Mon Sep 17 00:00:00 2001 From: Renat Gofman Date: Tue, 16 Aug 2022 01:49:51 -0700 Subject: [PATCH 8/8] ensure different namespaces running on different CI images --- .github/workflows/deploy-k8s.yml | 8 ++++++++ .github/workflows/docker.yml | 5 ++++- workflow-templates/ci-cd-development.yml | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-k8s.yml b/.github/workflows/deploy-k8s.yml index 9d7e2a8..c8ff0bd 100644 --- a/.github/workflows/deploy-k8s.yml +++ b/.github/workflows/deploy-k8s.yml @@ -1,6 +1,9 @@ on: workflow_call: inputs: + IMAGE_NAME: + required: true + type: string KUBE_NAMESPACE: required: true type: string @@ -84,6 +87,11 @@ jobs: with: args: create secret generic ${{ inputs.app_name }} -n ${{ inputs.KUBE_NAMESPACE }} ${{ steps.genparams.outputs.k8sparams }} --save-config --dry-run=client -o yaml | kubectl apply -f - + - name: Generate k8s secret params + shell: bash + run: | + sed -i 's|image: ${{ inputs.IMAGE_NAME }}|image: ${{ inputs.IMAGE_NAME }}:${{ inputs.KUBE_NAMESPACE }}|' deployment.yaml + - name: kubernets apply config uses: kodermax/kubectl-aws-eks@master env: diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e5a637f..9a6235a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -4,6 +4,9 @@ on: IMAGE_NAME: required: true type: string + KUBE_NAMESPACE: + required: true + type: string event_name: required: true type: string @@ -56,5 +59,5 @@ jobs: context: . file: ${{ inputs.dockerfile_path }}/Dockerfile push: ${{ inputs.event_name != 'pull_request' }} - tags: ${{ inputs.registry }}/${{ inputs.IMAGE_NAME }} + tags: ${{ inputs.registry }}/${{ inputs.IMAGE_NAME }}:${{ inputs.KUBE_NAMESPACE }} labels: ${{ steps.meta.outputs.labels }} diff --git a/workflow-templates/ci-cd-development.yml b/workflow-templates/ci-cd-development.yml index 61b64f0..f144c7d 100644 --- a/workflow-templates/ci-cd-development.yml +++ b/workflow-templates/ci-cd-development.yml @@ -16,6 +16,7 @@ jobs: needs: [call-workflow-init] with: IMAGE_NAME: ${{ needs.call-workflow-init.outputs.image_name }} + KUBE_NAMESPACE: ${{ needs.call-workflow-init.outputs.KUBE_NAMESPACE }} event_name: ${{ github.event_name }} registry: ${{ needs.call-workflow-init.outputs.registry }} dockerfile_path: ${{ needs.call-workflow-init.outputs.dockerfile_path }} @@ -27,6 +28,7 @@ jobs: if: github.event_name != 'pull_request' uses: DistributedCollective/.github/.github/workflows/deploy-k8s.yml@master # in case additional secrets is needed, this file must be changed and pushed to your repository with: + IMAGE_NAME: ${{ needs.call-workflow-init.outputs.image_name }} KUBE_NAMESPACE: ${{ needs.call-workflow-init.outputs.KUBE_NAMESPACE }} aws_region: ${{ needs.call-workflow-init.outputs.aws_region }} k8s_cluster_name: ${{ needs.call-workflow-init.outputs.k8s_cluster_name }}