Skip to content

Commit

Permalink
Merge branch 'main' into silopolis/docs_setup
Browse files Browse the repository at this point in the history
  • Loading branch information
silopolis authored Dec 29, 2023
2 parents d77c066 + 23eb084 commit 6e2cfa4
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
45 changes: 45 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Application local development environment setup


To ease daily local development and testing, the application, together with its database and proxy, can be launched and managed using Docker Compose.

Docker and Docker Compose must be installed and working on the local machine.

- **Clone repository**

```console
git clone https://github.com/DevOps-Boot/fastapi-k8s.git
```

- **Change to dev directory**

```console
cd fastapi-k8s/dev/
```

- **Launch the application**

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

To relaunch the application as code changes, the environment must be restarted and rebuilt:

```console
docker compose stop
docker compose up --build -d
```

Once application is launched:

* 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 connect directly to the database CLI, use the following command:

```console
docker exec -it docker-db-1 psql -U fastapi_traefik -d fastapi_traefik
```
47 changes: 47 additions & 0 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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/
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: [email protected]
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:

0 comments on commit 6e2cfa4

Please sign in to comment.