services:
  app:
    build:
      context: .
      args:
        APP_VERSION: ${APP_VERSION:-4.2.3}
    environment:
      APP_VERSION: ${APP_VERSION:-4.2.3}
      DATABASE_URL: postgresql://${POSTGRES_USER:-goodwalk}:${POSTGRES_PASSWORD:-goodwalk}@db:5432/${POSTGRES_DB:-goodwalk}
      NODE_ENV: production
      PORT: ${APP_PORT:-3000}
      ENABLE_GENERAL_ENQUIRIES: ${ENABLE_GENERAL_ENQUIRIES:-false}
      PUBLIC_ENABLE_MOBILE_CTA_BUTTON: ${PUBLIC_ENABLE_MOBILE_CTA_BUTTON:-false}
      TZ: ${TZ:-Pacific/Auckland}
    depends_on:
      - db
    restart: unless-stopped

  mail-api:
    build:
      context: ./mail-api
      args:
        APP_VERSION: ${APP_VERSION:-4.2.3}
    environment:
      APP_VERSION: ${APP_VERSION:-4.2.3}
      RESEND_API_KEY: ${RESEND_API_KEY}
      OWNER_EMAIL: ${OWNER_EMAIL}
      OWNER_BCC: ${OWNER_BCC:-}
      CLIENT_BCC: ${CLIENT_BCC:-}
      FROM_EMAIL: ${FROM_EMAIL:-GoodWalk <info@goodwalk.co.nz>}
      REPLY_TO: ${REPLY_TO:-info@goodwalk.co.nz}
      ENABLE_GENERAL_ENQUIRIES: ${ENABLE_GENERAL_ENQUIRIES:-false}
      TZ: ${TZ:-Pacific/Auckland}
    restart: unless-stopped

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-goodwalk}
      POSTGRES_USER: ${POSTGRES_USER:-goodwalk}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-goodwalk}
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./docker/postgres/init:/docker-entrypoint-initdb.d:ro
    restart: unless-stopped

  nginx:
    image: nginx:1.27-alpine
    depends_on:
      - app
      - mail-api
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - /etc/letsencrypt:/etc/letsencrypt:ro
      - /var/www/certbot:/var/www/certbot:ro
    restart: unless-stopped

volumes:
  postgres_data:
