Git Product home page Git Product logo

Comments (21)

s3rius avatar s3rius commented on June 8, 2024

Can you, please, show generated docker-compose?

from fastapi-template.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024

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.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024

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.

s3rius avatar s3rius commented on June 8, 2024

Can you wrap your code into blocks?

 
```yaml
{your-code here}
```

from fastapi-template.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024
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.

s3rius avatar s3rius commented on June 8, 2024

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.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024
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.

s3rius avatar s3rius commented on June 8, 2024

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.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024

Docker version 23.0.2, build 569dd73

from fastapi-template.

s3rius avatar s3rius commented on June 8, 2024

Consider upgrading it to 24+. Just to make sure. But still, it should work fine on 23+.

from fastapi-template.

s3rius avatar s3rius commented on June 8, 2024

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.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024

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.

s3rius avatar s3rius commented on June 8, 2024

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.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024

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.

s3rius avatar s3rius commented on June 8, 2024

As I showed you above. #174 (comment)

from fastapi-template.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024

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.

In payproject I have exactly this version: taskiq = { version = "^0", extras = ["reload"] }

from fastapi-template.

s3rius avatar s3rius commented on June 8, 2024

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.

shpilevskiyevgeniy avatar shpilevskiyevgeniy commented on June 8, 2024

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.

s3rius avatar s3rius commented on June 8, 2024

No, that's okay. 0 code means Everything worked fine and all migrations ran successfully.

from fastapi-template.

s3rius avatar s3rius commented on June 8, 2024

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.

s3rius avatar s3rius commented on June 8, 2024

However, in docker-compose configuration migrator runs automatically, when you start it.

from fastapi-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.