Skip to content

Commit

Permalink
Refactor Dockerfile, docker-compose.yaml, config and README
Browse files Browse the repository at this point in the history
  • Loading branch information
madnoberson committed Mar 10, 2024
1 parent 1e7d68f commit 4664293
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 17 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ FROM base AS web_api

COPY --from=builder ./app/dist ./

RUN $(printf "pip install %s[web_api,cli]" amdb*.whl)
RUN $(printf "pip install %s[web_api]" amdb*.whl)

CMD ["amdb-web_api"]
CMD ["amdb", "web-api"]

FROM base AS worker

COPY --from=builder ./app/dist ./

RUN pip install amdb*.whl

CMD ["amdb", "worker"]
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,54 @@
* [Dishka](https://github.com/reagento/dishka) - DI framework
* [PostgreSQL](https://www.postgresql.org/)
* [Redis](https://redis.io/)


## How to run:

### Manually:

1. Install

```sh
pip install -e ".[web_api]"
```

2. Create [config](./config/prod_config.template.toml) file

3. Provide `CONFIG_PATH` env variable

4. Run migrations

```sh
amdb alembic upgrade head
```

5. Run worker

```sh
amdb worker
```

6. Run server

```sh
amdb web_api
```

### Using docker-compose:

1. Create [config](./config/prod_config.template.toml) file

2. Provide `CONFIG_PATH`, `REDIS_PASSWORD`, `REDIS_PORT_NUMBER`, `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_DB`, `SERVER_HOST`, `SERVER_PORT` env variables

3. Run worker and server

```sh
docker-compose up web_api
```

4. Run migrations

```sh
docker exec amdb_backend.web_api amdb alembic upgrade head
```
5 changes: 0 additions & 5 deletions config/prod_config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ url = "redis://:1234@127.0.0.1:6379/0"

[auth-session]
lifetime = 3600 # Minutes

[web-api]
version = "0.5.0"
host = "127.0.0.1"
port = 8000
33 changes: 23 additions & 10 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: "3"

services:
web_api:
profiles: [web_api]
profiles: [web_api, worker]
container_name: amdb_backend.web_api
depends_on: [postgres, redis]
ports: ["${UVICORN_HOST}:${UVICORN_PORT}:${UVICORN_PORT}"]
depends_on: [postgres, redis, worker]
ports: ["${SERVER_HOST:-0.0.0.0}:${SERVER_PORT:-8000}:8000"]
restart: unless-stopped

build:
Expand All @@ -15,23 +15,36 @@ services:
environment:
- CONFIG_PATH

worker:
profiles: [web_api, worker]
container_name: amdb_backend.worker
depends_on: [postgres, redis]
restart: unless-stopped

build:
context: ./
dockerfile: ./Dockerfile
target: worker
environment:
- CONFIG_PATH

postgres:
profiles: [web_api]
profiles: [web_api, worker]
container_name: amdb_backend.postgres
image: postgres:15-alpine
restart: unless-stopped

environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-1234}
- POSTGRES_DB=${POSTGRES_DB:-amdb}

redis:
profiles: [web_api]
profiles: [web_api, worker]
container_name: amdb_backend.redis
image: bitnami/redis:7.2
restart: unless-stopped

environment:
- REDIS_PASSWORD
- REDIS_PORT_NUMBER=${REDIS_PORT}
- REDIS_PASSWORD=${REDIS_PASSWORD:-1234}
- REDIS_PORT_NUMBER=${REDIS_PORT:-6379}

0 comments on commit 4664293

Please sign in to comment.