Skip to content

Commit

Permalink
Merge pull request #1602 from cityofaustin/v2.4.0
Browse files Browse the repository at this point in the history
v2.4.0
  • Loading branch information
johnclary authored Nov 14, 2024
2 parents 164d63d + 778727b commit 457d064
Show file tree
Hide file tree
Showing 43 changed files with 944 additions and 276 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/aws-vz-api-helper.sh

This file was deleted.

51 changes: 39 additions & 12 deletions .github/workflows/build_docker_images.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: "Build Docker images and push to DockerHub"

on:
# Triggers the workflow on push or pull request events but only for the main and production branches
# and any updates to the etl scripts
push:
branches:
- main
Expand All @@ -12,16 +10,7 @@ on:
- "etl/afd_ems_import/**"
- "etl/cris_import/**"
- "etl/socrata_export/**"
pull_request:
branches:
- main
- production
paths:
- ".github/workflows/build_docker_images.yml"
- "etl/afd_ems_import/**"
- "etl/cris_import/**"
- "etl/socrata_export/**"
# Allows you to run this workflow manually from the Actions tab
- "api/**"
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -50,6 +39,8 @@ jobs:
- 'etl/cris_import/**'
socrata_export:
- 'etl/socrata_export/**'
user_cr3_api:
- 'api/**'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
Expand Down Expand Up @@ -80,3 +71,39 @@ jobs:
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
39 changes: 0 additions & 39 deletions .github/workflows/deploy_vz_api.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ env

# Zappa API deployment secrets
zappa_settings.json

env_file
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ See [here](docs/local_dev.md) for in-depth documentation about the `vision-zero`
- [Vision Zero Database (VZD)](./database/README.md) - the database that powers the Vision Zero suite
- [Vision Zero Editor (VZE)](./editor/README.md) - web application which enables City staff to browse and edit crash data
- [Vision Zero Viewer (VZV)](./viewer/README.md) - public dashboard which provides key metrics and insights about
- [atd-cr3-api](./atd-cr3-api/README.md) - our API that securely downloads a private file from S3
- [api](./api/README.md) - our API that securely downloads a private file from S3
- [etl](./etl/README.md) - integration scripts for bringing data in the Vision Zero Database
- [toolbox](./toolbox/README.md) - collection of utilities and scripts designed for ad-hoc maintenance tasks

Expand Down
3 changes: 3 additions & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
docker-compose.yaml
README.md
6 changes: 4 additions & 2 deletions atd-cr3-api/.env.example → api/.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
API_ENVIRONMENT="STAGING"
AUTH0_DOMAIN="atd-datatech.auth0.com"
CLIENT_ID="2qbqz2sf8L9idBOwn0d5YA9efNgQbL7c"
AWS_DEFALUT_REGION="us-east-1"
AWS_DEFAULT_REGION="us-east-1"
AWS_S3_CR3_LOCATION="staging/path_to_files"
AWS_S3_BUCKET="your_bucket_name_here"
AWS_S3_KEY="your_s3_key_here"
AWS_S3_SECRET="your_s3_secret_here"
AWS_S3_SECRET="your_s3_secret_here"
API_CLIENT_ID=
API_CLIENT_SECRET=
21 changes: 21 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.13-slim

# Set the working directory
WORKDIR /usr/src/app

# Install dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code
COPY . .

# Set environment variables
ENV FLASK_APP=server.py
ENV FLASK_ENV=development

# Expose the default Flask port
EXPOSE 5000

# Command to run the application
CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]
29 changes: 29 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# VZ User & CR3 API

## Big Picture

The API consists of a flask app which is bundled into a docker image and pushed to Docker Hub. It is deployed on AWS ECS as a service inside the VZ clusters. There is a `:production` and `:staging` version of the image, and these are built by CI on merger to the `production` and `main` branches respectively.

Our endpoints can be found at:

Staging: https://vision-zero-cr3-user-api-staging.austinmobility.io/

Production: https://vision-zero-cr3-user-api.austinmobility.io/

These flask apps are deployed as long-running tasks in ECS and are reverse proxy'd out to the internet by an AWS API gateway via a namespace / VPC link configuration. Specific deployment instructions for the COA deployment are contained in our internal documentation repositories.

## Local usage

You can start the API using either the project wide `docker compose` file with `docker compose up cr3-user-api` or if you prefer, you can use the `docker compose` stack that is concerned only with part of the stack as found in the `api` directory. Use whichever is best for your development needs. Additionally, you can use the `vision-zero` orchestration tool to `vision-zero api-up` and `vision-zero api-down` to start and stop the API.

## Configuration

The API requires certain environment variables to be set. Copy the `.env.example` file in the `api` directory to `.env` and fill in the values.

## Secrets

Please see the entry "Vision Zero (VZ) User & CR3 API Secrets" in the developers vault in 1PW for information about the secret values.

## Testing the API / Is this thing on?

Where ever you have the API running, you can hit it at the root of the domain `/` and you should get a health message that includes both the current time, but also the age of the process serving the API. This is helpful in confirming a restart has occurred, or that the API is up and running.
12 changes: 12 additions & 0 deletions api/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
api:
build:
context: .
ports:
- "5000:5000"
environment:
- FLASK_ENV=production
volumes:
- .:/usr/src/app
command: flask run --host=0.0.0.0 --port=5000
restart: unless-stopped
9 changes: 9 additions & 0 deletions api/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# pinning of major versions, allowing patch and minor updates.
# For example, for boto3, the ~= operator is equivalent to >=1.35.47, <1.36.0.

boto3~=1.35.47
Flask~=3.0.3
python-dotenv~=1.0.1
requests~=2.32.3
python-jose~=3.3.0
Flask-Cors~=5.0.0
Loading

0 comments on commit 457d064

Please sign in to comment.