services:
  db:
    image: postgres:18
    container_name: db
    restart: always
    volumes:
      - db-data:/var/lib/postgresql
    command: postgres -c listen_addresses='*'
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      TZ: Europe/Madrid
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}

  app:
    build: .
    container_name: app
    restart: always
    ports:
      - 3000:3000
    env_file:
      - .env
    environment:
      TZ: Europe/Madrid
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_HOST: ${POSTGRES_HOST}
      POSTGRES_PORT: ${POSTGRES_PORT}
      POSTGRES_DB: ${POSTGRES_DB}
      NODE_ENV: ${NODE_ENV:-"production"}
      DEMO_MODE: ${DEMO_MODE:-"false"}
      DOMAIN: ${DOMAIN}
      AUTH_TRUST_HOST: ${AUTH_TRUST_HOST}
      AUTH_SECRET: ${AUTH_SECRET}
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?schema=public
    depends_on:
      - db

volumes:
  db-data:
