captainVersion: 4
caproverOneClickApp:
    instructions:
        start: |-
            Zammad is a web-based, open source user support/ticketing solution. For Zammad and a database server like PostgreSQL we recommend at least:

            - 2 CPU cores
            - 4 GB of RAM (+4 GB if you want to run Elasticsearch on the same server)
            - For optimal performance up to 40 agents:
            - 4 CPU cores
            - 6 GB of RAM (+6 GB if you want to run Elasticsearch on the same server)

        end: >
            Zammad is deployed and available.
             IMPORTANT: It will take up to 5 minutes for Zammad to be ready. Before that, you might see a 502 error page.
    displayName: Zammad
    isOfficial: true
    description: Zammad is a web-based, open source user support/ticketing solution.
    documentation: Taken from https://hub.docker.com/r/zammad/zammad-docker-compose.
    variables:
        - id: $$cap_zammad_VERSION
          label: Zammad Version
          defaultValue: '5.1.0-48'
          description: Check out their docker page for the valid tags https://hub.docker.com/r/zammad/zammad-docker-compose/tags
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_zammad_ELASTICSEARCH_ENABLED
          label: ELASTICSEARCH_ENABLED
          defaultValue: 'true'
          description: Setting this variable to false will allow you to run your Zammad without Elasticsearch. Please note that we strongly advise against doing so.
          validRegex: /^(true|false)$/

        - id: $$cap_zammad_POSTGRESQL_USER
          label: POSTGRESQL_USER
          defaultValue: postgresuser
          validRegex: /^([a-zA-Z0-9\-\.\_])+$/

        - id: $$cap_zammad_POSTGRESQL_PASS
          label: POSTGRESQL_PASS
          defaultValue: $$cap_gen_random_hex(10)
          description: 'The password of Zammads database user.'
          validRegex: /.{1,}/

        - id: $$cap_zammad_POSTGRESQL_DB
          label: POSTGRESQL_DB
          defaultValue: zammad_production
          validRegex: /^([a-zA-Z0-9\-\.\_])+$/

        - id: $$cap_zammad_POSTGRESQL_CREATEDB
          label: POSTGRESQL_DB_CREATE
          defaultValue: 'true'
          description: By default we will create the required database.
          validRegex: /^(true|false)$/

        - id: $$cap_zammad_RAILS_TRUSTED_PROXIES
          label: RAILS_TRUSTED_PROXIES
          description: By default Zammad trusts localhost proxies only. ⚠ Only change this option if you know what you’re doing! ⚠
          defaultValue: "['127.0.0.1', '::1']"

