update nth version #28
Workflow file for this run
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# GitHub recommends pinning actions to a commit SHA. | |
# To get a newer version, you will need to update the SHA. | |
# You can also reference a tag or branch, but the action may change without warning. | |
name: Deploy to Amazon ECS STAGING | |
on: | |
pull_request: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: bash | |
env: | |
AWS_REGION: eu-west-2 | |
ECR_REPOSITORY: paasmigration-staging-webapp-repository # set this to your Amazon ECR repository name | |
ECS_SERVICE: paasmigration-staging-webapp-service # set this to your Amazon ECS service name | |
ECS_CLUSTER: paasmigration-staging-ecs-cluster # set this to your Amazon ECS cluster name | |
# ECS_TASK_DEFINITION: MY_ECS_TASK_DEFINITION # set this to the path to your Amazon ECS task definition | |
# file, e.g. .aws/task-definition.json | |
CONTAINER_NAME: | |
HfUApp # set this to the name of the container in the | |
# containerDefinitions section of your task definition | |
jobs: | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:13.5 | |
env: | |
POSTGRES_PASSWORD: password | |
POSTGRES_USER: ukraine | |
POSTGRES_DB: ukraine | |
ports: | |
- 5432:5432 | |
# needed because the postgres container does not provide a healthcheck | |
# tmpfs makes DB faster by using RAM | |
options: >- | |
--mount type=tmpfs,destination=/var/lib/postgresql/data | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
redis: | |
# Docker Hub image | |
image: redis | |
# Set health checks to wait until redis has started | |
options: >- | |
--health-cmd "redis-cli ping" | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
env: | |
RAILS_ENV: test | |
INSTANCE_NAME: ukraine-sponsor-resettlement-test | |
VCAP_SERVICES: '{"redis":[{"instance_name":"ukraine-sponsor-resettlement-test-redis","credentials":{"uri":"redis://redis"}}],"aws-s3-bucket":[{"instance_name":"ukraine-sponsor-resettlement-test-s3","credentials":{"aws_access_key_id":"access-key-id","aws_secret_access_key":"secret-access-key","aws_region":"eu-west-2","bucket_name":"test-bucket"}}]}' | |
GEMFILE_RUBY_VERSION: 3.1.4 | |
DB_HOST: localhost | |
DB_DATABASE: ukraine | |
DB_USERNAME: ukraine | |
DB_PASSWORD: password | |
GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.refToDeploy }} | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
# runs 'bundle install' and caches installed gems automatically | |
bundler-cache: true | |
- name: Set up node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: "16" | |
- name: Create DB | |
run: | | |
bundle exec rake db:prepare | |
- name: Migrate DB | |
run: | | |
bundle exec rake db:migrate | |
- name: Compile Assets | |
run: | | |
bundle exec rake assets:precompile | |
- name: Run tests | |
run: | | |
bundle exec rake | |
#- name: Test coverage | |
# uses: joshmfrankel/simplecov-check-action@main | |
# with: | |
# github_token: ${{ secrets.GITHUB_TOKEN }} | |
# minimum_suite_coverage: 70 | |
# minimum_file_coverage: 0 | |
lint: | |
name: Lint | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.refToDeploy }} | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
# runs 'bundle install' and caches installed gems automatically | |
bundler-cache: true | |
- name: Rubocop | |
run: | | |
bundle exec rubocop | |
audit: | |
name: Audit dependencies | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.refToDeploy }} | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
# runs 'bundle install' and caches installed gems automatically | |
bundler-cache: true | |
- name: Audit | |
run: | | |
bundle exec bundler-audit | |
brakeman-scan: | |
name: Brakeman Scan | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository to the GitHub Actions runner | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.refToDeploy }} | |
# Customize the ruby version depending on your needs | |
- name: Setup Ruby | |
uses: ruby/setup-ruby@v1 | |
- name: Setup Brakeman | |
run: | | |
gem install brakeman | |
# Execute Brakeman CLI and generate a SARIF output with the security issues identified during the analysis | |
- name: Scan | |
run: | | |
brakeman --color -o /dev/stdout | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
environment: aws-staging | |
needs: [lint, test, audit, brakeman-scan] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.refToDeploy }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
IMAGE_TAG: latest | |
run: | | |
# Build a docker container and | |
# push it to ECR so that it can | |
# be deployed to ECS. | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile-prod . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
- name: Run DB migrations | |
id: db-migrate | |
run: aws ecs run-task --cluster paasmigration-staging-ecs-cluster --launch-type FARGATE --task-definition paasmigration-staging-dbmigrate --network-configuration "awsvpcConfiguration={subnets=[subnet-0d51c122320a5109d,subnet-0ac8857c1a1fae109,subnet-023faa26a32d874f9],securityGroups=[sg-0febc019ff5d677b5]}" | |
- name: Force deployment | |
id: force-deploy | |
run: | | |
aws ecs update-service --cluster paasmigration-staging-ecs-cluster --service paasmigration-staging-webapp-service --force-new-deployment | |
aws ecs update-service --cluster paasmigration-staging-ecs-cluster --service paasmigration-staging-sidekiq-service --force-new-deployment |