{
"family": "smb-backend-td",
"containerDefinitions": [
{
"name": "smb-backend",
"image": {image arn},
"cpu": 0,
"portMappings": [
{
"name": "smb-backend-8000-tcp",
"containerPort": 8000,
"hostPort": 8000,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/smb-backend-td",
"awslogs-region": "ap-south-1",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
}
}
],
"taskRoleArn": "arn:aws:iam::126819498774:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::126819498774:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "1024",
"memory": "2048",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
}
}
name: Deploy to Amazon ECS
on:
push:
branches:
- staging
env:
AWS_REGION: ap-south-1
ECR_REPOSITORY: smb-backend
ECS_SERVICE: smb-backend
ECS_CLUSTER: smb-dev-cluster
ECS_TASK_DEFINITION: .aws/task-definition-staging.json
CONTAINER_NAME: smb-backend
permissions:
contents: read
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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@v1
- name: Make envfile
uses: SpicyPizza/create-envfile@v2.0
with:
envkey_APP_TOKEN: ${{ secrets.SMB_APP_TOKEN }}
envkey_CLIENT_SECRET: ${{ secrets.SMB_CLIENT_SECRET}}
envkey_JWT_PUBLIC_KEY: ${{ secrets.SMB_JWT_PUBLIC_KEY }}
envkey_GOOGLE_CLIENT_SECRET: ${{ secrets.SMB_GOOGLE_CLIENT_SECRET }}
envkey_AWS_CLOUDWATCH_LOG_GROUP: ${{ secrets.SMB_AWS_CLOUDWATCH_LOG_GROUP }}
envkey_AWS_CLOUDWATCH_LOG_STREAM: ${{ secrets.SMB_AWS_CLOUDWATCH_LOG_STREAM }}
envkey_MONGO_USER: ${{ secrets.SMB_MONGO_USER }}
envkey_MONGO_PASSWORD: ${{ secrets.SMB_MONGO_PASSWORD }}
envkey_MONGO_HOST: ${{ secrets.SMB_MONGO_HOST }}
envkey_MONGO_DB: ${{ secrets.SMB_MONGO_DB }}
envkey_AWS_ACCESS_KEY: ${{ secrets.SMB_AWS_ACCESS_KEY }}
envkey_AWS_SECRET_KEY: ${{ secrets.SMB_AWS_SECRET_KEY }}
envkey_EN_SECRET_KEY: ${{ secrets.SMB_EN_SECRET_KEY }}
envkey_GOOGLE_SERVICE_TOKEN: ${{ secrets.SMB_GOOGLE_SERVICE_TOKEN }}
envkey_MICROSOFT_SERVICE_TOKEN: ${{ secrets.SMB_MICROSOFT_SERVICE_TOKEN }}
envkey_LOGGING_AWS_ACCESS_KEY: ${{ secrets.SMB_LOGGING_AWS_ACCESS_KEY }}
envkey_LOGGING_AWS_SECRET_KEY: ${{ secrets.SMB_LOGGING_AWS_SECRET_KEY }}
envkey_STRIPE_WEBHOOK_ENDPOINT_SECRET: ${{ secrets.STRIPE_WEBHOOK_ENDPOINT_SECRET }}
envkey_STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
envkey_REDIS_HOST: ${{ vars.REDIS_HOST }}
envkey_REDIS_PORT: ${{ vars.REDIS_PORT }}
envkey_STRIPE_PAYMENT_CANCEL_PAGE: ${{ vars.STRIPE_PAYMENT_CANCEL_PAGE }}
envkey_STRIPE_PAYMENT_SUCCESS_PAGE: ${{ vars.STRIPE_PAYMENT_SUCCESS_PAGE }}
envkey_KAFKA_BROKERS: ${{ secrets.KAFKA_BROKERS }}
envkey_KAFKA_USERNAME: ${{ secrets.KAFKA_USERNAME }}
envkey_KAFKA_PASSWORD: ${{ secrets.KAFKA_PASSWORD }}
file_name: .env
fail_on_empty: false
sort_keys: false
- name: Build, tag, and push image to Amazon ECR for Development
id: build-image-dev
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
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 .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition for Development
id: task-def-dev
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image-dev.outputs.image }}
- name: Deploy Amazon ECS task definition for Development
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def-dev.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true