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-1702 Migrate test environment to AKS #2815

Merged
merged 14 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 60 additions & 1 deletion .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build and deploy to AKS cluster

on:
push:
branches: [master]
pull_request:
types: [labeled, opened, reopened, synchronize]

Expand All @@ -13,7 +15,6 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
outputs:
docker-image-tag: ${{ steps.build-image.outputs.tag }}

Expand All @@ -33,6 +34,7 @@ jobs:
name: Deploy to review environment
concurrency: deploy_review_${{ github.event.pull_request.number }}
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
needs: [build]
environment:
name: review-aks
Expand Down Expand Up @@ -78,3 +80,60 @@ jobs:
| Additional Payments | <${{ env.APP_URL }}/additional-payments/claim> |
| Student Loans | <${{ env.APP_URL }}/student-loans/claim> |
| Admin | <${{ env.APP_URL }}/admin> |

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

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- uses: ./.github/actions/deploy-environment
id: deploy
with:
environment: test-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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally have a smoke test post deployment for permanent env deployments (i.e. test/prod), and also look to have a slack msg generated on workflow failure (of perm env deploy/smoke test failure)

Copy link
Contributor Author

@AbigailMcP AbigailMcP Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smoke test PR: #2875

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slack message PR: #2864


- name: Install Ruby 3.2.4
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 3.2.4

- name: Run smoke tests
shell: bash
run: bundle exec rspec spec/smoke -t smoke:true -b
env:
RAILS_ENV: test
SMOKE_TEST_APP_HOST: ${{ env.APP_URL }}
BASIC_AUTH_USERNAME: ${{ secrets.BASIC_AUTH_USERNAME }}
BASIC_AUTH_PASSWORD: ${{ secrets.BASIC_AUTH_PASSWORD }}

- name: Notify on failure
if: failure()
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_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ group :test do
gem "launchy"
gem "rack_session_access"
gem "simplecov", require: false
# Return null object for active record connection rather than raising error
gem "activerecord-nulldb-adapter"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ GEM
activesupport (= 7.0.8.4)
activerecord-copy (1.1.0)
activerecord (>= 3.1)
activerecord-nulldb-adapter (1.0.1)
activerecord (>= 5.2.0, < 7.2)
activestorage (7.0.8.4)
actionpack (= 7.0.8.4)
activejob (= 7.0.8.4)
Expand Down Expand Up @@ -552,6 +554,7 @@ PLATFORMS

DEPENDENCIES
activerecord-copy
activerecord-nulldb-adapter
application_insights!
bootsnap (>= 1.1.0)
brakeman
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ review-aks: test-cluster
$(eval ENVIRONMENT=review-${PR_NUMBER})
$(eval export TF_VAR_environment=${ENVIRONMENT})
$(eval include global_config/review.sh)
echo https://claim-additional-payments-for-teaching-review-$(PR_NUMBER).test.teacherservices.cloud will be created in aks

.PHONY: test-aks
test-aks: test-cluster
Expand Down
18 changes: 0 additions & 18 deletions bin/slack-alert

This file was deleted.

19 changes: 12 additions & 7 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
#
Dir[Rails.root.join("spec", "support", "**", "*.rb")].sort.each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
if ENV["SMOKE_TEST_APP_HOST"].present?
ActiveRecord::Base.establish_connection adapter: :nulldb
else
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
end
end

RSpec.configure do |config|
Expand Down Expand Up @@ -82,6 +86,7 @@
OmniAuth.config.mock_auth[:default] = nil
end

config.filter_run_excluding :smoke
config.filter_run_excluding flaky: true unless ENV["RUN_FLAKY_SPECS"] == "true"
config.filter_run_excluding js: true unless ENV["RUN_JS_SPECS"] == "true"
config.filter_run_excluding slow: true unless ENV["RUN_SLOW_SPECS"] == "true"
Expand Down
24 changes: 24 additions & 0 deletions spec/smoke/start_a_claim_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "rails_helper"

RSpec.describe "Start a claim", :smoke, type: :feature do
# To test this locally you will need to add to your .env file:
#
# SMOKE_TEST_APP_HOST
# BASIC_AUTH_USERNAME
# BASIC_AUTH_PASSWORD

scenario "User starts a claim" do
visit url_with_basic_auth
expect(page).to have_text("Teachers: claim back your student loan repayments")
end

def url_with_basic_auth
host = ENV.fetch("SMOKE_TEST_APP_HOST")
path = new_claim_path(Journeys::TeacherStudentLoanReimbursement::ROUTING_NAME)
uri = URI.join(host, path)

uri.user = ENV.fetch("BASIC_AUTH_USERNAME", nil)
uri.password = ENV.fetch("BASIC_AUTH_PASSWORD", nil)
uri.to_s
end
end
10 changes: 10 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@
end

Capybara.automatic_label_click = true

RSpec.configure do |config|
config.around(:each, :smoke) do |example|
Capybara.current_driver = Capybara.javascript_driver
Capybara.run_server = false
example.run
Capybara.run_server = true
Capybara.current_driver = Capybara.default_driver
end
end
2 changes: 2 additions & 0 deletions terraform/application/application.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module "web_application" {

docker_image = var.docker_image
command = var.startup_command

replicas = var.web_replicas
}

module "worker_application" {
Expand Down
10 changes: 10 additions & 0 deletions terraform/application/config/test.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cluster": "test",
"namespace": "srtl-test",
"config": "test",
"environment": "test",
"canonical_hostname": "claim-additional-payments-for-teaching-test-web.test.teacherservices.cloud",
"web_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"]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the claim-additional-payments-for-teaching-test-web deployment should have 2 replicas

3 changes: 3 additions & 0 deletions terraform/application/config/test_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: "testing"
2 changes: 2 additions & 0 deletions terraform/application/config/test_app_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
SUPPRESS_DFE_ANALYTICS_INIT: true
1 change: 1 addition & 0 deletions terraform/application/database.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ module "postgres" {
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"
}
4 changes: 4 additions & 0 deletions terraform/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ variable "canonical_hostname" {
description = "External domain name for the app service"
default = null
}
variable "web_replicas" {
description = "Number of replicas of the web app"
default = 1
}

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