captainVersion: 4
services:
    $$cap_appname-db:
        documentation: Taken from https://hub.docker.com/_/postgres
        image: postgres:$$cap_postgres_version
        volumes:
            - $$cap_appname-db-data:/var/lib/postgresql/data
        restart: always
        environment:
            POSTGRES_PASSWORD: $$cap_db_pass
            POSTGRES_DB: n8n
            POSTGRES_USER: $$cap_db_user
        caproverExtra:
            notExposeAsWebApp: 'true'
    $$cap_appname:
        documentation: Taken from https://hub.docker.com/r/n8nio/n8n
        depends_on:
            - $$cap_appname-db
        image: n8nio/n8n:$$cap_n8n_version
        volumes:
            - $$cap_appname-data:/root/.n8n
            - $$cap_appname-data-write:/files
            - /var/run/docker.sock:/var/run/docker.sock
        environment:
            DB_POSTGRESDB_DATABASE: n8n
            DB_POSTGRESDB_HOST: srv-captain--$$cap_appname-db
            DB_POSTGRESDB_PASSWORD: $$cap_db_pass
            DB_POSTGRESDB_PORT: '5432'
            DB_POSTGRESDB_USER: $$cap_db_user
            DB_TYPE: postgresdb
            GENERIC_TIMEZONE: $$cap_timezone
            TZ: $$cap_timezone
            N8N_PROTOCOL: http
            WEBHOOK_TUNNEL_URL: https://$$cap_appname.$$cap_root_domain/
            VUE_APP_URL_BASE_API: https://$$cap_appname.$$cap_root_domain/
            N8N_HOST: https://$$cap_appname.$$cap_root_domain/
            N8N_BASIC_AUTH_ACTIVE: 'true'
            N8N_BASIC_AUTH_USER: $$cap_user
            N8N_BASIC_AUTH_PASSWORD: $$cap_pass
        restart: always
        caproverExtra:
            containerHttpPort: '5678'
caproverOneClickApp:
    variables:
        - id: $$cap_n8n_version
          label: n8n.io Version
          defaultValue: 0.159.1
          description: Check out their Docker page for the valid tags https://hub.docker.com/r/n8nio/n8n/tags
          validRegex: /^([^\s^\/])+$/
        - id: $$cap_postgres_version
          label: Postgres (database) version
          defaultValue: '14'
          description: Check out their Docker page for the valid tags https://hub.docker.com/_/postgres?tab=tags
          validRegex: /^([^\s^\/])+$/
        - id: $$cap_db_pass
          label: database password
          defaultValue: $$cap_gen_random_hex(16)
          description: Password for the database user and root using mysql.
          validRegex: /.{1,}/
        - id: $$cap_db_user
          label: database user
          defaultValue: n8n
          description: Username for the database using postgres.
          validRegex: /^([a-z0-9])+$/i
        - id: $$cap_timezone
          label: timezone
          defaultValue: Europe/Paris
          description: Timezone used by the server. Please check out this page https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for valid time
          validRegex: /^([a-z_\+-0-9]+\/?[a-z_\+-0-9]*)$/i
        - id: $$cap_user
          label: user
          defaultValue: root
          description: user you need to use to login into the web interface
          validRegex: /^([a-z0-9])+$/i
        - id: $$cap_pass
          label: password
          description: password you need to use to login into the web interface
          validRegex: /.{1,}/
    instructions:
        start: >-
            n8n is a free and open node based Workflow Automation Tool.

            The process will deploy a database and the App. It will take about a minute for the process to finish.
        end: >-
            n8n is deployed and available as $$cap_appname.

            IMPORTANT!! You need to enable https and websocket support.

            Also, make sure you DO NOT activate basic auth manually.
    displayName: n8n.io
    isOfficial: true
    description: n8n is a free and open node based Workflow Automation Tool.
