services:
  db:
    image: "postgres:15.1-alpine3.17"
    volumes:
      - ./data/db:/var/lib/postgresql/data
    env_file: .env
    ports:
      - "5432:5432"
  redis:
    image: "redis:7.0.7-alpine3.17"
    command: redis-server
    volumes:
      - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
      - ./redis-data:/var/lib/redis
    environment:
      - REDIS_REPLICATION_MODE=master
  celery:
    build: .
    command: celery -A ptcoffee worker --loglevel=INFO
    env_file: .env
    volumes:
      - .:/app
    depends_on:
      - db
      - redis
  web:
    build: .
    command: sh -c "python manage.py migrate && python manage.py collectstatic --no-input && gunicorn --bind :8000 --reload ptcoffee.wsgi:application"
    volumes:
      - .:/app
      - ./static/:/var/www/static
      - ./media/:/var/www/media
    ports:
      - "8000:8000"
    env_file: .env
    depends_on:
      - redis
      - db
  nginx:
    image: "nginx:1.23.3-alpine"
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./static/:/var/www/static
      - ./media/:/var/www/media
      - ./nginx/${NGINX_CONF}:/etc/nginx/conf.d/default.conf
      - /var/www/html:/var/www/html
      - /etc/letsencrypt:/etc/letsencrypt
      - /var/lib/letsencrypt:/var/lib/letsencrypt
    depends_on:
      - web
