Deploy-staging-ecs #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy-staging-ecs | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tags: | |
| description: 'Set custom tag for image' | |
| required: true | |
| type: string | |
| environment: | |
| type: string | |
| required: true | |
| default: 'staging' | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - '.github/**' | |
| - '**.md' | |
| jobs: | |
| build-push-image: | |
| name: Build deploy image and push to registry | |
| runs-on: ubuntu-latest | |
| environment: ${{ inputs.environment }} | |
| timeout-minutes: ${{ vars.timeout_minutes || 30 }} | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| driver: docker-container | |
| - name: Configure AWS credentials (with OIDC or access keys) | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ vars.aws_role_to_assume || '' }} | |
| aws-region: ${{ vars.aws_region }} | |
| role-session-name: "github-actions-session" | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID || '' }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY || '' }} | |
| - name: Pull secrets from AWS SSM parameter store | |
| if: ${{ vars.ssm_param_store_prefix }} | |
| uses: infinum/[email protected] | |
| with: | |
| prefix: ${{ vars.ssm_param_store_prefix }} | |
| destination_path: ${{ vars.ssm_param_store_destination_path }} | |
| - name: Configure custom region for AWS ECR | |
| if: ${{ vars.aws_ecr_region != vars.aws_region }} | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: ${{ vars.aws_ecr_region }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| with: | |
| registries: ${{ vars.aws_ecr_account_id }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ vars.context || '.' }} | |
| platforms: ${{ vars.platforms || 'linux/amd64' }} | |
| provenance: ${{ vars.provenance || false }} | |
| file: ${{ vars.file || '' }} | |
| target: ${{ vars.target || ''}} | |
| push: true | |
| build-args: ${{ vars.build_args || '' }} | |
| tags: ${{ vars.aws_ecr_uri }}:${{ inputs.tags }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| secret-files: ${{ vars.secret_files || '' }} | |
| deploy-to-ecs: | |
| name: 'Deploy to ECS' | |
| runs-on: ubuntu-latest | |
| environment: ${{ inputs.environment }} | |
| timeout-minutes: ${{ vars.timeout_minutes || 30 }} | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ vars.aws_region }} | |
| - name: Fill in the new image ID in the Amazon ECS task definition | |
| id: gen-task-def | |
| uses: aws-actions/[email protected] | |
| with: | |
| task-definition: '.aws/ecs/task-definition-app-staging.json' | |
| container-name: 'js-react-example' | |
| image: ${{ vars.aws_ecr_uri }}:${{ inputs.tags }} | |
| - name: Deploy Amazon ECS task definition | |
| uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | |
| with: | |
| task-definition: ${{ steps.gen-task-def.outputs.task-definition }} | |
| service: 'js-react-example' | |
| cluster: ${{ vars.ecs_cluster }} | |
| wait-for-service-stability: true |