|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +permissions: |
| 4 | + id-token: write |
| 5 | + contents: read |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - 'release/pr-v*' |
| 12 | + |
| 13 | +jobs: |
| 14 | + deploy: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + environment: ${{ inputs.deploy-env || (github.ref_name == 'main' && 'Development') || (startsWith(github.ref_name, 'release/pr-v') && 'Production') || 'None' }} |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - uses: aws-actions/configure-aws-credentials@v4 |
| 22 | + with: |
| 23 | + role-to-assume: ${{ vars.PIPELINE_ROLE_ARN }} |
| 24 | + aws-region: ${{ vars.AWS_REGION }} |
| 25 | + |
| 26 | + - uses: aws-actions/amazon-ecr-login@v2 |
| 27 | + |
| 28 | + - name: Build and push image |
| 29 | + id: build |
| 30 | + run: | |
| 31 | + IMAGE_TAG=${{ github.sha }} |
| 32 | + docker build -t ${{ vars.ECR_URL }}:$IMAGE_TAG . |
| 33 | + docker push ${{ vars.ECR_URL }}:$IMAGE_TAG |
| 34 | + echo "image=${{ vars.ECR_URL }}:$IMAGE_TAG" >> $GITHUB_OUTPUT |
| 35 | +
|
| 36 | + - name: Get current task definition |
| 37 | + run: | |
| 38 | + aws ecs describe-task-definition \ |
| 39 | + --task-definition ${{ vars.TASK_FAMILY }} \ |
| 40 | + --query taskDefinition \ |
| 41 | + > task-definition.json |
| 42 | +
|
| 43 | + - name: Update image in task definition |
| 44 | + id: render |
| 45 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 46 | + with: |
| 47 | + task-definition: task-definition.json |
| 48 | + container-name: ${{ vars.CONTAINER_NAME }} |
| 49 | + image: ${{ steps.build.outputs.image }} |
| 50 | + |
| 51 | + - name: Deploy to ECS |
| 52 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v2 |
| 53 | + with: |
| 54 | + task-definition: ${{ steps.render.outputs.task-definition }} |
| 55 | + service: ${{ vars.ECS_SERVICE }} |
| 56 | + cluster: ${{ vars.ECS_CLUSTER }} |
| 57 | + wait-for-service-stability: true |
0 commit comments