services:
  backend:
    # L'immagine usa il tag specificato nel file .env o passato da riga di comando
    # Nginx esterno deve servire /media/ con un alias verso
    # /mnt/cache/appdata/print-calculator/${ENV}/storage_media/public/
    image: ${REGISTRY_URL}/${REPO_OWNER}/print-calculator-backend:${TAG}
    container_name: print-calculator-backend-${ENV}
    ports:
      - "${BACKEND_PORT}:8000"
    environment:
      - SPRING_PROFILES_ACTIVE=${ENV}
      - DB_URL=${DB_URL}
      - DB_USERNAME=${DB_USERNAME}
      - DB_PASSWORD=${DB_PASSWORD}
      - CLAMAV_HOST=${CLAMAV_HOST}
      - CLAMAV_PORT=${CLAMAV_PORT}
      - CLAMAV_ENABLED=${CLAMAV_ENABLED}
      - TWINT_PAYMENT_URL=${TWINT_PAYMENT_URL:-}
      - MAIL_HOST=${MAIL_HOST:-mail.infomaniak.com}
      - MAIL_PORT=${MAIL_PORT:-587}
      - MAIL_USERNAME=${MAIL_USERNAME:-info@3d-fab.ch}
      - MAIL_PASSWORD=${MAIL_PASSWORD:-}
      - MAIL_SMTP_AUTH=${MAIL_SMTP_AUTH:-true}
      - MAIL_SMTP_STARTTLS=${MAIL_SMTP_STARTTLS:-true}
      - APP_MAIL_FROM=${APP_MAIL_FROM:-info@3d-fab.ch}
      - APP_MAIL_ADMIN_ENABLED=${APP_MAIL_ADMIN_ENABLED:-true}
      - APP_MAIL_ADMIN_ADDRESS=${APP_MAIL_ADMIN_ADDRESS:-info@3d-fab.ch}
      - APP_FRONTEND_BASE_URL=${APP_FRONTEND_BASE_URL:-http://localhost:4200}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD}
      - ADMIN_SESSION_SECRET=${ADMIN_SESSION_SECRET}
      - ADMIN_SESSION_TTL_MINUTES=${ADMIN_SESSION_TTL_MINUTES:-480}
      - TEMP_DIR=/app/temp
      - PROFILES_DIR=/app/profiles
      - MEDIA_STORAGE_ROOT=${MEDIA_STORAGE_ROOT:-/app/storage_media}
      - SHOP_STORAGE_ROOT=${SHOP_STORAGE_ROOT:-/app/storage_shop}
      - MEDIA_FFMPEG_PATH=${MEDIA_FFMPEG_PATH:-ffmpeg}
      - MEDIA_UPLOAD_MAX_FILE_SIZE_BYTES=${MEDIA_UPLOAD_MAX_FILE_SIZE_BYTES:-26214400}
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    volumes: 
      - backend_profiles_${ENV}:/app/profiles
      - /mnt/cache/appdata/print-calculator/${ENV}/storage_quotes:/app/storage_quotes
      - /mnt/cache/appdata/print-calculator/${ENV}/storage_orders:/app/storage_orders
      - /mnt/cache/appdata/print-calculator/${ENV}/storage_requests:/app/storage_requests
      - /mnt/cache/appdata/print-calculator/${ENV}/storage_media:/app/storage_media
      - /mnt/cache/appdata/print-calculator/${ENV}/storage_shop:/app/storage_shop
    extra_hosts:
      - "host.docker.internal:host-gateway"

  frontend:
    image: ${REGISTRY_URL}/${REPO_OWNER}/print-calculator-frontend:${TAG}
    container_name: print-calculator-frontend-${ENV}
    ports:
      - "${FRONTEND_PORT}:80"
    depends_on:
      - backend
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

volumes:
  backend_profiles_prod:
  backend_profiles_int:
  backend_profiles_dev:
