# documentation: https://codewithcj.github.io/SparkyFitness/
# slogan: SparkyFitness is a comprehensive fitness tracking and management application designed to help users monitor their nutrition, exercise, and body measurements. It provides tools for daily progress tracking, goal setting, and insightful reports to support a healthy lifestyle.
# category: health
# tags: sparkyfitness, fitness, health, nutrition, exercise, body measurements
# logo: svgs/sparkyfitness.svg
# port: 80

services:
  sparkyfitness-frontend:
    image: 'codewithcj/sparkyfitness:v1.6.1'
    environment:
      - SERVICE_URL_SPARKYFITNESS_80
      - 'SPARKY_FITNESS_FRONTEND_URL=${SERVICE_URL_SPARKYFITNESS_80}'
      - SPARKY_FITNESS_SERVER_HOST=sparkyfitness-server
      - SPARKY_FITNESS_SERVER_PORT=3010
    depends_on:
      - sparkyfitness-server

  sparkyfitness-server:
    image: 'codewithcj/sparkyfitness_server:v1.6.1'
    environment:
      - 'SPARKY_FITNESS_LOG_LEVEL=${SPARKY_FITNESS_LOG_LEVEL:-info}'
      - 'NODE_ENV=${NODE_ENV:-production}'
      - 'TZ=${TZ:-Etc/UTC}'
      # Database — superuser (used for migrations only)
      - 'SPARKY_FITNESS_DB_USER=${SERVICE_USER_POSTGRES}'
      - SPARKY_FITNESS_DB_HOST=sparkyfitness-db
      - 'SPARKY_FITNESS_DB_NAME=${SPARKY_FITNESS_DB_NAME:-sparkyfitness}'
      - 'SPARKY_FITNESS_DB_PASSWORD=${SERVICE_PASSWORD_POSTGRES}'
      - 'SPARKY_FITNESS_DB_PORT=${SPARKY_FITNESS_DB_PORT:-5432}'
      # Database — application user (unprivileged, used at runtime)
      - 'SPARKY_FITNESS_APP_DB_USER=${SPARKY_FITNESS_APP_DB_USER:-sparkyapp}'
      - 'SPARKY_FITNESS_APP_DB_PASSWORD=${SERVICE_PASSWORD_64_APPDBPASSWORD}'
      # Secrets
      - 'SPARKY_FITNESS_API_ENCRYPTION_KEY=${SERVICE_PASSWORD_64_SERVERAPIENCRYPTIONKEY}'
      - 'BETTER_AUTH_SECRET=${SERVICE_PASSWORD_64_BETTERAUTHSECRET}'
      # CORS / trusted origins
      - 'SPARKY_FITNESS_FRONTEND_URL=${SERVICE_URL_SPARKYFITNESS_80}'
      - 'ALLOW_PRIVATE_NETWORK_CORS=${ALLOW_PRIVATE_NETWORK_CORS:-false}'
      - 'SPARKY_FITNESS_EXTRA_TRUSTED_ORIGINS=${SPARKY_FITNESS_EXTRA_TRUSTED_ORIGINS:-}'
      # Auth / signup
      - 'SPARKY_FITNESS_DISABLE_SIGNUP=${SPARKY_FITNESS_DISABLE_SIGNUP:-false}'
      - 'SPARKY_FITNESS_FORCE_EMAIL_LOGIN=${SPARKY_FITNESS_FORCE_EMAIL_LOGIN:-true}'
      - 'SPARKY_FITNESS_ADMIN_EMAIL=${SPARKY_FITNESS_ADMIN_EMAIL:-admin@example.com}'
      # Email (optional)
      - 'SPARKY_FITNESS_EMAIL_HOST=${SPARKY_FITNESS_EMAIL_HOST:-smtp.gmail.com}'
      - 'SPARKY_FITNESS_EMAIL_PORT=${SPARKY_FITNESS_EMAIL_PORT:-587}'
      - 'SPARKY_FITNESS_EMAIL_SECURE=${SPARKY_FITNESS_EMAIL_SECURE:-false}'
      - 'SPARKY_FITNESS_EMAIL_USER=${SPARKY_FITNESS_EMAIL_USER}'
      - 'SPARKY_FITNESS_EMAIL_PASS=${SPARKY_FITNESS_EMAIL_PASS}'
      - 'SPARKY_FITNESS_EMAIL_FROM=${SPARKY_FITNESS_EMAIL_FROM:-"Sparky Fitness <noreply@sparkyfitness.com>"}'
    depends_on:
      - sparkyfitness-db
    volumes:
      - 'sparkyfitness-server-backup:/app/SparkyFitnessServer/backup'
      - 'sparkyfitness-server-uploads:/app/SparkyFitnessServer/uploads'

  sparkyfitness-db:
    image: 'postgres:18-alpine'
    environment:
      - 'POSTGRES_DB=${SPARKY_FITNESS_DB_NAME:-sparkyfitness}'
      - 'POSTGRES_USER=${SERVICE_USER_POSTGRES}'
      - 'POSTGRES_PASSWORD=${SERVICE_PASSWORD_POSTGRES}'
      - POSTGRES_PORT=${SPARKY_FITNESS_DB_PORT:-5432}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 5s
      timeout: 20s
      retries: 10
    volumes:
      - 'sparkyfitness-db-postgresql:/var/lib/postgresql'

