quivr/.github/workflows/aws-preview.yml
2023-08-18 15:09:51 +02:00

94 lines
2.9 KiB
YAML

name: Deploy Backend to Preview ECS
on:
push:
branches: [ "main" ]
# paths:
# - 'backend/core/**'
env:
AWS_REGION: eu-west-3
ECR_REPOSITORY: quivr
ECS_CLUSTER: quivr
jobs:
build_and_push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
environment: production
defaults:
run:
working-directory: ./backend/
outputs:
image: ${{ steps.build-image.outputs.image }}
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: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./core/
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> "$GITHUB_OUTPUT"
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
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 }}
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ matrix.task_definition }}
container-name: ${{ matrix.container }}
image: ${{ needs.build_and_push.outputs.image }}
- 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: false