-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from essexcountycouncil/feature/LP-118a
LP-118: Review Apps
- Loading branch information
Showing
5 changed files
with
554 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Stop Review App and cleanup when PR is closed | ||
|
||
on: | ||
pull_request: | ||
types: [ closed ] | ||
|
||
jobs: | ||
cleanup: | ||
name: Clean up Azure | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Add comment for start of job | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
Stopping Review App and clearing up | ||
- name: Log in to Azure | ||
uses: azure/login@v1 | ||
with: | ||
creds: '{"clientId":"${{ vars.ARM_CLIENT_ID }}","clientSecret":"${{ secrets.ARM_CLIENT_SECRET }}","subscriptionId":"${{ vars.ARM_SUBSCRIPTION_ID }}","tenantId":"${{ vars.ARM_TENANT_ID }}"}' | ||
|
||
- name: Remove label | ||
id: remove_label | ||
env: | ||
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} | ||
REF_NAME: ${{ github.head_ref }} | ||
run: | | ||
ENV_SLUG=$(echo "${REF_NAME}" | sed -e 's:[^[:alpha:]|^[:digit:]]:-:g' | sed -e 's/\(.*\)/\L\1/') | ||
az containerapp revision label remove --label ${ENV_SLUG} --name intranet -g rg-ecc-intranet-uks-dev --subscription "Essex County Council (Intranet)" | ||
sleep 1m | ||
- name: Deactivate revisions | ||
id: deactivate | ||
env: | ||
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} | ||
REF_NAME: ${{ github.head_ref }} | ||
shell: bash | ||
run: | | ||
ENV_SLUG=$(echo "${REF_NAME}" | sed -e 's:[^[:alpha:]|^[:digit:]]:-:g' | sed -e 's/\(.*\)/\L\1/') | ||
jq -n --argjson revisions $(az containerapp revision list -n intranet -g rg-ecc-intranet-uks-dev --subscription "Essex County Council (Intranet)" | jq -c '[.[].name]') --argjson ingress $(az containerapp ingress show -n intranet -g rg-ecc-intranet-uks-dev --subscription "Essex County Council (Intranet)" | jq -c ".traffic | [.[].revisionName]") '{"revisions": $revisions, "ingress": $ingress} | .revisions-.ingress | .[]' | tr -d '"' | while read revision | ||
do | ||
echo Deactivating "$revision" | ||
az containerapp revision deactivate --revision $revision -g rg-ecc-intranet-uks-dev --subscription "Essex County Council (Intranet)" | ||
done | ||
- name: Delete database | ||
id: delete_db | ||
env: | ||
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} | ||
REF_NAME: ${{ github.head_ref }} | ||
run: | | ||
ENV_SLUG=$(echo "${REF_NAME}" | sed -e 's:[^[:alpha:]|^[:digit:]]:-:g' | sed -e 's/\(.*\)/\L\1/') | ||
NEW_DB_SUFFIX="intranet_${ENV_SLUG}" | ||
az containerapp job start -n intranet-dbclone -g rg-ecc-intranet-uks-dev --subscription "Essex County Council (Intranet)" --image "acreccuksdev.azurecr.io/dbclone" --env-vars "NEW_DB_SUFFIX=${NEW_DB_SUFFIX}" "DESTROY_DB=1" 'MYSQL_HOST=mariadb-ecc-uks-dev.mariadb.database.azure.com' 'MYSQL_USER=mariadb-root' 'MYSQL_DATABASE=drupal_intranet' 'MYSQL_PASSWORD=secretref:mysql-password' --container-name dbclonea --cpu 0.75 --memory 1.5 | ||
- name: Add comment for end job | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
Stopped Review App and cleared up |
Oops, something went wrong.