Migrate the VZ User and CR3 API into our VZ ECS cluster with an API gateway setup #234
Workflow file for this run
This file contains 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: "Build Docker images and push to DockerHub" | |
on: | |
push: | |
branches: | |
- main | |
- production | |
paths: | |
- ".github/workflows/build_docker_images.yml" | |
- "etl/afd_ems_import/**" | |
- "etl/cris_import/**" | |
- "etl/socrata_export/**" | |
- "api/**" | |
pull_request: | |
branches: | |
- main | |
- production | |
paths: | |
- ".github/workflows/build_docker_images.yml" | |
- "etl/afd_ems_import/**" | |
- "etl/cris_import/**" | |
- "etl/socrata_export/**" | |
- "api/**" | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build docker images | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: "Checkout" | |
uses: actions/checkout@v4 | |
- name: "Paths filter" | |
uses: dorny/paths-filter@v3 | |
id: changes | |
with: | |
base: ${{ github.ref }} | |
filters: | | |
afd_ems: | |
- 'etl/afd_ems_import/**' | |
cris: | |
- 'etl/cris_import/**' | |
socrata_export: | |
- 'etl/socrata_export/**' | |
user_cr3_api: | |
- 'api/**' | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push AFD / EMS image | |
if: steps.changes.outputs.afd_ems == 'true' | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
context: etl/afd_ems_import | |
push: true | |
tags: atddocker/vz-afd-ems-import:${{ github.ref == 'refs/heads/production' && 'production' || 'latest' }} | |
- name: Build and push CRIS import image | |
if: steps.changes.outputs.cris == 'true' | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
context: etl/cris_import | |
push: true | |
tags: atddocker/vz-cris-import:${{ github.ref == 'refs/heads/production' && 'production' || 'latest' }} | |
- name: Build and push Socrata export image | |
if: steps.changes.outputs.socrata_export == 'true' | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
context: etl/socrata_export | |
push: true | |
tags: atddocker/vz-socrata-export:${{ github.ref == 'refs/heads/production' && 'production' || 'development' }} | |
- name: Build and push VZ User & CR3 API image | |
if: steps.changes.outputs.user_cr3_api == 'true' | |
uses: docker/build-push-action@v4 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
context: api | |
push: true | |
tags: atddocker/vz-user-cr3-api:${{ github.ref == 'refs/heads/production' && 'production' || 'latest' }} | |
- name: Set environment for ECS update | |
if: steps.changes.outputs.user_cr3_api == 'true' | |
run: | | |
if [ "${{ github.ref }}" == "refs/heads/production" ]; then | |
echo "ECS_CLUSTER=atd-vz-data-cluster-production" >> $GITHUB_ENV | |
echo "ECS_SERVICE=arn:aws:ecs:us-east-1:295525487728:service/atd-vz-data-cluster-production/cr3-and-user-mgmt-api" >> $GITHUB_ENV | |
else | |
echo "ECS_CLUSTER=atd-vz-data-cluster-staging" >> $GITHUB_ENV | |
echo "ECS_SERVICE=arn:aws:ecs:us-east-1:295525487728:service/atd-vz-data-cluster-staging/cr3-and-user-mgmt-api" >> $GITHUB_ENV | |
fi | |
- name: Restart ECS service | |
if: steps.changes.outputs.user_cr3_api == 'true' | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_ECS_CONTROL }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_ID_ECS_CONTROL }} | |
AWS_DEFAULT_REGION: "us-east-1" | |
ECS_CLUSTER: ${{ env.ECS_CLUSTER }} | |
ECS_SERVICE: ${{ env.ECS_SERVICE }} | |
run: | | |
sleep 30 | |
aws ecs update-service \ | |
--cluster $ECS_CLUSTER \ | |
--service $ECS_SERVICE \ | |
--force-new-deployment |