version: '3.9'

services:
  db:
    image: postgres:16-alpine
    container_name: afilmory_db
    environment:
      POSTGRES_USER: afilmory
      POSTGRES_PASSWORD: afilmory
      POSTGRES_DB: afilmory
    ports:
      - '5432:5432'
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U $$POSTGRES_USER']
      interval: 5s
      timeout: 5s
      retries: 20
      start_period: 5s

  redis:
    image: redis:7-alpine
    container_name: afilmory_redis
    command: ['redis-server', '--appendonly', 'yes']
    ports:
      - '6379:6379'
    volumes:
      - redisdata:/data
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 3s
      retries: 30
      start_period: 5s

  core:
    container_name: afilmory_core
    build:
      context: .
      dockerfile: Dockerfile.core
      target: runner
    environment:
      NODE_ENV: production
      HOSTNAME: '0.0.0.0'
      PORT: '1841'
      DATABASE_URL: 'postgresql://afilmory:afilmory@db:5432/afilmory'
      REDIS_URL: 'redis://redis:6379/0'
      CONFIG_ENCRYPTION_KEY: '756256a24394342622db58ee05ee61a64a3ae14c22d4fe665b753cba0fa6333e'

    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    ports:
      - '1841:1841'
    restart: unless-stopped

volumes:
  pgdata:
  redisdata:
