Skip to content

Deploy to Amazon ECS PRODUCTION #20

Deploy to Amazon ECS PRODUCTION

Deploy to Amazon ECS PRODUCTION #20

# 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 PRODUCTION
on:
workflow_dispatch:
inputs:
refToDeploy:
description: "Branch, tag or commit SHA1 to deploy"
required: true
type: string
defaults:
run:
shell: bash
env:
AWS_REGION: eu-west-2
ECR_REPOSITORY: paasmigration-default-webapp-repository # set this to your Amazon ECR repository name
ECS_SERVICE: paasmigration-default-webapp-service # set this to your Amazon ECS service name
ECS_CLUSTER: paasmigration-default-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:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: aws-production
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.refToDeploy }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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@v2
- 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 .
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-default-ecs-cluster --launch-type FARGATE --task-definition paasmigration-default-dbmigrate --network-configuration "awsvpcConfiguration={subnets=[subnet-091481d87daeaa67e,subnet-02591304001ccdcf4,subnet-037b1a22886c08933],securityGroups=[sg-03b9ae71f227ea847]}"
- name: Force deployment
id: force-deploy
run: |
aws ecs update-service --cluster paasmigration-default-ecs-cluster --service paasmigration-default-webapp-service --force-new-deployment
aws ecs update-service --cluster paasmigration-default-ecs-cluster --service paasmigration-default-sidekiq-service --force-new-deployment