version: '3.8'

services:
  app:
    image: drugstone_backend
    container_name: drugstone_backend
    command: 
      - "sh"
      - "scripts/docker-entrypoint.sh"
    build: .
    env_file:
      - 'docker-django.env.dev'
    restart: always
    volumes:
      - drugstone_db_schema_volume:/usr/src/drugstone/drugstone/migrations
      - drugstone_data_volume:/usr/src/drugstone/data
    ports:
      - 8001:8000
    networks:
      - drugstone_net
    depends_on:
      - db
      - redis
  db:
    image: postgres
    container_name: drugstone_postgres
    restart: always
    hostname: drugstone_postgres
    ports:
      - 5432:5432
    networks:
      - drugstone_net
    volumes:
      - drugstone_db_volume:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=drugstone
      - POSTGRES_USER=drugstone
      - POSTGRES_PASSWORD=t6278yczAH7rPKVMxaDD
    command: 
      - "postgres"
      - "-c" 
      - "max_connections=10000"
      - "-c"
      - "shared_buffers=2GB"
  redis:
    image: redis
    container_name: drugstone_redis
    restart: always
    command: ["redis-server"]
    networks:
      - drugstone_net
    ports:
      - 6379:6379
  celery:
    command: 
      - "sh"
      - "scripts/start_celery_worker.sh"
    restart: always
    image: drugstone_backend
    container_name: drugstone_celery
    hostname: drugstone_celery
    env_file:
      - './docker-django.env.dev'
    depends_on:
      - redis
      - db
    networks:
      - drugstone_net
  celery-beat:
    command: 
      - "sh"
      - "scripts/start_celery_beat.sh"
    image: drugstone_backend
    container_name: drugstone_celery_beat
    hostname: drugstone_celery_beat
    env_file:
      - './docker-django.env.dev'
    depends_on:
      - redis
      - db
    networks:
      - drugstone_net
  flower:  
    image: mher/flower
    container_name: drugstone_flower
    env_file:
      - './docker-django.env.dev'
    ports:  
      - 8888:8888
    networks:
      - drugstone_net

networks:
  drugstone_net:

volumes:
  drugstone_db_volume:
    external: true
  drugstone_db_schema_volume:
    external: true
  drugstone_data_volume:
    external: true