From 1633e5c23c30a648051c2f0089ad6ae4faa5bd6e Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 13:04:04 +0000 Subject: [PATCH 01/10] Add deploy dir input --- .github/workflows/cd_push.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index 2e94b2e..8c109f3 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -9,6 +9,10 @@ on: argocd_app_name: required: true type: string + deploy_dir: + required: false + type: string + default: "deploy" dockle_whitelist: required: false type: string @@ -67,21 +71,22 @@ jobs: if [ "$GIT_REF" == "development" ]; then echo ::set-output name=server-url::argocd.euc1.t.get-protocol.dev echo ::set-output name=token::$EUC1TESTING_TOKEN - echo ::set-output name=overlay::deploy/overlays/euc1-testing + echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-testing elif [ "$GIT_REF" == "master" ]; then echo ::set-output name=server-url::argocd.euc1.s.get-protocol.dev echo ::set-output name=token::$EUC1STAGING_TOKEN - echo ::set-output name=overlay::deploy/overlays/euc1-staging + echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-staging elif [ "$GIT_REF" == "production" ]; then echo ::set-output name=server-url::argocd.euc1.get-protocol.cloud echo ::set-output name=token::$EUC1_TOKEN - echo ::set-output name=overlay::deploy/overlays/euc1 + echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1 fi env: GIT_REF: ${{ github.ref_name }} EUC1TESTING_TOKEN: ${{ secrets.ARGOCD_EUC1TESTING_API_AUTH }} EUC1STAGING_TOKEN: ${{ secrets.ARGOCD_EUC1STAGING_API_AUTH }} EUC1_TOKEN: ${{ secrets.ARGOCD_EUC1_API_AUTH }} + DEPLOY_DIR: ${{ inputs.deploy_dir }} - name: Generate token id: generate_token From 80382dc65cd4e2bf28b00a44b8740bd26f22849a Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 13:11:40 +0000 Subject: [PATCH 02/10] Temporarily add test branch for gus --- .github/workflows/cd_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index 8c109f3..b761731 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -63,7 +63,7 @@ jobs: concurrency: group: ${{ github.ref }} cancel-in-progress: true - if: github.ref_name == 'development' || github.ref_name == 'master' || github.ref_name == 'production' + if: github.ref_name == 'development' || github.ref_name == 'master' || github.ref_name == 'production' || github.ref_name == 'feature/multiple-clusters' steps: - id: argocd shell: bash From 8e43eadef648b51a75570abfe00fe9b000a63c33 Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 13:16:32 +0000 Subject: [PATCH 03/10] Add test branch to if statement --- .github/workflows/cd_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index b761731..c29437a 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -68,7 +68,7 @@ jobs: - id: argocd shell: bash run: | - if [ "$GIT_REF" == "development" ]; then + if [ "$GIT_REF" == "development" ] || [ "$GIT_REF" == "feature/multiple-clusters" ]; then echo ::set-output name=server-url::argocd.euc1.t.get-protocol.dev echo ::set-output name=token::$EUC1TESTING_TOKEN echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-testing From e7dc3ef802db8370e233731c475e97476fad2c81 Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 13:47:16 +0000 Subject: [PATCH 04/10] Split kustomize and argocd sync --- .github/workflows/cd_push.yml | 63 ++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index c29437a..4d62f26 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -9,10 +9,10 @@ on: argocd_app_name: required: true type: string - deploy_dir: + deploy_dirs: required: false type: string - default: "deploy" + default: '["deploy"]' dockle_whitelist: required: false type: string @@ -57,7 +57,7 @@ jobs: SLACK_WEBHOOK: ${{ secrets.FAILURE_SLACK_WEBHOOK }} SLACK_ICON: https://github.com/GETProtocolLab.png?size=48 - deploy-argocd: + update-kustomize: runs-on: [self-hosted, ubuntu20.04-self] needs: build concurrency: @@ -65,28 +65,18 @@ jobs: cancel-in-progress: true if: github.ref_name == 'development' || github.ref_name == 'master' || github.ref_name == 'production' || github.ref_name == 'feature/multiple-clusters' steps: - - id: argocd + - name: Select overlay shell: bash run: | if [ "$GIT_REF" == "development" ] || [ "$GIT_REF" == "feature/multiple-clusters" ]; then - echo ::set-output name=server-url::argocd.euc1.t.get-protocol.dev - echo ::set-output name=token::$EUC1TESTING_TOKEN - echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-testing + echo ::set-output name=overlay::overlays/euc1-testing elif [ "$GIT_REF" == "master" ]; then - echo ::set-output name=server-url::argocd.euc1.s.get-protocol.dev - echo ::set-output name=token::$EUC1STAGING_TOKEN - echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-staging + echo ::set-output name=overlay::overlays/euc1-staging elif [ "$GIT_REF" == "production" ]; then - echo ::set-output name=server-url::argocd.euc1.get-protocol.cloud - echo ::set-output name=token::$EUC1_TOKEN - echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1 + echo ::set-output name=overlay::overlays/euc1 fi env: GIT_REF: ${{ github.ref_name }} - EUC1TESTING_TOKEN: ${{ secrets.ARGOCD_EUC1TESTING_API_AUTH }} - EUC1STAGING_TOKEN: ${{ secrets.ARGOCD_EUC1STAGING_API_AUTH }} - EUC1_TOKEN: ${{ secrets.ARGOCD_EUC1_API_AUTH }} - DEPLOY_DIR: ${{ inputs.deploy_dir }} - name: Generate token id: generate_token @@ -104,14 +94,17 @@ jobs: - name: Update overlay with new image tag run: | - cd $TARGET - kustomize edit set image $IMAGE=:$TAG - cat kustomization.yml + jq '.[]' -r <<< $DEPLOY_DIRS | while read i; do + cd $i/$TARGET + kustomize edit set image $IMAGE=:$TAG + cat kustomization.yml + done shell: bash env: TARGET: ${{ steps.argocd.outputs.overlay }} IMAGE: ${{ inputs.image }} TAG: ${{ github.sha }} + DEPLOY_DIRS: ${{ inputs.deploy_dirs }} - uses: actionsx/prettier@v2 with: @@ -120,6 +113,36 @@ jobs: - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "[skip ci] Deploy ${{ github.ref_name }} (${{ github.sha }}) to ${{ steps.argocd.outputs.overlay }}" + deploy-argocd: + runs-on: [self-hosted, ubuntu20.04-self] + needs: "update-kustomize" + strategy: + fail-fast: false + matrix: + DEPLOY_DIR: ${{ fromJSON(inputs.deploy_dirs) }} + steps: + - id: argocd + shell: bash + run: | + if [ "$GIT_REF" == "development" ] || [ "$GIT_REF" == "feature/multiple-clusters" ]; then + echo ::set-output name=server-url::argocd.euc1.t.get-protocol.dev + echo ::set-output name=token::$EUC1TESTING_TOKEN + echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-testing + elif [ "$GIT_REF" == "master" ]; then + echo ::set-output name=server-url::argocd.euc1.s.get-protocol.dev + echo ::set-output name=token::$EUC1STAGING_TOKEN + echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-staging + elif [ "$GIT_REF" == "production" ]; then + echo ::set-output name=server-url::argocd.euc1.get-protocol.cloud + echo ::set-output name=token::$EUC1_TOKEN + echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1 + fi + env: + GIT_REF: ${{ github.ref_name }} + EUC1TESTING_TOKEN: ${{ secrets.ARGOCD_EUC1TESTING_API_AUTH }} + EUC1STAGING_TOKEN: ${{ secrets.ARGOCD_EUC1STAGING_API_AUTH }} + EUC1_TOKEN: ${{ secrets.ARGOCD_EUC1_API_AUTH }} + DEPLOY_DIR: ${{ matrix.DEPLOY_DIR }} - run: docker run argoproj/argocd argocd app sync ${{ inputs.argocd_app_name }} --grpc-web --server $SERVER --auth-token $AUTH_TOKEN --prune env: From ced0f0bba9be014c65638dbef986d00518fa38c9 Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 13:55:25 +0000 Subject: [PATCH 05/10] Add id to overlay select step --- .github/workflows/cd_push.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index 4d62f26..ae270b9 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -48,7 +48,7 @@ jobs: uses: rtCamp/action-slack-notify@v2 if: failure() && (github.ref_name == 'development' || github.ref_name == 'master' || github.ref_name == 'production') env: - SLACK_CHANNEL: taas-dev + SLACK_CHANNEL: taas-github SLACK_COLOR: danger SLACK_MESSAGE: | Build job on *${{ github.ref_name }}* has failed for ${{ github.repository }} @@ -65,7 +65,8 @@ jobs: cancel-in-progress: true if: github.ref_name == 'development' || github.ref_name == 'master' || github.ref_name == 'production' || github.ref_name == 'feature/multiple-clusters' steps: - - name: Select overlay + - id: argocd + name: Select overlay shell: bash run: | if [ "$GIT_REF" == "development" ] || [ "$GIT_REF" == "feature/multiple-clusters" ]; then @@ -154,7 +155,7 @@ jobs: uses: rtCamp/action-slack-notify@v2 if: ${{ failure() }} env: - SLACK_CHANNEL: taas-dev + SLACK_CHANNEL: taas-github SLACK_COLOR: danger SLACK_MESSAGE: | Deploy job on *${{ github.ref_name }}* has failed for ${{ github.repository }} From 76a93edcd34ce5f3c10019a31d7a8a56e42e76a0 Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 13:59:52 +0000 Subject: [PATCH 06/10] Add full path to cd --- .github/workflows/cd_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index ae270b9..ff2cd96 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -96,7 +96,7 @@ jobs: - name: Update overlay with new image tag run: | jq '.[]' -r <<< $DEPLOY_DIRS | while read i; do - cd $i/$TARGET + cd $GITHUB_WORKSPACE/$i/$TARGET kustomize edit set image $IMAGE=:$TAG cat kustomization.yml done From 52baef20bcb1353fa10675fb57a3e1b6ed4b2a99 Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 14:19:18 +0000 Subject: [PATCH 07/10] Use npx to run prettier --- .github/workflows/cd_push.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index ff2cd96..9c777b9 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -99,6 +99,7 @@ jobs: cd $GITHUB_WORKSPACE/$i/$TARGET kustomize edit set image $IMAGE=:$TAG cat kustomization.yml + npx prettier --write . done shell: bash env: @@ -107,10 +108,6 @@ jobs: TAG: ${{ github.sha }} DEPLOY_DIRS: ${{ inputs.deploy_dirs }} - - uses: actionsx/prettier@v2 - with: - args: --write ${{ steps.argocd.outputs.overlay }}/kustomization.yml - - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "[skip ci] Deploy ${{ github.ref_name }} (${{ github.sha }}) to ${{ steps.argocd.outputs.overlay }}" From fd4424c7f2311e0279064aa67a1ab6c95424a3c1 Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 14:23:21 +0000 Subject: [PATCH 08/10] Install nodejs --- .github/workflows/cd_push.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index 9c777b9..c1adc24 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -93,6 +93,10 @@ jobs: with: kustomize-version: "4.4.0" + - uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Update overlay with new image tag run: | jq '.[]' -r <<< $DEPLOY_DIRS | while read i; do From 4617fa00975abd10607e59cdbc6c1cd9d4ae3ab8 Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 14:28:51 +0000 Subject: [PATCH 09/10] Use multiple app names --- .github/workflows/cd_push.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index c1adc24..408af30 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -6,7 +6,7 @@ on: image: required: true type: string - argocd_app_name: + argocd_app_names: required: true type: string deploy_dirs: @@ -121,7 +121,7 @@ jobs: strategy: fail-fast: false matrix: - DEPLOY_DIR: ${{ fromJSON(inputs.deploy_dirs) }} + APP_NAME: ${{ fromJSON(inputs.argocd_app_names) }} steps: - id: argocd shell: bash @@ -129,27 +129,24 @@ jobs: if [ "$GIT_REF" == "development" ] || [ "$GIT_REF" == "feature/multiple-clusters" ]; then echo ::set-output name=server-url::argocd.euc1.t.get-protocol.dev echo ::set-output name=token::$EUC1TESTING_TOKEN - echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-testing elif [ "$GIT_REF" == "master" ]; then echo ::set-output name=server-url::argocd.euc1.s.get-protocol.dev echo ::set-output name=token::$EUC1STAGING_TOKEN - echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1-staging elif [ "$GIT_REF" == "production" ]; then echo ::set-output name=server-url::argocd.euc1.get-protocol.cloud echo ::set-output name=token::$EUC1_TOKEN - echo ::set-output name=overlay::$DEPLOY_DIR/overlays/euc1 fi env: GIT_REF: ${{ github.ref_name }} EUC1TESTING_TOKEN: ${{ secrets.ARGOCD_EUC1TESTING_API_AUTH }} EUC1STAGING_TOKEN: ${{ secrets.ARGOCD_EUC1STAGING_API_AUTH }} EUC1_TOKEN: ${{ secrets.ARGOCD_EUC1_API_AUTH }} - DEPLOY_DIR: ${{ matrix.DEPLOY_DIR }} - - run: docker run argoproj/argocd argocd app sync ${{ inputs.argocd_app_name }} --grpc-web --server $SERVER --auth-token $AUTH_TOKEN --prune + - run: docker run argoproj/argocd argocd app sync $APP_NAME --grpc-web --server $SERVER --auth-token $AUTH_TOKEN --prune env: SERVER: ${{ steps.argocd.outputs.server-url }} AUTH_TOKEN: ${{ steps.argocd.outputs.token }} + APP_NAME: ${{ matrix.APP_NAME }} # Only triggers if this job fails - name: Failure Slack Notification From 1ee7cbe76661227b219b6f00ad40d1006af9ff88 Mon Sep 17 00:00:00 2001 From: Mihai Costea Date: Wed, 18 Jan 2023 14:36:39 +0000 Subject: [PATCH 10/10] Remove temp branch from all steps --- .github/workflows/cd_push.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index 408af30..8f2639d 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -63,13 +63,13 @@ jobs: concurrency: group: ${{ github.ref }} cancel-in-progress: true - if: github.ref_name == 'development' || github.ref_name == 'master' || github.ref_name == 'production' || github.ref_name == 'feature/multiple-clusters' + if: github.ref_name == 'development' || github.ref_name == 'master' || github.ref_name == 'production' steps: - id: argocd name: Select overlay shell: bash run: | - if [ "$GIT_REF" == "development" ] || [ "$GIT_REF" == "feature/multiple-clusters" ]; then + if [ "$GIT_REF" == "development" ]; then echo ::set-output name=overlay::overlays/euc1-testing elif [ "$GIT_REF" == "master" ]; then echo ::set-output name=overlay::overlays/euc1-staging @@ -126,7 +126,7 @@ jobs: - id: argocd shell: bash run: | - if [ "$GIT_REF" == "development" ] || [ "$GIT_REF" == "feature/multiple-clusters" ]; then + if [ "$GIT_REF" == "development" ]; then echo ::set-output name=server-url::argocd.euc1.t.get-protocol.dev echo ::set-output name=token::$EUC1TESTING_TOKEN elif [ "$GIT_REF" == "master" ]; then