From 4f85a1490dec3ba2e684bfcb40cb875b269ccedf Mon Sep 17 00:00:00 2001 From: Venkata Challa Date: Tue, 2 Jan 2024 16:45:05 +0000 Subject: [PATCH] Added workflow for deploy review app and delete while closing pull request --- .github/workflows/delete_review_app_aks.yml | 43 ++++++++ .github/workflows/deploy_aks.yml | 109 ++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 .github/workflows/delete_review_app_aks.yml create mode 100644 .github/workflows/deploy_aks.yml diff --git a/.github/workflows/delete_review_app_aks.yml b/.github/workflows/delete_review_app_aks.yml new file mode 100644 index 000000000..5becd6e9f --- /dev/null +++ b/.github/workflows/delete_review_app_aks.yml @@ -0,0 +1,43 @@ +name: Delete review app on AKS + +on: + pull_request: + branches: + - main + types: + - closed + +concurrency: deploy-${{ github.ref }} + +jobs: + build: + runs-on: ubuntu-latest + environment: review + + steps: + - name: Destroy review app + uses: actions/checkout@v4 + + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.6.4 + terraform_wrapper: false + + - uses: DFE-Digital/github-actions/set-arm-environment-variables@master + with: + azure-credentials: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Terraform Destroy + run: | + make ci review terraform-destroy + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + + - name: Post Pull Request Comment + if: ${{ github.event_name == 'pull_request' }} + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: aks + message: | + Review app track and pay deployed to was deleted + Review app school placements deployed to was deleted diff --git a/.github/workflows/deploy_aks.yml b/.github/workflows/deploy_aks.yml new file mode 100644 index 000000000..e2feefbd0 --- /dev/null +++ b/.github/workflows/deploy_aks.yml @@ -0,0 +1,109 @@ +name: Build and deploy to AKS cluster + +on: + push: + branches: + - main + pull_request: + branches: + - main + + +concurrency: deploy-${{ github.ref }} + +jobs: + build: + runs-on: ubuntu-latest + outputs: + docker-image-tag: ${{ steps.build-image.outputs.tag }} + matrix-environments: ${{ toJSON(steps.*.outputs.matrix-environment) }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2.2 + bundler-cache: true + - name: Use Node.js 20.9.0 + uses: actions/setup-node@v4 + with: + node-version: 20.9.0 + cache: "npm" + - name: Install dependencies + run: | + sudo apt-get update && sudo apt-get -yqq install libpq-dev + bundle install --jobs 4 --retry 3 + bundle exec rails assets:precompile + env: + DATABASE_URL: postgres://postgres:password@localhost:5432 + GOVUK_NOTIFY_API_KEY: fake_key + SIGN_IN_METHOD: persona + + - name: Intellisense + run: bin/bundle exec yard gems + + - name: Build and push docker image + id: build-image + uses: DFE-Digital/github-actions/build-docker-image@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + context: . + env: + SIGN_IN_METHOD: persona + + - name: Prepare matrix environments review + id: matrix-env-review + if: github.event_name == 'pull_request' + run: echo "matrix-environment=review" >> $GITHUB_OUTPUT + + deploy: + name: Deploy ${{ matrix.environment }} + runs-on: ubuntu-latest + needs: [build] + environment: + name: ${{ matrix.environment }} + url: ${{ steps.get-app-url.outputs.url1 }} + strategy: + max-parallel: 1 + matrix: + environment: ${{ fromJSON(needs.build.outputs.matrix-environments) }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.6.4 + terraform_wrapper: false + + - uses: DFE-Digital/github-actions/set-arm-environment-variables@master + with: + azure-credentials: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Terraform Apply + run: | + make ci ${{ matrix.environment }} terraform-apply + env: + DOCKER_IMAGE_TAG: ${{ needs.build.outputs.docker-image-tag }} + PR_NUMBER: ${{ github.event.pull_request.number }} + + - name: Get application URL + id: get-app-url + run: | + url1="https://track-and-pay-${{ github.event.number }}.test.teacherservices.cloud" + echo "url1=${url1}" >> $GITHUB_OUTPUT + url2="https://manage-school-placements-${{ github.event.number }}.test.teacherservices.cloud" + echo "url2=${url2}" >> $GITHUB_OUTPUT + + - name: Post comment to Pull Request ${{ github.event.number }} + if: ${{ github.event_name == 'pull_request' }} + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: aks + message: | + Review app track and pay deployed to + Review app school placements deployed to