diff --git a/.github/workflows/cd_push.yml b/.github/workflows/cd_push.yml index 2e94b2e..8f2639d 100755 --- a/.github/workflows/cd_push.yml +++ b/.github/workflows/cd_push.yml @@ -6,9 +6,13 @@ on: image: required: true type: string - argocd_app_name: + argocd_app_names: required: true type: string + deploy_dirs: + required: false + type: string + default: '["deploy"]' dockle_whitelist: required: false type: string @@ -44,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 }} @@ -53,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: @@ -62,26 +66,18 @@ jobs: 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" ]; 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::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::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::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 }} - name: Generate token id: generate_token @@ -97,36 +93,67 @@ jobs: with: kustomize-version: "4.4.0" + - uses: actions/setup-node@v3 + with: + node-version: 16 + - 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 $GITHUB_WORKSPACE/$i/$TARGET + kustomize edit set image $IMAGE=:$TAG + cat kustomization.yml + npx prettier --write . + done shell: bash env: TARGET: ${{ steps.argocd.outputs.overlay }} IMAGE: ${{ inputs.image }} TAG: ${{ github.sha }} - - - uses: actionsx/prettier@v2 - with: - args: --write ${{ steps.argocd.outputs.overlay }}/kustomization.yml + DEPLOY_DIRS: ${{ inputs.deploy_dirs }} - 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: + APP_NAME: ${{ fromJSON(inputs.argocd_app_names) }} + steps: + - id: argocd + shell: bash + run: | + 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 + echo ::set-output name=server-url::argocd.euc1.s.get-protocol.dev + echo ::set-output name=token::$EUC1STAGING_TOKEN + elif [ "$GIT_REF" == "production" ]; then + echo ::set-output name=server-url::argocd.euc1.get-protocol.cloud + echo ::set-output name=token::$EUC1_TOKEN + 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 }} - - 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 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 }}