diff --git a/.aws/task_definition_strapi.json b/.aws/task_definition_strapi.json new file mode 100644 index 000000000..b78c1fe1b --- /dev/null +++ b/.aws/task_definition_strapi.json @@ -0,0 +1,97 @@ +{ + "taskDefinitionArn": "arn:aws:ecs:eu-west-3:253053805092:task-definition/Strapi:1", + "containerDefinitions": [ + { + "name": "strapi", + "image": "253053805092.dkr.ecr.eu-west-3.amazonaws.com/quivr-strapi", + "cpu": 512, + "memory": 2048, + "portMappings": [ + { + "name": "strapi-1337-tcp", + "containerPort": 1337, + "hostPort": 1337, + "protocol": "tcp", + "appProtocol": "http" + } + ], + "essential": true, + "environment": [], + "environmentFiles": [ + { + "value": "arn:aws:s3:::quivr-env-variables/strapi.env", + "type": "s3" + } + ], + "mountPoints": [], + "volumesFrom": [], + "ulimits": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-create-group": "true", + "awslogs-group": "/ecs/Strapi", + "awslogs-region": "eu-west-3", + "awslogs-stream-prefix": "ecs" + }, + "secretOptions": [] + } + } + ], + "family": "Strapi", + "taskRoleArn": "arn:aws:iam::253053805092:role/ecsTaskExecutionRole", + "executionRoleArn": "arn:aws:iam::253053805092:role/ecsTaskExecutionRole", + "networkMode": "awsvpc", + "revision": 1, + "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": "512", + "memory": "2048", + "runtimePlatform": { + "cpuArchitecture": "X86_64", + "operatingSystemFamily": "LINUX" + }, + "registeredAt": "2023-09-21T07:48:32.167Z", + "registeredBy": "arn:aws:iam::253053805092:root", + "tags": [] +} \ No newline at end of file diff --git a/.github/workflows/aws-strapi.yml b/.github/workflows/aws-strapi.yml new file mode 100644 index 000000000..53c309bfc --- /dev/null +++ b/.github/workflows/aws-strapi.yml @@ -0,0 +1,103 @@ +name: Deploy Strapi + +on: + push: + branches: [ "main" ] + paths: + - 'cms/**' + +env: + AWS_REGION: eu-west-3 + ECR_REPOSITORY: quivr-strapi + ECR_REGISTRY: 253053805092.dkr.ecr.eu-west-3.amazonaws.com + ECS_CLUSTER: quivr + +jobs: + build_and_push: + name: Build and Push Docker Image + 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 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - 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 + - name: Build, tag, and push image to Amazon ECR + id: build-image + uses: docker/build-push-action@v4 + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ github.sha }} + with: + context: ./cms/quivr/ + push: true + tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}, ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest, ghcr.io/stangirard/quivr:latest + 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: "strapi" + service: "strapi" + task_definition: ".aws/task_definition_strapi.json" + container: "strapi" + + 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: ${{env.ECR_REGISTRY}}/${{ env.ECR_REPOSITORY }}:${{ github.sha }} + + - 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 \ No newline at end of file diff --git a/cms/quivr/.env.example b/cms/quivr/.env.example index ebfc96a35..bb25a7239 100644 --- a/cms/quivr/.env.example +++ b/cms/quivr/.env.example @@ -5,3 +5,4 @@ API_TOKEN_SALT=tobemodified ADMIN_JWT_SECRET=tobemodified TRANSFER_TOKEN_SALT=tobemodified JWT_SECRET=tobemodified +