services:
  postgres:
    image: postgres:16-alpine
    container_name: serengo-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: serengo
      POSTGRES_PASSWORD: serengo_password
      POSTGRES_DB: serengo
    ports:
      - '5432:5432'
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U serengo']
      interval: 10s
      timeout: 5s
      retries: 5

  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - DATABASE_URL=postgresql://serengo:serengo_password@postgres:5432/serengo
        - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
        - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
        - R2_ACCOUNT_ID=${R2_ACCOUNT_ID}
        - R2_ACCESS_KEY_ID=${R2_ACCESS_KEY_ID}
        - R2_SECRET_ACCESS_KEY=${R2_SECRET_ACCESS_KEY}
        - R2_BUCKET_NAME=${R2_BUCKET_NAME}
        - GOOGLE_MAPS_API_KEY=${GOOGLE_MAPS_API_KEY}
        - VAPID_PUBLIC_KEY=${VAPID_PUBLIC_KEY}
        - VAPID_PRIVATE_KEY=${VAPID_PRIVATE_KEY}
        - VAPID_SUBJECT=${VAPID_SUBJECT}
    container_name: serengo-app
    restart: unless-stopped
    ports:
      - '3000:3000'
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgresql://serengo:serengo_password@postgres:5432/serengo
      - ORIGIN=http://localhost:3000
      # Add your environment variables here or use env_file
      - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
      - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
      - R2_ACCOUNT_ID=${R2_ACCOUNT_ID}
      - R2_ACCESS_KEY_ID=${R2_ACCESS_KEY_ID}
      - R2_SECRET_ACCESS_KEY=${R2_SECRET_ACCESS_KEY}
      - R2_BUCKET_NAME=${R2_BUCKET_NAME}
      - GOOGLE_MAPS_API_KEY=${GOOGLE_MAPS_API_KEY}
      - VAPID_PUBLIC_KEY=${VAPID_PUBLIC_KEY}
      - VAPID_PRIVATE_KEY=${VAPID_PRIVATE_KEY}
      - VAPID_SUBJECT=${VAPID_SUBJECT}
    depends_on:
      postgres:
        condition: service_healthy
    # Uncomment to use .env file
    # env_file:
    #   - .env

volumes:
  postgres_data:
    driver: local
