Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAPT-1703 Migrate production environment to AKS #2887

Merged
merged 28 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
02261ba
Production deployment workflow
vacabor Jun 20, 2024
85e9d48
Trailing newline
vacabor Jun 20, 2024
a75e7d9
Use a datatype that exists
vacabor Jun 20, 2024
58d9255
Merge branch 'master' into CAPT-1703-prod-aks-migration
vacabor Jun 20, 2024
f38d7c5
Merge branch 'master' into CAPT-1703-prod-aks-migration
vacabor Jun 21, 2024
788c5e5
Wait for test deployment before deploying to production
vacabor Jun 24, 2024
90e40d5
Merge branch 'master' into CAPT-1703-prod-aks-migration
vacabor Jun 24, 2024
5c7c334
Add HA and PG backups for production
vacabor Jun 24, 2024
9201c0a
Merge branch 'CAPT-1703-prod-aks-migration' of github.com:DFE-Digital…
vacabor Jun 24, 2024
48c7070
Refactor running migrations into deployment action
vacabor Jun 25, 2024
21aaab5
WIP: Run the action on this branch for testing
vacabor Jun 25, 2024
a4dfafa
Provide PR_NUMBER when running migrations
vacabor Jun 25, 2024
97ad209
Perform azure/login ahead of migrations
vacabor Jun 25, 2024
3d551b3
WIP: Run the test/prod deploys on this branch for testing
vacabor Jun 25, 2024
9401464
Turn off HA initially to allow the SKU to change
vacabor Jun 26, 2024
6e71ed1
Merge branch 'master' of github.com:DFE-Digital/claim-additional-paym…
vacabor Jun 26, 2024
da47883
Revert "Turn off HA initially to allow the SKU to change"
vacabor Jun 26, 2024
e974aa6
Require the build job for prod deploy per PR feedback
vacabor Jun 27, 2024
7312f50
Revert "WIP: Run the action on this branch for testing"
vacabor Jun 27, 2024
a4ee510
Revert "WIP: Run the test/prod deploys on this branch for testing"
vacabor Jun 27, 2024
24cd1fb
WIP: Use the new production canonical_hostname for testing
vacabor Jun 28, 2024
e2363be
Merge branch 'master' into CAPT-1703-prod-aks-migration
vacabor Jul 3, 2024
9c16a5c
Clean up duplicate workflow steps with a matrix
vacabor Jul 5, 2024
593a520
Merge branch 'master' into CAPT-1703-prod-aks-migration
vacabor Jul 5, 2024
e9d72c6
Merge branch 'master' into CAPT-1703-prod-aks-migration
vacabor Jul 10, 2024
67fdaba
Merge branch 'master' of github.com:DFE-Digital/claim-additional-paym…
vacabor Jul 10, 2024
e514f83
Switch back to targetting master
vacabor Jul 10, 2024
5bdcc89
Merge branch 'CAPT-1703-prod-aks-migration' of github.com:DFE-Digital…
vacabor Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/actions/deploy-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ inputs:
pull-request-number:
description: The pull request number which triggered this deploy.
required: false
prepare-database:
description: Whether to prepare the database by running migrations or seeding if needed
required: false
default: true
aks-namespace:
description: The namespace under which kubectl will run
required: true
aks-deployment:
description: The deployment which kubectl will target for running migrations
required: true

runs:
using: composite
Expand Down Expand Up @@ -42,3 +52,19 @@ runs:
run: |
output=$(terraform -chdir=terraform/application output -raw url)
echo "APP_URL=$output" >> $GITHUB_ENV

- uses: azure/login@v2
with:
creds: ${{ inputs.azure-credentials }}

- name: Set kubectl
uses: DFE-Digital/github-actions/set-kubectl@master

- name: Prepare database
if: ${{ inputs.prepare-database }}
shell: bash
run: |
make ci ${{ inputs.environment }} get-cluster-credentials
kubectl exec -n ${{ inputs.aks-namespace }} deployment/${{ inputs.aks-deployment }}-worker -- sh -c "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bin/prepare-database"
env:
PR_NUMBER: ${{ inputs.pull-request-number }}
45 changes: 16 additions & 29 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,9 @@ jobs:
docker-image: ${{ needs.build.outputs.docker-image-tag }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
pull-request-number: ${{ github.event.pull_request.number }}

- uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Set kubectl
uses: DFE-Digital/github-actions/set-kubectl@master

- name: Seed review app
shell: bash
if: github.event.number != ''
run: |
make ci review-aks get-cluster-credentials
kubectl exec -n srtl-development deployment/claim-additional-payments-for-teaching-review-${{ github.event.pull_request.number }}-worker -- sh -c "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bin/prepare-database"
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
aks-namespace: srtl-development
aks-deployment: claim-additional-payments-for-teaching-review-${{ github.event.pull_request.number }}
prepare-database: ${{ github.event.pull_request.number != '' }}

- name: Post comment to Pull Request ${{ github.event.number }}
if: ${{ github.event_name == 'pull_request' }}
Expand All @@ -83,17 +70,21 @@ jobs:
| Relocation Payments | <${{ env.APP_URL }}/get-a-teacher-relocation-payment/landing-page> |
| Admin | <${{ env.APP_URL }}/admin> |

deploy_test:
name: Deploy to test environment
concurrency: deploy_test
deploy:
name: Deploy to ${{ matrix.environment }}
runs-on: ubuntu-latest
concurrency: deploy_${{ matrix.environment }}
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
needs: [build]
environment:
name: test-aks
name: ${{ matrix.environment }}-aks
url: ${{ steps.deploy.outputs.environment_url }}
outputs:
environment_url: ${{ steps.deploy.outputs.environment_url }}
strategy:
max-parallel: 1
matrix:
environment: [test, production]

steps:
- name: Checkout code
Expand All @@ -106,15 +97,11 @@ jobs:
- uses: ./.github/actions/deploy-environment
id: deploy
with:
environment: test-aks
environment: ${{ matrix.environment }}-aks
docker-image: ${{ needs.build.outputs.docker-image-tag }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}

- name: Run migrations
shell: bash
run: |
make ci test-aks get-cluster-credentials
kubectl exec -n srtl-test deployment/claim-additional-payments-for-teaching-test-worker -- sh -c "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bin/prepare-database"
aks-namespace: srtl-${{ matrix.environment }}
aks-deployment: claim-additional-payments-for-teaching-${{ matrix.environment }}

- name: Install Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -135,6 +122,6 @@ jobs:
uses: rtCamp/action-slack-notify@master
env:
SLACK_COLOR: failure
SLACK_TITLE: Failure deploying release to test
SLACK_MESSAGE: Failure deploying release to test - Docker tag ${{ needs.build.outputs.docker-image-tag }}
SLACK_TITLE: Failure deploying release to ${{ matrix.environment }}
SLACK_MESSAGE: Failure deploying release to ${{ matrix.environment }} - Docker tag ${{ needs.build.outputs.docker-image-tag }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
2 changes: 2 additions & 0 deletions terraform/application/application.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ module "worker_application" {

docker_image = var.docker_image
command = var.worker_command

replicas = var.worker_replicas
}
19 changes: 19 additions & 0 deletions terraform/application/config/production.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cluster": "production",
"namespace": "srtl-production",
"config": "production",
"environment": "production",
"canonical_hostname": "claim-additional-payments-for-teaching-production-web.teacherservices.cloud",
"web_replicas": 2,
"worker_replicas": 2,
"startup_command": ["/bin/sh", "-c", "bin/rails server -b 0.0.0.0"],
"worker_command": ["/bin/sh", "-c", "bin/bundle exec bin/delayed_job run -n 1"],
"postgres_flexible_server_sku": "GP_Standard_D2ds_v4",
"postgres_enable_high_availability": true,
"enable_postgres_backup_storage": true,
"azure_maintenance_window": {
"day_of_week": 0,
"start_hour": 3,
"start_minute": 0
}
}
3 changes: 3 additions & 0 deletions terraform/application/config/production_Terrafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
aks:
source: "https://github.com/DFE-Digital/terraform-modules"
version: "stable"
1 change: 1 addition & 0 deletions terraform/application/config/production_app_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
AbigailMcP marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion terraform/application/config/review.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"deploy_azure_backing_services": false,
"enable_postgres_ssl": false,
"startup_command": ["/bin/sh", "-c", "bin/rails server -b 0.0.0.0"],
"worker_command": ["/bin/sh", "-c", "bin/bundle exec bin/delayed_job run -n 4"]
"worker_command": ["/bin/sh", "-c", "bin/bundle exec bin/delayed_job run -n 1"]
}
27 changes: 15 additions & 12 deletions terraform/application/database.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
module "postgres" {
source = "./vendor/modules/aks//aks/postgres"

namespace = var.namespace
environment = var.environment
azure_resource_prefix = var.azure_resource_prefix
service_name = var.service_name
service_short = var.service_short
config_short = var.config_short
cluster_configuration_map = module.cluster_data.configuration_map
use_azure = var.deploy_azure_backing_services
azure_enable_monitoring = var.enable_monitoring
azure_enable_backup_storage = var.enable_postgres_backup_storage
azure_extensions = ["pg_trgm", "pgcrypto", "plpgsql"]
server_version = "16"
namespace = var.namespace
environment = var.environment
azure_resource_prefix = var.azure_resource_prefix
service_name = var.service_name
service_short = var.service_short
config_short = var.config_short
cluster_configuration_map = module.cluster_data.configuration_map
use_azure = var.deploy_azure_backing_services
azure_enable_monitoring = var.enable_monitoring
azure_enable_backup_storage = var.enable_postgres_backup_storage
azure_extensions = ["pg_trgm", "pgcrypto", "plpgsql"]
server_version = "16"
azure_sku_name = var.postgres_flexible_server_sku
azure_enable_high_availability = var.postgres_enable_high_availability
azure_maintenance_window = var.azure_maintenance_window
}
13 changes: 13 additions & 0 deletions terraform/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ variable "web_replicas" {
description = "Number of replicas of the web app"
default = 1
}
variable "worker_replicas" {
description = "Number of replicas of the worker"
default = 1
}
variable "azure_maintenance_window" {
default = null
}
variable "postgres_flexible_server_sku" {
default = "B_Standard_B1ms"
}
variable "postgres_enable_high_availability" {
default = false
}

locals {
postgres_ssl_mode = var.enable_postgres_ssl ? "require" : "disable"
Expand Down
Loading