# Configuration for big-bear-n8n setup
name: big-bear-n8n
# Service definitions for the big-bear-n8n application
services:
  # Service configuration for the n8n application
  app:
    container_name: n8n # Name of the n8n container
    image: n8nio/n8n:2.27.3 # Docker image and version to use for n8n
    restart: unless-stopped # Restart policy: Restart unless manually stopped
    ports:
      - 5678:5678 # Port mapping between host and container
    links:
      - db-n8n # Link to the database container
    volumes:
      - /DATA/AppData/$AppID/.n8n:/home/node/.n8n # Volume for persistent data
    environment:
      # Database configuration environment variables
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_HOST=db-n8n
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_USER=bigbearcasaos
      - DB_POSTGRESDB_PASSWORD=bigbearcasaos
    depends_on:
      db-n8n:
        condition: service_healthy # Ensure DB is healthy before starting app
    x-casaos:
      envs:
        - container: DB_TYPE
          description:
            en_us: 'Container Variable: DB_TYPE'
        - container: DB_POSTGRESDB_DATABASE
          description:
            en_us: 'Container Variable: DB_POSTGRESDB_DATABASE'
        - container: DB_POSTGRESDB_HOST
          description:
            en_us: 'Container Variable: DB_POSTGRESDB_HOST'
        - container: DB_POSTGRESDB_PORT
          description:
            en_us: 'Container Variable: DB_POSTGRESDB_PORT'
        - container: DB_POSTGRESDB_USER
          description:
            en_us: 'Container Variable: DB_POSTGRESDB_USER'
        - container: DB_POSTGRESDB_PASSWORD
          description:
            en_us: 'Container Variable: DB_POSTGRESDB_PASSWORD'
      volumes:
        - container: /home/node/.n8n
          description:
            en_us: 'Container Path: /home/node/.n8n'
      ports:
        - container: "5678"
          description:
            en_us: 'Container Port: 5678'
  # Database service configuration
  db-n8n:
    container_name: db-n8n # Name of the database container
    image: postgres:14.2 # Docker image and version for PostgreSQL
    restart: on-failure # Restart policy: Restart on failure
    volumes:
      - /DATA/AppData/$AppID/pgdata:/var/lib/postgresql/data # Persistent DB data
      - /DATA/AppData/$AppID/db/init-data.sh:/docker-entrypoint-initdb.d/init-data.sh # DB initialization script
    environment:
      # PostgreSQL user, password, and database environment variables
      - POSTGRES_PASSWORD=bigbearcasaos
      - POSTGRES_USER=bigbearcasaos
      - POSTGRES_DB=n8n
    healthcheck:
      # Health check commands to ensure DB availability
      test: ["CMD-SHELL", "pg_isready -h localhost -U bigbearcasaos -d n8n"]
      interval: 5s
      timeout: 5s
      retries: 10
    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'
        - container: /docker-entrypoint-initdb.d/init-data.sh
          description:
            en_us: 'Container Path: /docker-entrypoint-initdb.d/init-data.sh'
x-casaos:
  # Supported CPU architectures for this application
  architectures:
    - amd64
    - arm64
  # Main service for this application
  main: app
  # Detailed description for the application
  description:
    en_us: Free and open fair-code licensed node based Workflow Automation Tool.
  # Brief tagline for the application
  tagline:
    en_us: Workflow automation tool
  # Developer's information
  developer: n8n
  # Author of this particular configuration
  author: BigBearTechWorld
  # Icon URL for the application
  icon: https://cdn.jsdelivr.net/gh/selfhst/icons/png/n8n.png
  # Thumbnail image for the application (if any)
  thumbnail: ""
  # Installation tips
  tips:
    before_install:
      en_us: |
        Run this script:

        ```
        bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/generate-n8n-init-data/run.sh)"
        ```
  # Title for the application
  title:
    en_us: n8n
  # Category under which the application falls
  category: BigBearCasaOS
  # Default port mapping for the application
  port_map: "5678"
