Skip to content

Commit

Permalink
Creating simple dev environment using docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
gitkvark committed Dec 26, 2023
1 parent 9edc2be commit 19901a8
Show file tree
Hide file tree
Showing 3 changed files with 10,073 additions and 0 deletions.
25 changes: 25 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## To launch

```
docker compose up --build -d
```

## To connect to the database:

```
docker exec -it docker-db-1 psql -U fastapi_traefik -d fastapi_traefik
```

The FastAPI application is available at ```http://localhost:8008```

Traefik interface is available at ```http://localhost:8081```

PgAdmin4 is available at ```http://localhost:8888```

## To import data from data set

> To be executed only once as the postgres server container has a persistent volume attached to it.
```
fastapi_traefik=# \COPY gladiators (name, age, birth_year, origin, height, weight, category, wins, losses, special_skills, weapon_of_choice, patron_wealth, equipment_quality, public_favor, injury_history, mental_resilience, diet_and_nutrition, tactical_knowledge, allegiance_network, battle_experience, psychological_profile, health_status, personal_motivation, previous_occupation, training_intensity, battle_strategy, social_standing, crowd_appeal_techniques, survived) FROM '/gladiator_data.csv' DELIMITER ',' CSV HEADER;
```
48 changes: 48 additions & 0 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '3.8'

services:
web:
build: ../app
command: '-m uvicorn app.main:app --host 0.0.0.0'
volumes:
- ..:/app
expose:
- 8000
environment:
- DATABASE_URL=postgresql://fastapi_traefik:fastapi_traefik@db:5432/fastapi_traefik
depends_on:
- db
labels:
- "traefik.enable=true"
- "traefik.http.routers.fastapi.rule=Host(`fastapi.localhost`)"
db:
image: postgres:15-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
- ./gladiator_data.csv:/gladiator_data.csv
expose:
- 5432
environment:
- POSTGRES_USER=fastapi_traefik
- POSTGRES_PASSWORD=fastapi_traefik
- POSTGRES_DB=fastapi_traefik
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin4_container
restart: always
ports:
- "127.0.0.1:8888:80"
environment:
PGADMIN_DEFAULT_EMAIL: user@domain-name.com
PGADMIN_DEFAULT_PASSWORD: strong-password
traefik:
image: traefik:v2.9.6
ports:
- 127.0.0.1:8008:80
- 127.0.0.1:8081:8080
volumes:
- "../traefik/traefik.dev.toml:/etc/traefik/traefik.toml"
- "/var/run/docker.sock:/var/run/docker.sock:ro"

volumes:
postgres_data:
Loading

0 comments on commit 19901a8

Please sign in to comment.