Comments (21)
Can you, please, show generated docker-compose?
from fastapi-template.
version: '3.9'
services:
api: &main_app
build:
context: .
dockerfile: ./deploy/Dockerfile
target: prod
image: hrm:${HRM_VERSION:-latest}
restart: always
env_file:
- .env
labels:
# Enables traefik for this container.
- traefik.enable=true
- traefik.http.routers.hrm.rule=Host(${HRM_TRAEFIK_HOST:-hrm.localhost}
)
- traefik.http.routers.hrm.entrypoints=http
- traefik.http.routers.hrm.service=hrm
- traefik.http.services.hrm.loadbalancer.server.port=${HRM_PORT:-8000}
networks:
- default
- traefik-shared
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
kafka:
condition: service_healthy
environment:
HRM_HOST: 0.0.0.0
HRM_DB_HOST: hrm-db
HRM_DB_PORT: 5432
HRM_DB_USER: hrm
HRM_DB_PASS: hrm
HRM_DB_BASE: hrm
HRM_REDIS_HOST: hrm-redis
TESTKAFKA_KAFKA_BOOTSTRAP_SERVERS: '["hrm-kafka:9092"]'
taskiq-worker:
<<: *main_app
labels: []
command:
- taskiq
- worker
- hrm.tkq:broker
db:
image: postgres:13.8-bullseye
hostname: hrm-db
environment:
POSTGRES_PASSWORD: "hrm"
POSTGRES_USER: "hrm"
POSTGRES_DB: "hrm"
volumes:
- hrm-db-data:/var/lib/postgresql/data
restart: always
healthcheck:
test: pg_isready -U hrm
interval: 2s
timeout: 3s
retries: 40
migrator:
image: hrm:${HRM_VERSION:-latest}
restart: "no"
command: alembic upgrade head
environment:
HRM_DB_HOST: hrm-db
HRM_DB_PORT: 5432
HRM_DB_USER: hrm
HRM_DB_PASS: hrm
HRM_DB_BASE: hrm
depends_on:
db:
condition: service_healthy
redis:
image: bitnami/redis:6.2.5
hostname: "hrm-redis"
restart: always
environment:
ALLOW_EMPTY_PASSWORD: "yes"
healthcheck:
test: redis-cli ping
interval: 1s
timeout: 3s
retries: 50
zookeeper:
image: "bitnami/zookeeper:3.7.1"
hostname: "hrm-zookeeper"
environment:
ALLOW_ANONYMOUS_LOGIN: "yes"
ZOO_LOG_LEVEL: "ERROR"
healthcheck:
test: zkServer.sh status
interval: 1s
timeout: 3s
retries: 30
kafka:
image: "bitnami/kafka:3.2.0"
hostname: "hrm-kafka"
environment:
KAFKA_BROKER_ID: "1"
ALLOW_PLAINTEXT_LISTENER: "yes"
KAFKA_CFG_LISTENERS: "PLAINTEXT://0.0.0.0:9092"
KAFKA_CFG_ADVERTISED_LISTENERS: "PLAINTEXT://hrm-kafka:9092"
KAFKA_CFG_ZOOKEEPER_CONNECT: "hrm-zookeeper:2181"
healthcheck:
test: kafka-topics.sh --list --bootstrap-server localhost:9092
interval: 1s
timeout: 3s
retries: 30
depends_on:
zookeeper:
condition: service_healthy
volumes:
hrm-db-data:
name: hrm-db-data
networks:
Network for traefik.
traefik-shared:
name: traefik-shared
from fastapi-template.
It also throws the following error on startup: (hrm-py3.10) lab42@lab42-Linux:~/Рабочий стол/dev/hrm$ sudo docker-compose -f deploy/docker-compose.dev.yml --project-directory . up --build
ERROR: The Compose file is invalid because:
Service api has neither an image nor a build context specified. At least one must be provided.
version: '3.9'
services:
api:
ports:
# Exposes application port.
- "8000:8000"
build:
target: dev
volumes:
# Adds current directory as volume.
- .:/app/src/
environment:
# Enables autoreload.
HRM_RELOAD: "True"
taskiq-worker:
volumes:
# Adds current directory as volume.
- .:/app/src/
command:
- taskiq
- worker
- hrm.tkq:broker
- --reload
from fastapi-template.
Can you wrap your code into blocks?
```yaml {your-code here} ```
from fastapi-template.
version: '3.9'
services:
api: &main_app
build:
context: .
dockerfile: ./deploy/Dockerfile
target: prod
image: hrm:${HRM_VERSION:-latest}
restart: always
env_file:
- .env
labels:
# Enables traefik for this container.
- traefik.enable=true
- traefik.http.routers.hrm.rule=Host(`${HRM_TRAEFIK_HOST:-hrm.localhost}`)
- traefik.http.routers.hrm.entrypoints=http
- traefik.http.routers.hrm.service=hrm
- traefik.http.services.hrm.loadbalancer.server.port=${HRM_PORT:-8000}
networks:
- default
- traefik-shared
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
kafka:
condition: service_healthy
environment:
HRM_HOST: 0.0.0.0
HRM_DB_HOST: hrm-db
HRM_DB_PORT: 5432
HRM_DB_USER: hrm
HRM_DB_PASS: hrm
HRM_DB_BASE: hrm
HRM_REDIS_HOST: hrm-redis
TESTKAFKA_KAFKA_BOOTSTRAP_SERVERS: '["hrm-kafka:9092"]'
taskiq-worker:
<<: *main_app
labels: []
command:
- taskiq
- worker
- hrm.tkq:broker
db:
image: postgres:13.8-bullseye
hostname: hrm-db
environment:
POSTGRES_PASSWORD: "hrm"
POSTGRES_USER: "hrm"
POSTGRES_DB: "hrm"
volumes:
- hrm-db-data:/var/lib/postgresql/data
restart: always
healthcheck:
test: pg_isready -U hrm
interval: 2s
timeout: 3s
retries: 40
migrator:
image: hrm:${HRM_VERSION:-latest}
restart: "no"
command: alembic upgrade head
environment:
HRM_DB_HOST: hrm-db
HRM_DB_PORT: 5432
HRM_DB_USER: hrm
HRM_DB_PASS: hrm
HRM_DB_BASE: hrm
depends_on:
db:
condition: service_healthy
redis:
image: bitnami/redis:6.2.5
hostname: "hrm-redis"
restart: always
environment:
ALLOW_EMPTY_PASSWORD: "yes"
healthcheck:
test: redis-cli ping
interval: 1s
timeout: 3s
retries: 50
zookeeper:
image: "bitnami/zookeeper:3.7.1"
hostname: "hrm-zookeeper"
environment:
ALLOW_ANONYMOUS_LOGIN: "yes"
ZOO_LOG_LEVEL: "ERROR"
healthcheck:
test: zkServer.sh status
interval: 1s
timeout: 3s
retries: 30
kafka:
image: "bitnami/kafka:3.2.0"
hostname: "hrm-kafka"
environment:
KAFKA_BROKER_ID: "1"
ALLOW_PLAINTEXT_LISTENER: "yes"
KAFKA_CFG_LISTENERS: "PLAINTEXT://0.0.0.0:9092"
KAFKA_CFG_ADVERTISED_LISTENERS: "PLAINTEXT://hrm-kafka:9092"
KAFKA_CFG_ZOOKEEPER_CONNECT: "hrm-zookeeper:2181"
healthcheck:
test: kafka-topics.sh --list --bootstrap-server localhost:9092
interval: 1s
timeout: 3s
retries: 30
depends_on:
zookeeper:
condition: service_healthy
volumes:
hrm-db-data:
name: hrm-db-data
networks:
# Network for traefik.
traefik-shared:
name: traefik-shared
from fastapi-template.
The docker-compose.dev.yaml
should be used along with the main file. Like this:
docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up --build
from fastapi-template.
version: '3.9'
services:
api:
ports:
# Exposes application port.
- "8000:8000"
build:
target: dev
volumes:
# Adds current directory as volume.
- .:/app/src/
environment:
# Enables autoreload.
HRM_RELOAD: "True"
taskiq-worker:
volumes:
# Adds current directory as volume.
- .:/app/src/
command:
- taskiq
- worker
- hrm.tkq:broker
- --reload
(hrm-py3.10) lab42@lab42-Linux:~/Рабочий стол/dev/hrm$ sudo docker-compose -f deploy/docker-compose.dev.yml --project-directory . up --build
ERROR: The Compose file is invalid because:
Service api has neither an image nor a build context specified. At least one must be provided.
from fastapi-template.
What docker version are you using?
I guess it has some problems finding your image. Please try building image before running it. Maybe it would help.
docker-compose -f deploy/docker-compose.yml --project-directory . build
docker-compose -f deploy/docker-compose.yml --project-directory . up
from fastapi-template.
Docker version 23.0.2, build 569dd73
from fastapi-template.
Consider upgrading it to 24+. Just to make sure. But still, it should work fine on 23+.
from fastapi-template.
This postgresql image works fine on my computer. Can you have access problems to hub.docker.com?
❯ docker run --rm -it postgres:13.8-bullseye
Unable to find image 'postgres:13.8-bullseye' locally
13.8-bullseye: Pulling from library/postgres
e9995326b091: Already exists
a0cb03f17886: Already exists
bb26f7e78134: Already exists
c8e073b7ae91: Already exists
99b5b1679915: Already exists
55c520fc03c5: Pull complete
d0ac84d6672c: Pull complete
4effb95d5849: Pull complete
97fd2548fc1e: Pull complete
43e7f13e3769: Pull complete
2898936d5b2e: Pull complete
b4b731b0864d: Pull complete
fbd79522dd4c: Pull complete
Digest: sha256:2b31dc28ab2a687bb191e66e69c2534c9c74107ddb3192ff22a04de386425905
Status: Downloaded newer image for postgres:13.8-bullseye
Error: Database is uninitialized and superuser password is not specified.
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
connections without a password. This is *not* recommended.
See PostgreSQL documentation about "trust":
https://www.postgresql.org/docs/current/auth-trust.html
from fastapi-template.
When I run the command: docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up --build
it runs containers and throws an error:
taskiq-worker_1 | ValueError: To use '--reload' flag, please install 'taskiq[reload]'.
and if I run only dev, then it gives an error:
(hrm-py3.10) lab42@lab42-Linux:~/Desktop/dev/hrm$ sudo docker-compose -f deploy/docker-compose.dev.yml --project-directory . up --build
ERROR: Compose file is invalid because:
Service api has neither an image nor a build context specified. At least one must be provided.
from fastapi-template.
Taskiq moved some dependencies to extras.
Can you replace your taskiq
entry from pyproject toml with taskiq = {version = "^0", extras = ["reload"]}
After that, update your poetry.lock by running poetry update
.
It should fix it.
from fastapi-template.
So how do I run dev? sudo docker-compose -f deploy/docker-compose.dev.yml --project-directory . up --build
ERROR: The Compose file is invalid because:
Service api has neither an image nor a build context specified. At least one must be provided.
from fastapi-template.
As I showed you above. #174 (comment)
from fastapi-template.
Taskiq moved some dependencies to extras.
Can you replace your
taskiq
entry from pyproject toml withtaskiq = {version = "^0", extras = ["reload"]}
After that, update your poetry.lock by running
poetry update
.It should fix it.
In payproject I have exactly this version: taskiq = { version = "^0", extras = ["reload"] }
from fastapi-template.
Can you try building image with dev compose file for dev?
docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . build
from fastapi-template.
The migrator container does not start and gives an error: hrm_migrator_1 exited with code 0
what command should I run only dev and what prod?
from fastapi-template.
No, that's okay. 0 code means Everything worked fine and all migrations ran successfully
.
from fastapi-template.
The migrator is a container that only runs migrations and shuts down. You should run it before rolling out new version of the application. It will apply all migrations and then you can start your application.
from fastapi-template.
However, in docker-compose configuration migrator runs automatically, when you start it.
from fastapi-template.
Related Issues (20)
- Where to set sqlalchemy.url for alembic? HOT 2
- How to swap out Pydantic-settings HOT 2
- RMQ Consumer HOT 1
- alembic upgrade head failed: ModuleNotFoundError: No module named 'pydantic_settings' HOT 2
- TypeError: 'type' object is not subscriptable HOT 2
- Alembic supports HOT 3
- Loguru startup error HOT 12
- Taskiq Mypy validation error HOT 1
- pytest is not working with kafka HOT 3
- Docker Conflict. The container name "/buildx_buildkit_default" HOT 3
- How setup VSC launch.json for run debugging app HOT 1
- Add Ruff HOT 2
- RuntimeError After Pytest Completion
- ImportError: cannot import name 'auth_cookie' HOT 3
- PEP 604 Optional[] HOT 3
- Please add NATS support HOT 1
- Unable to locate GCC
- Mac m1, do not progress HOT 1
- feat: Add Support for PDM
- Fast api
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastapi-template.