Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 1.63 KB

installation_with_docker.md

File metadata and controls

67 lines (46 loc) · 1.63 KB

Install with Docker

Env file

Create .env file in root directory :

FASTAPI_ENV=development

PROJECT_NAME=PyShortener
APP_VERSION=1.0.0

DATABASE_USER=app
DATABASE_PASSWORD=password
DATABASE_URL=postgres-app
DATABASE_NAME=pyshortener
DATABASE_PORT=5432

REDIS_CONNECTION=True # Optional : Default False
REDIS_HOST=pyshortener-redis

PostgreSQL

Run a postgresql database in docker :

docker network create pyshortener
docker run -d --network pyshortener --name postgres-app -e POSTGRES_USER=app -e POSTGRES_DB=app -e POSTGRES_PASSWORD=password -e PGDATA=/var/lib/postgresql/data/pgdata -v pgdata:/var/lib/postgresql/data -p 5432:5432 postgres

(Optional) Redis

docker run -d --network pyshortener --name pyshortener-redis -v pyshortener-redis:/data -p 6379:6379 redis

Start FastAPI app

docker build . -f docker/dockerfile.dev -t app-fast-api:dev
docker run --rm --name fastapi --network fast-api --env-file app/config/.env -it -v $PWD:/app/fast-api/ -p 5555:5555 app-fast-api:dev

DO NOT USE dockerfile.dev FOR PRODUCTION. Use dockerfile.prod instead.

Database migration

If there is no migration file, or you need to generate a new one, execute these commands, use docker exec :

docker exec -it fastapi alembic revision --autogenerate -m "init"

Generate tables with Alembic

To apply your migration file to the database :

alembic upgrade head

In case of error : FAILED: Can't locate revision identified by '747e6da84866' you might delete entry in alembic_version table :

$ docker exec -it postgres-app psql -U app
DELETE FROM alembic_version;