# Configuration for joplin setup

# Name of the big-bear-joplin application
name: big-bear-joplin
# Service definitions for the big-bear-joplin application
services:
  # Configuration for the Joplin server service
  big-bear-joplin:
    container_name: big-bear-joplin # The name of the Docker container for easy reference.
    image: joplin/server:3.7.1 # Docker image to use, specifying version.
    restart: unless-stopped # Policy to automatically restart the container unless manually stopped.
    # Environment variables for the Joplin server, configuring database connection and application settings.
    environment:
      - APP_PORT=22300 # Port the Joplin server listens on.
      - APP_BASE_URL=http://localhost:22300 # Base URL for the Joplin server.
      - DB_CLIENT=pg # Specifies the database client (PostgreSQL).
      - POSTGRES_PASSWORD=27a1d42a-a15d-43dd-903c-2a73538647fe # Password for the PostgreSQL database.
      - POSTGRES_USER=bigbear # Username for the PostgreSQL database.
      - POSTGRES_DATABASE=joplin # Database name for Joplin data.
      - POSTGRES_PORT=5432 # Port for connecting to the PostgreSQL database.
      - POSTGRES_HOST=big-bear-joplin-db # Hostname of the PostgreSQL database container.
      - MAX_TIME_DRIFT=0 # Maximum allowed time drift for synchronization.
    # Ports mapping from host to container, for network access to the Joplin server.
    ports:
      - "22300:22300" # Maps port 22300 on the host to port 22300 on the container.
    networks:
      - big_bear_joplin_network # Connects the container to a defined network for inter-container communication.
    depends_on:
      - big-bear-joplin-db # Specifies the database service as a dependency for the Joplin server.
    x-casaos:
      envs:
        - container: APP_PORT
          description:
            en_us: 'Container Variable: APP_PORT'
        - container: APP_BASE_URL
          description:
            en_us: 'Container Variable: APP_BASE_URL'
        - container: DB_CLIENT
          description:
            en_us: 'Container Variable: DB_CLIENT'
        - container: POSTGRES_PASSWORD
          description:
            en_us: 'Container Variable: POSTGRES_PASSWORD'
        - container: POSTGRES_USER
          description:
            en_us: 'Container Variable: POSTGRES_USER'
        - container: POSTGRES_DATABASE
          description:
            en_us: 'Container Variable: POSTGRES_DATABASE'
        - container: POSTGRES_PORT
          description:
            en_us: 'Container Variable: POSTGRES_PORT'
        - container: POSTGRES_HOST
          description:
            en_us: 'Container Variable: POSTGRES_HOST'
        - container: MAX_TIME_DRIFT
          description:
            en_us: 'Container Variable: MAX_TIME_DRIFT'
      ports:
        - container: "22300"
          description:
            en_us: 'Container Port: 22300'
  # Configuration for the PostgreSQL database service used by Joplin
  big-bear-joplin-db:
    container_name: big-bear-joplin-db # Name of the database container.
    image: postgres:14.2 # Docker image for PostgreSQL, specifying version.
    volumes:
      - /DATA/AppData/$AppID/postgresql/data:/var/lib/postgresql/data # Maps data directory to host for persistence.
    restart: unless-stopped # Restart policy similar to the Joplin server container.
    environment:
      - POSTGRES_PASSWORD=27a1d42a-a15d-43dd-903c-2a73538647fe # Database password, matching the Joplin server configuration.
      - POSTGRES_USER=bigbear # Username for the database, intended for CasaOS usage.
      - POSTGRES_DB=joplin # Specifies the database used for storing Joplin data.
    networks:
      - big_bear_joplin_network # Ensures database container is on the same network as the Joplin server.
    x-casaos:
      envs:
        - container: POSTGRES_PASSWORD
          description:
            en_us: 'Container Variable: POSTGRES_PASSWORD'
        - container: POSTGRES_USER
          description:
            en_us: 'Container Variable: POSTGRES_USER'
        - container: POSTGRES_DB
          description:
            en_us: 'Container Variable: POSTGRES_DB'
      volumes:
        - container: /var/lib/postgresql/data
          description:
            en_us: 'Container Path: /var/lib/postgresql/data'
# Network configuration for the services to communicate internally.
networks:
  big_bear_joplin_network:
    driver: bridge # Uses a bridge network for inter-container communication.
x-casaos:
  # Supported CPU architectures for this application
  architectures:
    - amd64
    - arm64
  # Main service for this application
  main: big-bear-joplin
  # Detailed description for the application
  description:
    en_us: Note taking and to-do application with synchronisation
  # Brief tagline for the application
  tagline:
    en_us: joplin
  # Developer's information
  developer: joplin
  # Author of this particular configuration
  author: BigBearTechWorld
  # Icon URL for the application
  icon: https://cdn.jsdelivr.net/gh/selfhst/icons/png/joplin.png
  # Thumbnail image for the application (if any)
  thumbnail: ""
  # Installation tips
  tips:
    before_install:
      en_us: |
        Read this before installing: https://community.bigbeartechworld.com/t/added-joplin-server-to-bigbearcasaos/800?u=dragonfire1119
  # Title for the application
  title:
    en_us: joplin
  # Category under which the application falls
  category: BigBearCasaOS
  # Default port mapping for the application
  port_map: "22300"
