2023-06-29 10:56:19 +03:00
|
|
|
name: Deploy Backend to Preview ECS
|
2023-06-29 10:55:06 +03:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches: [ "main" ]
|
2023-07-02 15:37:15 +03:00
|
|
|
paths:
|
2023-07-17 09:57:27 +03:00
|
|
|
- 'backend/core/**'
|
2023-06-29 10:55:06 +03:00
|
|
|
|
|
|
|
env:
|
2023-08-18 15:49:48 +03:00
|
|
|
AWS_REGION: eu-west-3
|
|
|
|
ECR_REPOSITORY: quivr
|
|
|
|
ECS_CLUSTER: quivr
|
2023-06-29 10:55:06 +03:00
|
|
|
|
|
|
|
jobs:
|
2023-08-18 15:49:48 +03:00
|
|
|
build_and_push:
|
|
|
|
name: Build and Push Docker Image
|
2023-06-29 10:55:06 +03:00
|
|
|
runs-on: ubuntu-latest
|
2023-08-18 15:49:48 +03:00
|
|
|
environment: production
|
2023-06-29 10:55:06 +03:00
|
|
|
defaults:
|
|
|
|
run:
|
2023-07-18 17:26:10 +03:00
|
|
|
working-directory: ./backend/
|
2023-08-18 15:49:48 +03:00
|
|
|
outputs:
|
|
|
|
image: ${{ steps.build-image.outputs.image }}
|
2023-06-29 10:55:06 +03:00
|
|
|
|
|
|
|
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: |
|
2023-07-18 17:54:31 +03:00
|
|
|
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./core/
|
2023-06-29 10:55:06 +03:00
|
|
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
2023-08-18 15:49:48 +03:00
|
|
|
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
|
2023-06-29 10:55:06 +03:00
|
|
|
|
2023-08-18 15:49:48 +03:00
|
|
|
deploy:
|
|
|
|
needs: build_and_push
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
environment: production
|
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
include:
|
|
|
|
- name: "quivr"
|
|
|
|
service: "quivr-preview"
|
|
|
|
task_definition: ".aws/task_definition_preview.json"
|
|
|
|
container: "quivr"
|
|
|
|
- name: "quivr-chat"
|
|
|
|
service: "preview-service-chat"
|
|
|
|
task_definition: ".aws/task_definition_preview_chat.json"
|
|
|
|
container: "quivr-chat"
|
|
|
|
- name: "quivr-upload"
|
|
|
|
service: "preview-service-upload"
|
|
|
|
task_definition: ".aws/task_definition_preview_upload.json"
|
|
|
|
container: "quivr-upload"
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
|
|
|
|
- name: Configure AWS credentials
|
|
|
|
uses: aws-actions/configure-aws-credentials@v2
|
2023-06-29 10:55:06 +03:00
|
|
|
with:
|
2023-08-18 15:49:48 +03:00
|
|
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
aws-region: ${{ env.AWS_REGION }}
|
|
|
|
- name: Fill in the new image ID in the Amazon ECS task definition for ${{ matrix.name }}
|
|
|
|
id: task-def
|
2023-08-18 13:02:57 +03:00
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
2023-08-18 15:49:48 +03:00
|
|
|
task-definition: ${{ matrix.task_definition }}
|
|
|
|
container-name: ${{ matrix.container }}
|
|
|
|
image: ${{ needs.build_and_push.outputs.image }}
|
2023-06-29 10:55:06 +03:00
|
|
|
|
2023-08-18 15:49:48 +03:00
|
|
|
- name: Deploy Amazon ECS task definition for ${{ matrix.name }}
|
2023-06-29 10:55:06 +03:00
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: ${{ steps.task-def.outputs.task-definition }}
|
2023-08-18 15:49:48 +03:00
|
|
|
service: ${{ matrix.service }}
|
2023-08-18 13:02:57 +03:00
|
|
|
cluster: ${{ env.ECS_CLUSTER }}
|
2023-08-18 15:49:48 +03:00
|
|
|
wait-for-service-stability: false
|