Skip to content

Commit

Permalink
Merge pull request #900 from DFE-Digital/2081-aytq-decommission-s165-…
Browse files Browse the repository at this point in the history
…resources-pipelines

s165 code removal from AYTQ repo
  • Loading branch information
shaheislamdfe authored Oct 31, 2024
2 parents b66bc23 + 90d7784 commit 5ce12ba
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 411 deletions.
2 changes: 1 addition & 1 deletion .github/actions/deploy-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ runs:
- name: Terraform Apply
shell: bash
run: |
make ci ${{ inputs.environment }} aks-terraform-apply
make ci ${{ inputs.environment }} terraform-apply
env:
DOCKER_IMAGE_TAG: ${{ inputs.image-tag }}
PR_NUMBER: ${{ inputs.pull-request-number }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
deploy_review_app:
name: Deploy to review environment
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'deploy-aks')
if: contains(github.event.pull_request.labels.*.name, 'deploy')
concurrency: deploy_review_${{ github.event.pull_request.number }}
needs: [build_image]
environment:
name: aks-review
name: review

steps:
- uses: actions/checkout@v4
Expand All @@ -54,7 +54,7 @@ jobs:
uses: ./.github/actions/deploy-environment
id: deploy
with:
environment: aks-review
environment: review
image-tag: ${{ github.sha }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
pull-request-number: ${{ github.event.number }}
Expand All @@ -71,7 +71,7 @@ jobs:
- name: Seed role codes
shell: bash
run: |
make ci aks-review get-cluster-credentials PR_NUMBER=123
make ci review get-cluster-credentials PR_NUMBER=123
kubectl exec -n tra-development deployment/access-your-teaching-qualifications-pr-${{ github.event.number }} -- /bin/sh -c "cd /app && bundle exec rake db:seed_role_codes"
- name: Post comment to Pull Request ${{ github.event.number }}
Expand All @@ -95,7 +95,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
environment: [aks-test, aks-preprod]
environment: [test, preprod]
environment:
name: ${{ matrix.environment }}
url: ${{ steps.deploy.outputs.environment_url }}
Expand All @@ -117,7 +117,7 @@ jobs:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [build_image, deploy]
environment:
name: aks-production
name: production
url: ${{ steps.deploy.outputs.environment_url }}

steps:
Expand All @@ -127,6 +127,6 @@ jobs:
uses: ./.github/actions/deploy-environment
id: deploy
with:
environment: aks-production
environment: production
image-tag: ${{ github.sha }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
2 changes: 1 addition & 1 deletion .github/workflows/database-backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
name: Backup database
runs-on: ubuntu-latest
environment:
name: aks-${{ inputs.environment || 'production' }}
name: ${{ inputs.environment || 'production' }}
env:
DEPLOY_ENV: ${{ inputs.environment || 'production' }}
BACKUP_FILE: ${{ inputs.backup-file || 'schedule' }}
Expand Down
122 changes: 1 addition & 121 deletions .github/workflows/delete-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,126 +20,6 @@ jobs:
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
environment: review
steps:
- uses: actions/checkout@v4
- name: Extract configuration from tfvars
id: config
run: |
if [ ${{ github.event_name }} == 'workflow_dispatch' ]; then
PR_NUMBER=${{ github.event.inputs.pr_number }}
else
PR_NUMBER=${{ github.event.pull_request.number }}
fi
if [ -z "$PR_NUMBER" ]; then
echo "::error ::Failed to extract PR_NUMBER"
exit 1
fi
RESOURCE_PREFIX=$(jq -r '.resource_prefix' $TFVARS)
APP_RESOURCE_GROUP_NAME=$RESOURCE_PREFIX-review-pr-$PR_NUMBER-rg
STORAGE_ACCOUNT_NAME=$(jq -r '.storage_account_name' $TFVARS)
TERRAFORM_VERSION=$(awk '/{/{f=/^terraform/;next}f' terraform.tf | grep -o [0-9\.]*)
DEV_TFVARS=workspace_variables/dev.tfvars.json
TF_RESOURCE_GROUP_NAME=$(jq -r '.resource_group_name' $DEV_TFVARS)
TF_STATE_CONTAINER=$(awk '/{/{f=/backend/;next}f' terraform.tf | grep -o "\"[a-z\-]*\"" | tr -d \")
if [ -z "$APP_RESOURCE_GROUP_NAME" ]; then
echo "::error ::Failed to extract app_resource_group_name from $TFVARS"
exit 1
fi
if [ -z "$STORAGE_ACCOUNT_NAME" ]; then
echo "::error ::Failed to extract storage_account_name from $TFVARS"
exit 1
fi
if [ -z "$TERRAFORM_VERSION" ]; then
echo "::error ::Failed to extract terraform_version from terraform.tf"
exit 1
fi
if [ -z "$TF_RESOURCE_GROUP_NAME" ]; then
echo "::error ::Failed to extract resource_group_name from $DEV_TFVARS"
exit 1
fi
if [ -z "$TF_STATE_CONTAINER" ]; then
echo "::error ::Failed to extract tf_state_container from terraform.tf"
exit 1
fi
echo "app_resource_group_name=$APP_RESOURCE_GROUP_NAME" >> $GITHUB_ENV
echo "pr_number=$PR_NUMBER" >> $GITHUB_ENV
echo "storage_account_name=$STORAGE_ACCOUNT_NAME" >> $GITHUB_ENV
echo "terraform_version=$TERRAFORM_VERSION" >> $GITHUB_ENV
echo "tf_resource_group_name=$TF_RESOURCE_GROUP_NAME" >> $GITHUB_ENV
echo "tf_state_container=$TF_STATE_CONTAINER" >> $GITHUB_ENV
shell: bash
env:
TFVARS: workspace_variables/review.tfvars.json
working-directory: terraform

- uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- run: |
TFSTATE_CONTAINER_ACCESS_KEY="$(az storage account keys list -g ${{ env.tf_resource_group_name }} -n ${{ env.storage_account_name }} | jq -r '.[0].value')"
echo "::add-mask::$TFSTATE_CONTAINER_ACCESS_KEY"
echo "TFSTATE_CONTAINER_ACCESS_KEY=$TFSTATE_CONTAINER_ACCESS_KEY" >> $GITHUB_ENV
shell: bash
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false

- name: Check resource group exists
run: |
GROUP=$(az group exists --name ${{ env.app_resource_group_name }})
if [[ "$GROUP" =~ "true" ]]; then
echo "REVIEW_APP_EXISTS=true" >> $GITHUB_ENV
fi
- name: Set Environment variables
if: env.REVIEW_APP_EXISTS == 'true'
run: |
TF_STATE_FILE=review/review-pr-${{ env.pr_number }}.tfstate
echo "TF_STATE_FILE=$TF_STATE_FILE" >> $GITHUB_ENV
pr_state_file=$(az storage blob list -c ${{ env.tf_state_container }} \
--account-key ${{ env.TFSTATE_CONTAINER_ACCESS_KEY }} \
--account-name ${{ env.storage_account_name }} \
--prefix $TF_STATE_FILE --query "[].name" -o tsv)
if [ -n "$pr_state_file" ]; then
echo "TF_STATE_EXISTS=true" >> $GITHUB_ENV
fi
- name: Terraform
if: env.TF_STATE_EXISTS == 'true'
id: terraform
run: |
make ci review terraform-destroy pr_id=${{ env.pr_number }}
env:
ARM_ACCESS_KEY: ${{ env.TFSTATE_CONTAINER_ACCESS_KEY }}
TF_VAR_azure_sp_credentials_json: ${{ secrets.AZURE_CREDENTIALS }}
TF_VAR_aytq_docker_image: ${{ github.sha }}
shell: bash

- name: Delete tf state file
if: env.TF_STATE_EXISTS == 'true'
run: |
az storage blob delete -c ${{ env.tf_state_container }} --name ${{ env.TF_STATE_FILE }} \
--account-key ${{ env.TFSTATE_CONTAINER_ACCESS_KEY }} \
--account-name ${{ env.storage_account_name }}
delete-review-app-aks:
name: Delete Review App ${{ github.event.pull_request.number }}
concurrency: deploy_review_${{ github.event.pull_request.number }}
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy-aks') }}
environment: aks-review
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -191,7 +71,7 @@ jobs:

- name: Terraform Destroy
run: |
make ci aks-review aks-terraform-destroy
make ci review terraform-destroy
env:
PR_NUMBER: ${{ env.PR_NUMBER }}

Expand Down
Loading

0 comments on commit 5ce12ba

Please sign in to comment.