From cf6493198203ec4e714344f834edd9db50bab661 Mon Sep 17 00:00:00 2001 From: Mikhail Yarmaliuk Date: Thu, 13 Jul 2023 17:26:43 +0200 Subject: [PATCH] feat: deploy to aws --- .github/task-definition.json | 100 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 40 +++++++++++++- 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 .github/task-definition.json diff --git a/.github/task-definition.json b/.github/task-definition.json new file mode 100644 index 0000000..d6eac5d --- /dev/null +++ b/.github/task-definition.json @@ -0,0 +1,100 @@ +{ + "ipcMode": null, + "executionRoleArn": "arn:aws:iam::771350349623:role/ECSTaskDefinitionRole", + "containerDefinitions": [ + { + "dnsSearchDomains": null, + "environmentFiles": null, + "logConfiguration": { + "logDriver": "none", + "secretOptions": null, + "options": null + }, + "entryPoint": [], + "portMappings": [ + { + "hostPort": 0, + "protocol": "tcp", + "containerPort": 3000 + } + ], + "command": [], + "linuxParameters": null, + "cpu": 0, + "environment": [], + "resourceRequirements": null, + "ulimits": null, + "repositoryCredentials": { + "credentialsParameter": "arn:aws:secretsmanager:eu-west-1:771350349623:secret:ecs/docker-github-EvtP4B" + }, + "dnsServers": null, + "mountPoints": [], + "workingDirectory": null, + "secrets": null, + "dockerSecurityOptions": null, + "memory": null, + "memoryReservation": null, + "volumesFrom": [], + "stopTimeout": null, + "image": "ghcr.io/lomray-software/vite-template/web:latest-prod", + "startTimeout": null, + "firelensConfiguration": null, + "dependsOn": null, + "disableNetworking": null, + "interactive": null, + "healthCheck": null, + "essential": true, + "links": null, + "hostname": null, + "extraHosts": null, + "pseudoTerminal": null, + "user": null, + "readonlyRootFilesystem": null, + "dockerLabels": null, + "systemControls": null, + "privileged": null, + "name": "web" + } + ], + "placementConstraints": [], + "memory": "100", + "taskRoleArn": "arn:aws:iam::771350349623:role/ECSTaskDefinitionRole", + "compatibilities": [ + "EXTERNAL", + "EC2" + ], + "taskDefinitionArn": "arn:aws:ecs:eu-west-1:771350349623:task-definition/vite-template:2", + "family": "vite-template", + "requiresAttributes": [ + { + "targetId": null, + "targetType": null, + "value": null, + "name": "ecs.capability.private-registry-authentication.secretsmanager" + }, + { + "targetId": null, + "targetType": null, + "value": null, + "name": "com.amazonaws.ecs.capability.task-iam-role" + }, + { + "targetId": null, + "targetType": null, + "value": null, + "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18" + } + ], + "pidMode": null, + "requiresCompatibilities": [ + "EC2" + ], + "networkMode": "bridge", + "runtimePlatform": null, + "cpu": null, + "revision": 2, + "status": "ACTIVE", + "inferenceAccelerators": null, + "proxyConfiguration": null, + "volumes": [] +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 43814e9..bb082ec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,8 +5,13 @@ on: branches: [ prod, staging ] env: + NODE_VERSION: 18.13.0 REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }}/web + ECS_TASK_DEFINITION: ./.github/task-definition.json + ECS_TASK_CONTAINER_NAME: web + ECS_SERVICE: vite-template + ECS_CLUSTER: Development jobs: build: @@ -22,7 +27,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: '18.13.0' + node-version: ${{ env.NODE_VERSION }} cache: 'npm' - name: Install dependencies @@ -67,6 +72,9 @@ jobs: concurrency: group: ${{ github.ref }}-build-docker cancel-in-progress: true + outputs: + # get docker image tag with version + image-tag: ${{ fromJSON(steps.meta.outputs.json).tags[0] }} steps: - uses: actions/download-artifact@v3 @@ -113,6 +121,36 @@ jobs: build-args: | BUILD_PATH=./build + deploy: + needs: [ docker-build ] + runs-on: ubuntu-latest + concurrency: + group: ${{ github.ref }}-deploy + cancel-in-progress: true + + steps: + - 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: ${{ secrets.AWS_REGION }} + + - name: Update AWS 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.ECS_TASK_CONTAINER_NAME }} + image: ${{ needs.docker-build.outputs.image-tag }} + + - name: Deploy AWS 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 }} + release: needs: [build, docker-build] runs-on: ubuntu-latest