services:
  app:
    image: goyco:latest
    depends_on:
      db:
        condition: service_healthy
    env_file:
      - ../.env
    environment:
      DB_HOST: db
      DB_PORT: ${DB_PORT:-5432}
      DB_USER: ${DB_USER:-goyco}
      DB_PASSWORD: ${DB_PASSWORD:?DB_PASSWORD is required}
      DB_NAME: ${DB_NAME:?DB_NAME is required}
      DB_SSLMODE: ${DB_SSLMODE:-disable}
      JWT_SECRET: ${JWT_SECRET:?JWT_SECRET is required}
      JWT_EXPIRATION: ${JWT_EXPIRATION:-24}
      SERVER_HOST: ${SERVER_HOST:-0.0.0.0}
      SERVER_PORT: ${SERVER_PORT:-8080}
      SMTP_HOST: ${SMTP_HOST:?SMTP_HOST is required}
      SMTP_PORT: ${SMTP_PORT:-857}
      SMTP_USERNAME: ${SMTP_USERNAME:-}
      SMTP_PASSWORD: ${SMTP_PASSWORD:-}
      SMTP_FROM: ${SMTP_FROM:?SMTP_FROM is required}
      APP_BASE_URL: ${APP_BASE_URL:-http://127.0.0.1:8080}
    ports:
      - "8080:8080"
    restart: always
    networks:
      - goyco

  db:
    image: postgres:18-alpine
    restart: always
    env_file:
      - ../.env
    environment:
      POSTGRES_USER: ${DB_USER:?DB_USER is required}
      POSTGRES_PASSWORD: ${DB_PASSWORD:?DB_PASSWORD is required}
      POSTGRES_DB: ${DB_NAME:?DB_NAME is required}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - goyco

volumes:
  pgdata:

networks:
  goyco:
