version: '3'
services:
  postgres:
    image: groonga/pgroonga:3.1.6-alpine-16-slim
    restart: unless-stopped
    environment:
      - POSTGRES_DB=kemono
      - POSTGRES_USER=kemono
      - POSTGRES_PASSWORD=kemono
    volumes:
      - ./storage/postgres:/var/lib/postgresql/data
    command: ["postgres", "-c", "log_statement=all"]
    ports:
      - '15432:5432'

  redis:
    image: redis:7-alpine
    restart: always
    ports:
      - '16379:6379'

  web:
    build:
      context: .
      args:
        GIT_COMMIT_HASH: "custom"
    restart: unless-stopped
    depends_on:
      - postgres
      - redis
    environment:
      - FLASK_ENV=development
      - KEMONO_SITE=http://localhost:5000
      - UPLOAD_LIMIT=2000000000
      - ARCHIVERHOST=kemono-archiver
      - ARCHIVERPORT=80
      - PYTHONUNBUFFERED=1
      - KEMONO_CONFIG=config.example.json
      - PYTHONPATH=/app
    volumes:
      - ./:/app
      - ./storage/files:/storage
    sysctls:
      net.core.somaxconn: 2000
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:80" ]
      interval: 60s
      timeout: 2m
      retries: 3
      start_period: 30s

    command:
      [ "python", "-m", "src", "run" ]

  nginx:
    image: nginx
    depends_on:
      - web
    ports:
      - '5000:80'
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./storage/files:/storage
      - ./:/app

  webpack:
    build:
      context: .
    restart: unless-stopped
    environment:
      - FLASK_ENV=development
      - KEMONO_SITE=http://localhost:5000
      - KEMONO_CONFIG=config.example.json
      - PYTHONPATH=/app
    volumes:
      - .:/app
    command:
      [ "python", "-m", "src", "webpack" ]
