From 4ce080b7859ef8225d31ea28339c14c811049d5b Mon Sep 17 00:00:00 2001 From: Stan Girard Date: Thu, 29 Jun 2023 09:55:06 +0200 Subject: [PATCH] Feat/preview env (#399) * feat(preview): added * feat(vercel): preview env --- .aws/task_definition_preview.json | 95 ++++++++++++++++++++++++++++ .github/workflows/aws-preview.yml | 71 +++++++++++++++++++++ .github/workflows/aws.yml | 5 +- .github/workflows/vercel-preview.yml | 20 ++++++ .github/workflows/vercel.yml | 22 +++++++ vercel.json | 7 ++ 6 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 .aws/task_definition_preview.json create mode 100644 .github/workflows/aws-preview.yml create mode 100644 .github/workflows/vercel-preview.yml create mode 100644 .github/workflows/vercel.yml create mode 100644 vercel.json diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json new file mode 100644 index 000000000..46bafe176 --- /dev/null +++ b/.aws/task_definition_preview.json @@ -0,0 +1,95 @@ +{ + "taskDefinitionArn": "arn:aws:ecs:eu-west-3:253053805092:task-definition/quivr-preview:4", + "containerDefinitions": [ + { + "name": "quivr", + "image": "253053805092.dkr.ecr.eu-west-3.amazonaws.com/quivr:c0ff0301002fe6d043270b26dabcfda797437afc", + "cpu": 0, + "portMappings": [ + { + "name": "quivr-5050-tcp", + "containerPort": 5050, + "hostPort": 5050, + "protocol": "tcp", + "appProtocol": "http" + } + ], + "essential": true, + "environment": [], + "environmentFiles": [ + { + "value": "arn:aws:s3:::quivr-env-variables/preview.env", + "type": "s3" + } + ], + "mountPoints": [], + "volumesFrom": [], + "ulimits": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-create-group": "true", + "awslogs-group": "/ecs/quivr-preview", + "awslogs-region": "eu-west-3", + "awslogs-stream-prefix": "ecs" + } + } + } + ], + "family": "quivr-preview", + "taskRoleArn": "arn:aws:iam::253053805092:role/ecsTaskExecutionRole", + "executionRoleArn": "arn:aws:iam::253053805092:role/ecsTaskExecutionRole", + "networkMode": "awsvpc", + "revision": 4, + "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.env-files.s3" + }, + { + "name": "com.amazonaws.ecs.capability.task-iam-role" + }, + { + "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-06-29T07:33:39.537Z", + "registeredBy": "arn:aws:iam::253053805092:root", + "tags": [] +} \ No newline at end of file diff --git a/.github/workflows/aws-preview.yml b/.github/workflows/aws-preview.yml new file mode 100644 index 000000000..22ce75425 --- /dev/null +++ b/.github/workflows/aws-preview.yml @@ -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-preview # 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_preview.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 \ No newline at end of file diff --git a/.github/workflows/aws.yml b/.github/workflows/aws.yml index bfff8f041..27a1cbaa0 100644 --- a/.github/workflows/aws.yml +++ b/.github/workflows/aws.yml @@ -1,8 +1,9 @@ name: Deploy to Amazon ECS -on: +on: push: - branches: [ "main" ] + tags: + - 'v*' env: AWS_REGION: eu-west-3 # set this to your preferred AWS region, e.g. us-west-1 diff --git a/.github/workflows/vercel-preview.yml b/.github/workflows/vercel-preview.yml new file mode 100644 index 000000000..252ae51fd --- /dev/null +++ b/.github/workflows/vercel-preview.yml @@ -0,0 +1,20 @@ +name: Preview Deployment +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} +on: + push: + branches: [ "main" ] +jobs: + Deploy-Preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Vercel CLI + run: npm install --global vercel@latest + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=development --token=${{ secrets.VERCEL_TOKEN }} + - name: Build Project Artifacts + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + - name: Deploy Project Artifacts to Vercel + run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/vercel.yml b/.github/workflows/vercel.yml new file mode 100644 index 000000000..cc93895fa --- /dev/null +++ b/.github/workflows/vercel.yml @@ -0,0 +1,22 @@ +name: Production Tag Deployment +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} +on: + push: + # Pattern matched against refs/tags + tags: + - '*' # Push events to every tag not containing / +jobs: + Deploy-Production: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Vercel CLI + run: npm install --global vercel@latest + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + - name: Build Project Artifacts + run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} + - name: Deploy Project Artifacts to Vercel + run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} \ No newline at end of file diff --git a/vercel.json b/vercel.json new file mode 100644 index 000000000..8e82c51ff --- /dev/null +++ b/vercel.json @@ -0,0 +1,7 @@ +{ + "git": { + "deploymentEnabled": { + "main": false + } + } +} \ No newline at end of file