services:
    $$cap_appname-backup:
        restart: always
        depends_on:
            - $$cap_appname-railsserver
        environment:
            BACKUP_SLEEP: 86400
            HOLD_DAYS: 10
            POSTGRESQL_HOST: srv-captain--$$cap_appname-postgresql
            POSTGRESQL_PORT: 5432
            POSTGRESQL_USER: $$cap_zammad_POSTGRESQL_USER
            POSTGRESQL_PASSWORD: $$cap_zammad_POSTGRESQL_PASS
            POSTGRESQL_DB: $$cap_zammad_POSTGRESQL_DB
            ZAMMAD_RAILSSERVER_HOST: srv-captain--$$cap_appname-railsserver
            ZAMMAD_RAILSSERVER_PORT: 3000
        volumes:
            - $$cap_appname-backup:/var/tmp/zammad
            - $$cap_appname-data:/opt/zammad
        caproverExtra:
            notExposeAsWebApp: true
            dockerfileLines:
                - FROM zammad/zammad-docker-compose:zammad-postgresql-$$cap_zammad_VERSION
                - ENTRYPOINT []
                - CMD /usr/local/bin/backup.sh zammad-backup

    $$cap_appname-elasticsearch:
        restart: always
        image: zammad/zammad-docker-compose:zammad-elasticsearch-$$cap_zammad_VERSION
        environment:
            discovery.type: single-node
        volumes:
            - $$cap_appname-elasticsearch-data:/usr/share/elasticsearch/data
        caproverExtra:
            notExposeAsWebApp: true

    $$cap_appname-init:
        restart: on-failure
        depends_on:
            - $$cap_appname-postgresql
        environment:
            AUTOWIZARD_JSON: ''
            ELASTICSEARCH_ENABLED: $$cap_zammad_ELASTICSEARCH_ENABLED
            ELASTICSEARCH_HOST: srv-captain--$$cap_appname-elasticsearch
            ELASTICSEARCH_PORT: 9200
            ELASTICSEARCH_SCHEMA: http
            ELASTICSEARCH_NAMESPACE: zammad
            ELASTICSEARCH_REINDEX: true
            ELASTICSEARCH_SSL_VERIFY: true
            MEMCACHED_HOST: srv-captain--$$cap_appname-memcached
            MEMCACHED_PORT: 11211
            NGINX_PORT: 8080
            NGINX_SERVER_NAME: _
            NGINX_SERVER_SCHEME: \$scheme
            POSTGRESQL_HOST: srv-captain--$$cap_appname-postgresql
            POSTGRESQL_PORT: 5432
            POSTGRESQL_USER: $$cap_zammad_POSTGRESQL_USER
            POSTGRESQL_PASS: $$cap_zammad_POSTGRESQL_PASS
            POSTGRESQL_DB: $$cap_zammad_POSTGRESQL_DB
            POSTGRESQL_DB_CREATE: $$cap_zammad_POSTGRESQL_CREATEDB
            RAILS_TRUSTED_PROXIES: $$cap_zammad_RAILS_TRUSTED_PROXIES
            RSYNC_ADDITIONAL_PARAMS: --no-perms --no-owner
            ZAMMAD_RAILSSERVER_HOST: srv-captain--$$cap_appname-railsserver
            ZAMMAD_RAILSSERVER_PORT: 3000
            ZAMMAD_WEBSOCKET_HOST: srv-captain--$$cap_appname-websocket
            ZAMMAD_WEBSOCKET_PORT: 6042
        volumes:
            - $$cap_appname-data:/opt/zammad
        caproverExtra:
            notExposeAsWebApp: true
            dockerfileLines:
                - FROM zammad/zammad-docker-compose:zammad-$$cap_zammad_VERSION
                - ENTRYPOINT []
                - CMD /docker-entrypoint.sh zammad-init && tail -f /dev/null

    $$cap_appname-memcached:
        restart: always
        caproverExtra:
            notExposeAsWebApp: true
            dockerfileLines:
                - FROM memcached:1.6.10-alpine
                - CMD memcached -m 256M

    $$cap_appname-nginx:
        ports:
            - '8080:8080'
        depends_on:
            - $$cap_appname-railsserver
        environment:
            ZAMMAD_RAILSSERVER_HOST: srv-captain--$$cap_appname-railsserver
            ZAMMAD_RAILSSERVER_PORT: 3000
            ZAMMAD_WEBSOCKET_HOST: srv-captain--$$cap_appname-websocket
            ZAMMAD_WEBSOCKET_PORT: 6042
        restart: always
        volumes:
            - $$cap_appname-data:/opt/zammad
        caproverExtra:
            notExposeAsWebApp: false
            containerHttpPort: 8080
            dockerfileLines:
                - FROM zammad/zammad-docker-compose:zammad-$$cap_zammad_VERSION
                - ENTRYPOINT []
                - CMD /docker-entrypoint.sh zammad-nginx

    $$cap_appname-postgresql:
        environment:
            POSTGRES_PORT: 5432
            POSTGRES_USER: $$cap_zammad_POSTGRESQL_USER
            POSTGRES_PASSWORD: $$cap_zammad_POSTGRESQL_PASS
        image: zammad/zammad-docker-compose:zammad-postgresql-$$cap_zammad_VERSION
        restart: always
        volumes:
            - $$cap_appname-postgresql-data:/var/lib/postgresql/data
        caproverExtra:
            notExposeAsWebApp: true

    $$cap_appname-railsserver:
        depends_on:
            - $$cap_appname-memcached
            - $$cap_appname-postgresql
        environment:
            ZAMMAD_RAILSSERVER_PORT: 3000
        restart: always
        volumes:
            - $$cap_appname-data:/opt/zammad
        caproverExtra:
            notExposeAsWebApp: true
            dockerfileLines:
                - FROM zammad/zammad-docker-compose:zammad-$$cap_zammad_VERSION
                - ENTRYPOINT []
                - CMD /docker-entrypoint.sh zammad-railsserver

    $$cap_appname-scheduler:
        depends_on:
            - $$cap_appname-memcached
            - $$cap_appname-railsserver
        restart: always
        volumes:
            - $$cap_appname-data:/opt/zammad
        caproverExtra:
            notExposeAsWebApp: true
            dockerfileLines:
                - FROM zammad/zammad-docker-compose:zammad-$$cap_zammad_VERSION
                - ENTRYPOINT []
                - CMD /docker-entrypoint.sh zammad-scheduler

    $$cap_appname-websocket:
        depends_on:
            - $$cap_appname-memcached
            - $$cap_appname-railsserver
        environment:
            ZAMMAD_WEBSOCKET_PORT: 6042
        restart: always
        volumes:
            - $$cap_appname-data:/opt/zammad
        caproverExtra:
            notExposeAsWebApp: false
            dockerfileLines:
                - FROM zammad/zammad-docker-compose:zammad-$$cap_zammad_VERSION
                - ENTRYPOINT []
                - CMD /docker-entrypoint.sh zammad-websocket

volumes:
    $$cap_appname-elasticsearch-data:
        driver: local
    $$cap_appname-postgresql-data:
        driver: local
    $$cap_appname-backup:
        driver: local
    $$cap_appname-data:
        driver: local
