2023-06-02 10:28:26 +03:00
|
|
|
name: Deploy to Amazon ECS
|
|
|
|
|
2023-06-29 10:55:06 +03:00
|
|
|
on:
|
2023-06-02 10:28:26 +03:00
|
|
|
push:
|
2023-08-18 19:18:36 +03:00
|
|
|
tags:
|
|
|
|
- 'v*'
|
2023-06-02 10:28:26 +03:00
|
|
|
|
|
|
|
env:
|
2023-08-18 19:16:01 +03:00
|
|
|
AWS_REGION: eu-west-3
|
|
|
|
ECR_REPOSITORY: quivr
|
|
|
|
ECR_REGISTRY: 253053805092.dkr.ecr.eu-west-3.amazonaws.com
|
|
|
|
ECS_CLUSTER: quivr
|
2023-06-02 10:28:26 +03:00
|
|
|
|
|
|
|
jobs:
|
2023-08-18 19:16:01 +03:00
|
|
|
build_and_push:
|
|
|
|
name: Build and Push Docker Image
|
2023-06-02 10:28:26 +03:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
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
|
2023-08-18 19:16:01 +03:00
|
|
|
|
2023-08-18 19:41:50 +03:00
|
|
|
- name: Login to GitHub Container Registry
|
|
|
|
uses: docker/login-action@v2
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2023-08-18 19:16:01 +03:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
|
|
|
|
- name: Create Docker Cacha Storage Backend
|
|
|
|
run: |
|
|
|
|
docker buildx create --use --driver=docker-container
|
|
|
|
- name: See the file in the runner
|
|
|
|
run: |
|
|
|
|
ls -la
|
2023-06-02 10:28:26 +03:00
|
|
|
- name: Build, tag, and push image to Amazon ECR
|
|
|
|
id: build-image
|
2023-08-18 19:16:01 +03:00
|
|
|
uses: docker/build-push-action@v4
|
2023-06-02 10:28:26 +03:00
|
|
|
env:
|
|
|
|
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
|
|
|
IMAGE_TAG: ${{ github.sha }}
|
2023-08-18 19:16:01 +03:00
|
|
|
with:
|
|
|
|
context: ./backend/core/
|
|
|
|
push: true
|
2023-08-18 19:41:50 +03:00
|
|
|
tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}, ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ github.ref_name}}, ghcr.io/stangirard/quivr:${{ github.ref_name}}
|
2023-08-18 19:16:01 +03:00
|
|
|
cache-from: type=gha
|
|
|
|
cache-to: type=gha,mode=max
|
|
|
|
|
|
|
|
deploy:
|
|
|
|
needs: build_and_push
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
environment: production
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
include:
|
|
|
|
- name: "quivr"
|
|
|
|
service: "quivr-backend"
|
|
|
|
task_definition: ".aws/task_definition.json"
|
|
|
|
container: "quivr"
|
|
|
|
- name: "quivr-chat"
|
|
|
|
service: "prod-service-chat"
|
|
|
|
task_definition: ".aws/task_definition_prod_chat.json"
|
|
|
|
container: "quivr-chat"
|
|
|
|
- name: "quivr-upload"
|
|
|
|
service: "prod-service-upload"
|
|
|
|
task_definition: ".aws/task_definition_prod_upload.json"
|
|
|
|
container: "quivr-upload"
|
|
|
|
- name: "quivr-crawl"
|
|
|
|
service: "prod-service-crawl"
|
|
|
|
task_definition: ".aws/task_definition_prod_crawl.json"
|
|
|
|
container: "quivr-crawl"
|
2023-06-02 10:28:26 +03:00
|
|
|
|
2023-08-18 19:16:01 +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: Fill in the new image ID in the Amazon ECS task definition for ${{ matrix.name }}
|
2023-06-02 10:28:26 +03:00
|
|
|
id: task-def
|
|
|
|
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
|
|
with:
|
2023-08-18 19:16:01 +03:00
|
|
|
task-definition: ${{ matrix.task_definition }}
|
|
|
|
container-name: ${{ matrix.container }}
|
|
|
|
image: ${{env.ECR_REGISTRY}}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
|
2023-06-02 10:28:26 +03:00
|
|
|
|
2023-08-18 19:18:36 +03:00
|
|
|
- name: Deploy Amazon ECS task definition for ${{ matrix.name }}
|
|
|
|
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
|
|
|
with:
|
|
|
|
task-definition: ${{ steps.task-def.outputs.task-definition }}
|
|
|
|
service: ${{ matrix.service }}
|
|
|
|
cluster: ${{ env.ECS_CLUSTER }}
|
|
|
|
wait-for-service-stability: true
|