{
    "captainVersion": "2",
    "documentation": "Adapted from: https://github.com/FusionAuth/fusionauth-containers",
    "displayName": "FusionAuth",
    "description": "FusionAuth is a scalable, identity and user management platform built for devs",
    "dockerCompose": {
        "version": "3.3",
        "services": {
            "$$cap_appname-db": {
                "image": "postgres:$$cap_postgres_version",
                "notExposeAsWebApp": "true",
                "environment": {
                    "POSTGRES_USER": "$$cap_db_user",
                    "POSTGRES_PASSWORD": "$$cap_db_pass",
                    "POSTGRES_DB": "fusionauth"
                },
                "restart": "unless-stopped",
                "volumes": ["$$cap_appname-db-data:/var/lib/postgresql/data"]
            },
            "$$cap_appname-elasticsearch": {
                "image": "docker.elastic.co/elasticsearch/elasticsearch:$$cap_elasticsearch_version",
                "volumes": [
                    "$$cap_appname-elasticsearch-data:/usr/share/elasticsearch/data"
                ],
                "restart": "always",
                "environment": {
                    "ES_JAVA_OPTS": "-Xms512m -Xmx512m",
                    "cluster.name": "$$cap_elasticsearch_cluster_name",
                    "http.port": "$$cap_container_search_port",
                    "node.master": "$$cap_elasticsearch_node_master",
                    "node.data": "$$cap_elasticsearch_node_data",
                    "discovery.type": "single-node",
                    "discovery.zen.minimum_master_nodes": "$$cap_elasticsearch_minimum_master_nodes",
                    "discovery.zen.ping.unicast.hosts": "$$cap_elasticsearch_unicast_hosts"
                },
                "containerHttpPort": "$$cap_container_search_port"
            },
            "$$cap_appname-fusionauth": {
                "image": "fusionauth/fusionauth-app:$$cap_fusionauth_version",
                "depends_on": [
                    "$$cap_appname-db",
                    "$$cap_appname-elasticsearch"
                ],
                "environment": {
                    "DATABASE_URL": "jdbc:postgresql://srv-captain--$$cap_appname-db:5432/fusionauth",
                    "DATABASE_ROOT_USER": "$$cap_db_user",
                    "DATABASE_ROOT_PASSWORD": "$$cap_db_pass",
                    "DATABASE_USER": "$$cap_db_user",
                    "DATABASE_PASSWORD": "$$cap_db_pass",
                    "FUSIONAUTH_MEMORY": "$$cap_fusion_memory",
                    "FUSIONAUTH_SEARCH_SERVERS": "http://srv-captain--$$cap_appname-elasticsearch:9200",
                    "FUSIONAUTH_URL": "http://srv-captain--$$cap_appname-fusionauth:9011"
                },
                "containerHttpPort": "$$cap_container_port",
                "restart": "unless-stopped",
                "volumes": [
                    "$$cap_appname-fusionauth-config:/usr/local/fusionauth/config"
                ]
            }
        },
        "networks": {
            "db": {
                "driver": "bridge"
            },
            "search": {
                "driver": "bridge"
            }
        },
        "volumes": {
            "db_data": null,
            "es_data": null,
            "fa_config": null
        }
    },
    "instructions": {
        "start": "NOTE: This app requires at least 4GB of RAM. Without this requirement it fails to start up. \n\nFusionAuth is a modern platform for Customer Identity and Access Management (CIAM). FusionAuth provides APIs and a responsive web user interface to support login, registration, localized email, multi-factor authentication, reporting and much more. See: https://fusionauth.io/docs/v1/tech/getting-started/ and https://github.com/FusionAuth/fusionauth-containers",
        "end": "FusionAuth is deployed and available as srv-captain--$$cap_appname-fusionauth:9011 to other apps"
    },

    "variables": [
        {
            "id": "$$cap_db_user",
            "label": "Database user",
            "defaultValue": "fusion",
            "validRegex": "/^([a-zA-Z0-9])+$/"
        },
        {
            "id": "$$cap_db_pass",
            "label": "Database password",
            "description": "",
            "validRegex": "/.{1,}/"
        },
        {
            "id": "$$cap_fusionauth_version",
            "label": "FusionAuth Version",
            "defaultValue": "1.7.2",
            "description": "See tags at: https://hub.docker.com/r/fusionauth/fusionauth-app/tags",
            "validRegex": "/^([^\\s^\\/])+$/"
        },
        {
            "id": "$$cap_fusion_memory",
            "label": "Fusion Memory",
            "defaultValue": "256M",
            "description": "",
            "validRegex": "/^([a-zA-Z0-9])+$/"
        },
        {
            "id": "$$cap_postgres_version",
            "label": "Postgres Version",
            "defaultValue": "9.6",
            "description": "",
            "validRegex": "/^([^\\s^\\/])+$/"
        },
        {
            "id": "$$cap_container_port",
            "label": "Container TCP Port",
            "defaultValue": "9011",
            "description": "Internal port for Fusion Auth container to listens to.",
            "validRegex": "/^([0-9])+$/"
        },
        {
            "id": "$$cap_container_search_port",
            "label": "Container TCP Port",
            "defaultValue": "9200",
            "description": "Internal port for Elasticsearch the container listens to.",
            "validRegex": "/^([0-9])+$/"
        },
        {
            "id": "$$cap_elasticsearch_version",
            "label": "Elasticsearch Version Tag ",
            "description": "Checkout the releases overview: https://www.elastic.co/de/downloads/elasticsearch",
            "defaultValue": "6.7.1",
            "validRegex": "/^([^\\s^\\/])+$/"
        },
        {
            "id": "$$cap_elasticsearch_cluster_name",
            "label": "Cluster Name",
            "description": "Only nodes within the same cluster name can be combined",
            "defaultValue": "elasticsearch-cluster",
            "validRegex": "/^([^\\s^\\/])+$/"
        },
        {
            "id": "$$cap_elasticsearch_unicast_hosts",
            "label": "Unicasts hosts",
            "description": "References to other node to attach to. (for example: srv-captain--XXX)",
            "defaultValue": "false",
            "validRegex": "/^([^\\s^\\/])+$/"
        },
        {
            "id": "$$cap_elasticsearch_node_data",
            "label": "Node Data",
            "description": "Should the node used for storing data? (true / false)",
            "defaultValue": "true",
            "validRegex": "/^([^\\s^\\/])+$/"
        },
        {
            "id": "$$cap_elasticsearch_node_master",
            "label": "Node Master",
            "description": "Define node as master-eligible (usual first node YES, others NO).",
            "defaultValue": "true",
            "validRegex": "/^([^\\s^\\/])+$/"
        },
        {
            "id": "$$cap_elasticsearch_minimum_master_nodes",
            "label": "Minimum Master Nodes",
            "description": "Define minimum amount of master (N) ( best practice: ceil(N/2 + 1) ).",
            "defaultValue": "1",
            "validRegex": "/^([0-9])+$/"
        }
    ]
}
