Skip to content

Deploy to ECS

Deploy to ECS #725

Workflow file for this run

name: Deploy to ECS
on:
schedule:
- cron: '0 1 * * *'
workflow_dispatch:
inputs:
environment:
type: environment
required: true
default: staging
push:
branches: main
jobs:
build:
name: Build/push Docker Image
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
environment: ${{ github.event.inputs.environment || 'staging' }}
concurrency: ${{ github.event.inputs.environment || 'staging' }}
outputs:
docker-tag-suffix: ${{ steps.build-push.outputs.docker-tag-suffix }}
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Fetch LFS objects
run: git lfs checkout
- uses: mbta/actions/build-push-ecr@v2
id: build-push
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
docker-repo: ${{ secrets.DOCKER_REPO }}
docker-additional-args: --build-arg SENTRY_DSN=${{ vars.SENTRY_DSN }}
deploy_ecs:
name: Deploy (ECS)
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write
contents: read
environment: ${{ github.event.inputs.environment || 'staging' }}
env:
ECS_CLUSTER: ride-along
ECS_SERVICE: ride-along-${{ github.event.inputs.environment || 'staging' }}
steps:
- uses: mbta/actions/deploy-ecs@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
ecs-cluster: ${{ env.ECS_CLUSTER }}
ecs-service: ${{ env.ECS_SERVICE }}
docker-tag: ${{ secrets.DOCKER_REPO }}:${{ needs.build.outputs.docker-tag-suffix }}
deploy_onprem:
name: Deploy (on-prem)
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write
contents: read
environment: ${{ github.event.inputs.environment || 'staging' }}
env:
ONPREM_SERVICE: ride-along-onprem-${{ github.event.inputs.environment || 'staging' }}
steps:
- name: Use linux-staging for non-prod environments
if: env.ONPREM_SERVICE != 'ride-along-onprem-prod'
run: echo "ONPREM_CLUSTER=linux-staging" >> "$GITHUB_ENV"
- name: Use linux-prod for prod environment
if: env.ONPREM_SERVICE == 'ride-along-onprem-prod'
run: echo "ONPREM_CLUSTER=linux-prod" >> "$GITHUB_ENV"
- uses: mbta/actions/deploy-ecs@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
ecs-cluster: ${{ env.ONPREM_CLUSTER }}
ecs-service: ${{ env.ONPREM_SERVICE }}
docker-tag: ${{ secrets.DOCKER_REPO }}:${{ needs.build.outputs.docker-tag-suffix }}
launch-type: EXTERNAL
notify:
name: Notify
runs-on: ubuntu-latest
needs: [deploy_ecs, deploy_onprem]
if: always()
steps:
- uses: mbta/actions/notify-slack-deploy@v2
if: ${{ !cancelled() }}
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK }}
job-status: ${{ job.status }}