# Configuration for Planka v2 setup

# PLANKA V2.0.1 - NEW DEPLOYMENT
# ================================
# This is a SEPARATE app from 'planka' (v1.26.3). They can coexist.
#
# FOR NEW INSTALLATIONS:
# - Deploy this app for new Planka instances
# - Uses modern v2 architecture with unified data directory
# - Includes enhanced security (SSRF protection)
# - Features: user mentions, task linking, webhooks UI, SMTP UI
#
# FOR MIGRATION FROM V1:
# - Do NOT uninstall your existing 'planka' v1 app
# - Deploy this as NEW app alongside v1
# - Follow manual migration: https://docs.planka.cloud/docs/upgrade-to-v2/docker/
# - Migration is ONE-WAY with NO ROLLBACK (create backups!)
# - Requirements: Must be on v1 >= 1.26.2, subdomain hosting
#
# Migration steps (after deploying this app):
# 1. Backup v1 database: docker compose -f apps/planka/docker-compose.yml exec big-bear-planka-postgres pg_dump -U postgres planka > backup.sql
# 2. Stop v2 containers: docker compose -f apps/planka-v2/docker-compose.yml down
# 3. Copy background images: docker compose -f apps/planka-v2/docker-compose.yml run --rm --user root big-bear-planka-v2 sh -c 'cp -av /app/public/project-background-images/. /app/public/background-images && chown -R node:node /app/public/background-images'
# 4. Import v1 database to v2: docker compose -f apps/planka-v2/docker-compose.yml exec -T big-bear-planka-v2-postgres psql -U postgres planka < backup.sql
# 5. Run database upgrade: docker compose -f apps/planka-v2/docker-compose.yml run --rm big-bear-planka-v2 npm run db:upgrade
# 6. Migrate data structure: docker compose -f apps/planka-v2/docker-compose.yml run --rm big-bear-planka-v2 sh -c 'mkdir -p /app/data/protected /app/data/private && for folder in user-avatars background-images; do cp -av /app/public/$folder /app/data/protected; done && cp -av /app/private/attachments /app/data/private'
# 7. Start v2: docker compose -f apps/planka-v2/docker-compose.yml up -d
# 8. Verify migration success before removing v1
#
# Detailed migration: https://community.bigbeartechworld.com/t/added-planka-to-bigbearcasaos/924

# Name of the big-bear-planka-v2 application
name: big-bear-planka-v2
# Service definitions for the big-bear-planka-v2 application
services:
  # Service name: big-bear-planka-v2
  # The `big-bear-planka-v2` service definition
  big-bear-planka-v2:
    # Name of the container
    container_name: big-bear-planka-v2
    # Image to be used for the container specifies the Planka version and source
    image: ghcr.io/plankanban/planka:2.1.1
    # Container restart policy - restarts the container unless manually stopped
    restart: unless-stopped
    # Volumes to be mounted to the container for persistent storage
    volumes:
      # v2.0.0 Unified data directory (required)
      - /DATA/AppData/$AppID/data:/app/data
      # v2.0.0 Background images directory
      - /DATA/AppData/$AppID/background-images:/app/public/background-images
      # Legacy mount points (kept for migration compatibility)
      - /DATA/AppData/$AppID/user-avatars:/app/public/user-avatars
      - /DATA/AppData/$AppID/project-background-images:/app/public/project-background-images
      - /DATA/AppData/$AppID/attachments:/app/private/attachments
    # Ports mapping between host and container for network access
    ports:
      # Mapping port 3001 of the host to port 1337 of the container
      - "3001:1337"
    # Environment variables to be set in the container for application configuration
    environment:
      - BASE_URL=http://[YOUR_CASAOS_LAN_IP]:3001
      - DATABASE_URL=postgresql://postgres@big-bear-planka-v2-postgres/planka
      - SECRET_KEY=notsecretkey
      # v2.0.0 CHANGE: TRUST_PROXY now requires boolean strings (false/true) instead of numeric (0/1)
      # - TRUST_PROXY=false
      # - TOKEN_EXPIRES_IN=365 # Token expiration in days

      # Additional environment variables for database and security configurations
      # - PGSSLMODE=<value> # For PostgreSQL SSL mode configuration

      # Configure knex to accept SSL certificates
      # - KNEX_REJECT_UNAUTHORIZED_SSL_CERTIFICATE=false

      # Default admin account settings (use for initial setup)
      - DEFAULT_ADMIN_EMAIL=demo@demo.demo
      - DEFAULT_ADMIN_PASSWORD=demo
      - DEFAULT_ADMIN_NAME=Demo Demo
      - DEFAULT_ADMIN_USERNAME=demo
      # v2.0.0 New optional configurations
      # - DEFAULT_LANGUAGE=en-US # Default UI language
      # - MAX_UPLOAD_FILE_SIZE=100000000 # Max file upload size in bytes (default: 100MB)
      # - STORAGE_LIMIT=0 # Total storage limit in bytes (0 = unlimited)
      # - ACTIVE_USERS_LIMIT=0 # Maximum active users (0 = unlimited)
    # SSRF protection - blocks outgoing requests to these hosts
    # - OUTGOING_BLOCKED_HOSTS=localhost,postgres
    # - OUTGOING_PROXY= # HTTP proxy for outgoing requests
    # - OUTGOING_PROXY_TLS_REJECT_UNAUTHORIZED=true

    # OpenID Connect (OIDC) configuration for authentication
    # - OIDC_ISSUER=
    # - OIDC_CLIENT_ID=
    # - OIDC_CLIENT_SECRET=
    # - OIDC_SCOPES=openid email profile
    # - OIDC_ADMIN_ROLES=admin
    # - OIDC_EMAIL_ATTRIBUTE=email
    # - OIDC_NAME_ATTRIBUTE=name
    # - OIDC_USERNAME_ATTRIBUTE=preferred_username
    # - OIDC_ROLES_ATTRIBUTE=groups
    # - OIDC_IGNORE_USERNAME=true
    # - OIDC_IGNORE_ROLES=true
    # - OIDC_ENFORCED=true
    networks:
      - big-bear-planka-v2-network
    # Dependency on another service, ensuring it is healthy before starting
    depends_on:
      big-bear-planka-v2-postgres:
        condition: service_healthy
    x-casaos:
      envs:
        - container: BASE_URL
          description:
            en_us: 'Container Variable: BASE_URL'
        - container: DATABASE_URL
          description:
            en_us: 'Container Variable: DATABASE_URL'
        - container: SECRET_KEY
          description:
            en_us: 'Container Variable: SECRET_KEY'
        - container: DEFAULT_ADMIN_EMAIL
          description:
            en_us: 'Container Variable: DEFAULT_ADMIN_EMAIL'
        - container: DEFAULT_ADMIN_PASSWORD
          description:
            en_us: 'Container Variable: DEFAULT_ADMIN_PASSWORD'
        - container: DEFAULT_ADMIN_NAME
          description:
            en_us: 'Container Variable: DEFAULT_ADMIN_NAME'
        - container: DEFAULT_ADMIN_USERNAME
          description:
            en_us: 'Container Variable: DEFAULT_ADMIN_USERNAME'
      volumes:
        - container: /app/data
          description:
            en_us: 'Container Path: /app/data'
        - container: /app/public/background-images
          description:
            en_us: 'Container Path: /app/public/background-images'
        - container: /app/public/user-avatars
          description:
            en_us: 'Container Path: /app/public/user-avatars'
        - container: /app/public/project-background-images
          description:
            en_us: 'Container Path: /app/public/project-background-images'
        - container: /app/private/attachments
          description:
            en_us: 'Container Path: /app/private/attachments'
      ports:
        - container: "1337"
          description:
            en_us: 'Container Port: 1337'
  # Service definition for the PostgreSQL database used by big-bear-planka-v2
  big-bear-planka-v2-postgres:
    # Specifies the Docker image to use for the PostgreSQL database
    # Using version 14 of PostgreSQL, based on the lightweight Alpine Linux distribution
    image: postgres:14-alpine
    # Specifies the container restart policy
    # The container will restart if it fails during runtime
    restart: on-failure
    # Volumes to be mounted to the container for data persistence
    # Maps a host directory to the container's data directory
    # Ensures that the database data persists across container restarts and deployments
    volumes:
      - /DATA/AppData/$AppID/postgresql:/var/lib/postgresql/data
    # Environment variables passed to the PostgreSQL container for configuration
    environment:
      # Sets the default database that is created when the container starts
      - POSTGRES_DB=planka
      # Configures the authentication method for connections from the host
      # Setting to 'trust' allows connections without a password
      # Note: This setting is not recommended for production environments due to security concerns
      - POSTGRES_HOST_AUTH_METHOD=trust
    networks:
      - big-bear-planka-v2-network
    # Healthcheck configuration to ensure the database service is running properly
    # Runs a command inside the container at specified intervals to check the health of the service
    healthcheck:
      # Command to check if PostgreSQL is ready to accept connections
      # Uses `pg_isready` tool with the default 'postgres' user and the 'planka' database
      test: ["CMD-SHELL", "pg_isready -U postgres -d planka"]
      # The interval between running the healthcheck command
      # Here, it's set to run every 10 seconds
      interval: 10s
      # The timeout duration for the healthcheck command
      # If the command does not complete within 5 seconds, the healthcheck is considered failed
      timeout: 5s
      # Number of consecutive failures needed to consider the service as unhealthy
      retries: 5
    x-casaos:
      envs:
        - container: POSTGRES_DB
          description:
            en_us: 'Container Variable: POSTGRES_DB'
        - container: POSTGRES_HOST_AUTH_METHOD
          description:
            en_us: 'Container Variable: POSTGRES_HOST_AUTH_METHOD'
      volumes:
        - container: /var/lib/postgresql/data
          description:
            en_us: 'Container Path: /var/lib/postgresql/data'
networks:
  big-bear-planka-v2-network:
    driver: bridge
x-casaos:
  # Supported CPU architectures for this application
  architectures:
    - amd64
    - arm64
  # Main service for this application
  main: big-bear-planka-v2
  # Detailed description for the application
  description:
    en_us: The realtime kanban board for workgroups built with React and Redux.
  # Brief tagline for the application
  tagline:
    en_us: Free open source kanban board for workgroups.
  # Developer's information
  developer: plankanban
  # Author of this particular configuration
  author: BigBearTechWorld
  # Icon URL for the application
  icon: https://cdn.jsdelivr.net/gh/selfhst/icons/png/planka.png
  # Thumbnail image for the application (if any)
  thumbnail: ""
  # Installation tips
  tips:
    before_install:
      en_us: "\U0001F195 PLANKA V2 - SEPARATE APP\n\nThis is a NEW app, separate from 'planka' (v1). Both can run simultaneously.\n\nFOR NEW USERS:\n✅ Install this app for new Planka deployments\n✅ Modern v2 architecture with unified data directory\n✅ Enhanced security (SSRF protection)\n✅ New features: user mentions, task linking, webhooks UI, SMTP UI\n\nFOR V1 USERS:\n⚠️  Do NOT uninstall your 'planka' v1 app\n⚠️  Deploy this as a NEW app alongside v1\n⚠️  Migration is ONE-WAY with NO ROLLBACK\n⚠️  Requires manual data migration: https://docs.planka.cloud/docs/upgrade-to-v2/docker/\n⚠️  Must be on v1 >= 1.26.2, subdomain hosting required\n\nDetailed migration guide: https://community.bigbeartechworld.com/t/added-planka-to-bigbearcasaos/924"
  # Title for the application
  title:
    en_us: Planka v2
  # Category under which the application falls
  category: BigBearCasaOS
  # Default port mapping for the application
  port_map: "3001"
