feat(aws): deployment

This commit is contained in:
Stan Girard 2023-06-02 09:28:26 +02:00
parent c3bb0257f0
commit dc495523cc
2 changed files with 153 additions and 0 deletions

82
.aws/task_definition.json Normal file
View File

@ -0,0 +1,82 @@
{
"taskDefinitionArn": "arn:aws:ecs:eu-west-3:253053805092:task-definition/quivr:32",
"containerDefinitions": [
{
"name": "quivr",
"image": "253053805092.dkr.ecr.eu-west-3.amazonaws.com/quivr:0c7a11ada31c57d0c203225803a37b5b92696a7c",
"cpu": 256,
"memory": 512,
"portMappings": [
{
"name": "quivr-5050-tcp",
"containerPort": 5050,
"hostPort": 5050,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/quivr",
"awslogs-region": "eu-west-3",
"awslogs-stream-prefix": "ecs"
}
}
}
],
"family": "quivr",
"executionRoleArn": "arn:aws:iam::253053805092:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"revision": 32,
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"name": "ecs.capability.execution-role-awslogs"
},
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"name": "ecs.capability.execution-role-ecr-pull"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"name": "ecs.capability.task-eni"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2",
"FARGATE"
],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "256",
"memory": "512",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"registeredAt": "2023-04-01T15:02:18.838Z",
"registeredBy": "arn:aws:iam::253053805092:root",
"tags": []
}

71
.github/workflows/aws.yml vendored Normal file
View File

@ -0,0 +1,71 @@
name: Deploy to Amazon ECS
on:
push:
branches: [ "main" ]
env:
AWS_REGION: eu-west-3 # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: quivr # set this to your Amazon ECR repository name
ECS_SERVICE: quivr # set this to your Amazon ECS service name
ECS_CLUSTER: quivr # set this to your Amazon ECS cluster name
ECS_TASK_DEFINITION: .aws/task_definition.json # set this to the path to your Amazon ECS task definition
# file, e.g. .aws/task-definition.json
CONTAINER_NAME: quivr # set this to the name of the container in the
# containerDefinitions section of your task definition
permissions:
contents: read
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
environment: production
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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: Build, tag, and push image to Amazon ECR
id: build-image
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
id: task-def
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.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true