|
1 | 1 | name: Deploy |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: [main] |
6 | | - workflow_dispatch: |
7 | | - inputs: |
8 | | - environment: |
9 | | - description: Target environment |
10 | | - required: true |
11 | | - default: production |
12 | | - type: choice |
13 | | - options: [production, staging] |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + environment: |
| 9 | + description: Target environment |
| 10 | + required: true |
| 11 | + default: production |
| 12 | + type: choice |
| 13 | + options: [production, staging] |
14 | 14 |
|
15 | 15 | env: |
16 | | - AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }} |
17 | | - ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY_POST_WORKER || 'backendworks/post-worker' }} |
18 | | - ECS_CLUSTER: ${{ vars.ECS_CLUSTER || 'backendworks' }} |
19 | | - ECS_SERVICE: ${{ vars.ECS_SERVICE_POST_WORKER || 'post-worker' }} |
20 | | - CONTAINER_NAME: bw-post-worker |
| 16 | + AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }} |
| 17 | + ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY_POST_WORKER || 'backendworks/post-worker' }} |
| 18 | + ECS_CLUSTER: ${{ vars.ECS_CLUSTER || 'backendworks' }} |
| 19 | + ECS_SERVICE: ${{ vars.ECS_SERVICE_POST_WORKER || 'post-worker' }} |
| 20 | + CONTAINER_NAME: bw-post-worker |
21 | 21 |
|
22 | 22 | jobs: |
23 | | - deploy: |
24 | | - name: Build & Deploy to AWS ECS |
25 | | - runs-on: ubuntu-latest |
26 | | - environment: ${{ github.event.inputs.environment || 'production' }} |
| 23 | + deploy: |
| 24 | + name: Build & Deploy to AWS ECS |
| 25 | + runs-on: ubuntu-latest |
| 26 | + environment: ${{ github.event.inputs.environment || 'production' }} |
27 | 27 |
|
28 | | - permissions: |
29 | | - id-token: write # OIDC token for AWS auth |
30 | | - contents: read |
| 28 | + permissions: |
| 29 | + id-token: write # OIDC token for AWS auth |
| 30 | + contents: read |
31 | 31 |
|
32 | | - steps: |
33 | | - - name: Checkout |
34 | | - uses: actions/checkout@v4 |
| 32 | + steps: |
| 33 | + - name: Checkout |
| 34 | + uses: actions/checkout@v4 |
35 | 35 |
|
36 | | - - name: Setup Node |
37 | | - uses: actions/setup-node@v4 |
38 | | - with: |
39 | | - node-version: 20 |
| 36 | + - name: Setup Node |
| 37 | + uses: actions/setup-node@v4 |
| 38 | + with: |
| 39 | + node-version: 20 |
40 | 40 |
|
41 | | - - name: Install dependencies |
42 | | - run: yarn install --frozen-lockfile |
43 | | - env: |
44 | | - NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 41 | + - name: Install dependencies |
| 42 | + run: yarn install --frozen-lockfile |
| 43 | + env: |
| 44 | + NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }} |
45 | 45 |
|
46 | | - - name: Build application |
47 | | - run: npm run build |
| 46 | + - name: Build application |
| 47 | + run: npm run build |
48 | 48 |
|
49 | | - - name: Configure AWS credentials (OIDC) |
50 | | - uses: aws-actions/configure-aws-credentials@v4 |
51 | | - with: |
52 | | - role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }} |
53 | | - aws-region: ${{ env.AWS_REGION }} |
| 49 | + - name: Configure AWS credentials (OIDC) |
| 50 | + uses: aws-actions/configure-aws-credentials@v4 |
| 51 | + with: |
| 52 | + role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }} |
| 53 | + aws-region: ${{ env.AWS_REGION }} |
54 | 54 |
|
55 | | - - name: Login to Amazon ECR |
56 | | - id: login-ecr |
57 | | - uses: aws-actions/amazon-ecr-login@v2 |
| 55 | + - name: Login to Amazon ECR |
| 56 | + id: login-ecr |
| 57 | + uses: aws-actions/amazon-ecr-login@v2 |
58 | 58 |
|
59 | | - - name: Build, tag & push Docker image |
60 | | - id: build-image |
61 | | - env: |
62 | | - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
63 | | - IMAGE_TAG: ${{ github.sha }} |
64 | | - run: | |
65 | | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . |
66 | | - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ |
67 | | - $ECR_REGISTRY/$ECR_REPOSITORY:latest |
68 | | - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
69 | | - docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest |
70 | | - echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> "$GITHUB_OUTPUT" |
| 59 | + - name: Build, tag & push Docker image |
| 60 | + id: build-image |
| 61 | + env: |
| 62 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 63 | + IMAGE_TAG: ${{ github.sha }} |
| 64 | + run: | |
| 65 | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . |
| 66 | + docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ |
| 67 | + $ECR_REGISTRY/$ECR_REPOSITORY:latest |
| 68 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 69 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest |
| 70 | + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> "$GITHUB_OUTPUT" |
71 | 71 |
|
72 | | - - name: Download current ECS task definition |
73 | | - run: | |
74 | | - aws ecs describe-task-definition \ |
75 | | - --task-definition ${{ env.ECS_SERVICE }} \ |
76 | | - --query taskDefinition > task-definition.json |
| 72 | + - name: Download current ECS task definition |
| 73 | + run: | |
| 74 | + aws ecs describe-task-definition \ |
| 75 | + --task-definition ${{ env.ECS_SERVICE }} \ |
| 76 | + --query taskDefinition > task-definition.json |
77 | 77 |
|
78 | | - - name: Update task definition with new image |
79 | | - id: task-def |
80 | | - uses: aws-actions/amazon-ecs-render-task-definition@v1 |
81 | | - with: |
82 | | - task-definition: task-definition.json |
83 | | - container-name: ${{ env.CONTAINER_NAME }} |
84 | | - image: ${{ steps.build-image.outputs.image }} |
| 78 | + - name: Update task definition with new image |
| 79 | + id: task-def |
| 80 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 81 | + with: |
| 82 | + task-definition: task-definition.json |
| 83 | + container-name: ${{ env.CONTAINER_NAME }} |
| 84 | + image: ${{ steps.build-image.outputs.image }} |
85 | 85 |
|
86 | | - - name: Deploy to ECS |
87 | | - uses: aws-actions/amazon-ecs-deploy-task-definition@v2 |
88 | | - with: |
89 | | - task-definition: ${{ steps.task-def.outputs.task-definition }} |
90 | | - service: ${{ env.ECS_SERVICE }} |
91 | | - cluster: ${{ env.ECS_CLUSTER }} |
92 | | - wait-for-service-stability: true |
| 86 | + - name: Deploy to ECS |
| 87 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v2 |
| 88 | + with: |
| 89 | + task-definition: ${{ steps.task-def.outputs.task-definition }} |
| 90 | + service: ${{ env.ECS_SERVICE }} |
| 91 | + cluster: ${{ env.ECS_CLUSTER }} |
| 92 | + wait-for-service-stability: true |
0 commit comments