Skip to content

๐Ÿ” Find all the States in the contiguous USA on a map. Simple enough.

License

Notifications You must be signed in to change notification settings

johndatserakis/find-the-state-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

35 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Find the State API

Find all the States in the contiguous USA on a map. Simple enough.

Run

# If your running this for the first time, make sure to run the migrations

# Start
docker-compose up -d --build

# Stop
docker-compose down

# Docker cleanup commands https://gist.github.com/johndatserakis/0002d9aded5778f9d0589a23ce1e08d4

Commands While Running

# Below are commands to be run when the containers are running locally with docker-comose

# Run migrations
docker-compose exec api poetry run alembic upgrade head

# Run tests
docker-compose exec api pytest .

# Run a specific script
docker-compose exec api python ./program_scripts/get_state_data.py

# Add a dependency
docker-compose exec api poetry add slowapi

# Create poetry.lock file
docker-compose exec api poetry lock

Alembic

# Create migration (called a "revision")
docker-compose exec api poetry run alembic revision -m "Create score table"

# Run migrations
docker-compose exec api poetry run alembic upgrade head

# Downgrade 1 migration file
docker-compose exec api poetry run alembic downgrade -1

# View list of migration files
docker-compose exec api poetry run alembic history
docker-compose exec api poetry run alembic downgrade $Id

View Running API

Build for Production

In development I use docker-compose because it sets up the PostgreSQL dependency nicely. For the production build, I just use a regular Dockerfile, ./app/Dockerfile-production, to build the API.

# Currently I'm using AWS ECR for the registry

# From root, build for production using `./app/Dockerfile-production` Dockerfile
docker build \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
-f ./app/Dockerfile-production ./app \
--build-arg POSTGRES_USER=$POSTGRES_USER \
--build-arg POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
--build-arg POSTGRES_HOST=$POSTGRES_HOST \
--build-arg POSTGRES_DB=$POSTGRES_DB

# Run what you built locally to test
docker run -dit --publish 8000:8000 --restart unless-stopped $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

# Lastly push to your container registry of choice
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

Built With

  • Python 3.8
  • FastAPI
  • SQLAlchemy
  • Alembic
  • pymediawiki
  • Poetry
  • PostgreSQL
  • slowapi

Notes

  • Below are some links I saved while learning Python.

Python

FastAPI

About

๐Ÿ” Find all the States in the contiguous USA on a map. Simple enough.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages