# ./docker_data is created and filled with persistent data that should be backuped

version: '2'
services:
    proxy:
        image: quay.io/abretaud/nginx-ldap:latest # Not using the default nginx image as we need the ldap module
        ports:
            - "9170:80"
        links:
            - galaxy
            - jbrowse
            - tripal
            - apollo
            - apollo-report
            - blast
            - wiki
        volumes:
            - ./src_data/:/project_data/
            #- /groups/XXX/:/groups/XXX/:ro  # We do this when we have symlinks in src_data pointing to /groups/XXX/...
            - ./nginx/conf:/etc/nginx/conf.d

    tripal:
        image: quay.io/galaxy-genome-annotation/tripal@sha256:4451cc3a601d109c07c7aedcc76bd41a5da7c438c8fa0862488680bd462f125b
        links:
            - tripaldb:postgres
            - elasticsearch:elasticsearch
        volumes_from:
            - "galaxy"
        volumes:
            - ./src_data:/data:ro
        environment:
            BASE_URL_PATH: /sp/genus_species
            UPLOAD_LIMIT: 20M
            MEMORY_LIMIT: 512M
            TRIPAL_GIT_CLONE_MODULES: "https://github.com/abretaud/tripal_rest_api.git[@c6f9021ea5d4c6d7c67c5bd363a7dd9359228bbc] https://github.com/tripal/tripal_elasticsearch.git[@dc7f276046e394a80a7dfc9404cf1a149006eb2a] https://github.com/tripal/tripal_analysis_interpro.git https://github.com/tripal/tripal_analysis_go.git https://github.com/tripal/tripal_analysis_blast.git  https://github.com/tripal/tripal_analysis_expression.git[@7240039fdeb4579afd06bbcb989cb7795bd4c342]"
            TRIPAL_DOWNLOAD_MODULES: ""
            TRIPAL_ENABLE_MODULES: "tripal_analysis_blast tripal_analysis_interpro tripal_analysis_go tripal_rest_api tripal_elasticsearch"
            SITE_NAME: "Genus species"
            ENABLE_JBROWSE: /jbrowse/?data=data/gspecies
            ENABLE_APOLLO: 1
            ENABLE_BLAST: 1
            ENABLE_DOWNLOAD: 1
            ENABLE_WIKI: 1
            ENABLE_GO: /organism/Genus/species?pane=GO
            ENABLE_ORTHOLOGY: 0
            ENABLE_ORTHOLOGY_LINKS: http://localhost/sp/orthology/
            #THEME: "bipaa"    # Use this to use another theme
            #THEME_GIT_CLONE: "https://gitlab.inria.fr/abretaud/tripal_bipaa.git"    # Use this to install another theme
            ADMIN_PASSWORD: XXXXXX  # You need to define it and update it in galaxy config below

    tripaldb:
        image: quay.io/galaxy-genome-annotation/chado:1.31-jenkins110.1-pg9.5
        environment:
            - POSTGRES_PASSWORD=postgres
            # The default chado image would try to install the schema on first run,
            # we just want the tools to be available.
            - INSTALL_CHADO_SCHEMA=0
        volumes:
            - ./docker_data/tripal_db/:/var/lib/postgresql/data/

    elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
        #mem_limit: 500m   # This is to limit usage, but can make the docker crash when ram is exhausted, not recommended while indexing all data, ok once indexing is done
        ulimits:
            memlock:
                soft: -1
                hard: -1
        volumes:
            - ./docker_data/elastic_search_index/:/usr/share/elasticsearch/data
        environment:
            bootstrap.memory_lock: "true"
            xpack.security.enabled: "false"
            xpack.monitoring.enabled: "false"
            xpack.ml.enabled: "false"
            xpack.graph.enabled: "false"
            xpack.watcher.enabled: "false"
            cluster.routing.allocation.disk.threshold_enabled: "false"
            ES_JAVA_OPTS: "-Xms200m -Xmx200m"
            TAKE_FILE_OWNERSHIP: "true"

    galaxy:
        image: quay.io/galaxy-genome-annotation/docker-galaxy-annotation:gmod
        volumes:
            - ../galaxy_data_libs_SI.py:/opt/setup_data_libraries.py
            - ./docker_data/galaxy:/export
            - ./src_data/:/project_data:ro
            #- /groups/XXX/:/groups/XXX/:ro  # We do this when we have symlinks in src_data pointing to /groups/XXX/...
            - ./docker_data/jbrowse/:/jbrowse/data/
            - ./docker_data/apollo/:/apollo-data/
        links:
            - "tripaldb:chado"
        environment:
            NONUSE: nodejs,proftp,reports
            GALAXY_LOGGING: full
            GALAXY_CONFIG_BRAND: "Genus species"
            GALAXY_CONFIG_ALLOW_LIBRARY_PATH_PASTE: "True"
            GALAXY_CONFIG_USE_REMOTE_USER: "True"
            GALAXY_CONFIG_REMOTE_USER_MAILDOMAIN: "bipaa"
            GALAXY_CONFIG_ADMIN_USERS: "admin@galaxy.org,gogepp@bipaa"   # admin@galaxy.org is the default (leave it), gogepp@bipaa is a shared ldap user we use to connect
            ENABLE_FIX_PERMS: 0
            PROXY_PREFIX: /sp/genus_species/galaxy
            GALAXY_CONFIG_COOKIE_PATH: /galaxy
            GALAXY_TRIPAL_PASSWORD: XXXXXX  # See tripal config above
            GALAXY_WEBAPOLLO_URL: http://apollo:8080
            GALAXY_WEBAPOLLO_USER: "admin_apollo@bipaa"
            GALAXY_WEBAPOLLO_PASSWORD: "XXXXXX"  # See tripal config below
            GALAXY_WEBAPOLLO_EXT_URL: /sp/genus_species/apollo
            GALAXY_CHADO_DBHOST: chado
            GALAXY_CHADO_DBSCHEMA: chado
            GALAXY_AUTO_UPDATE_DB: 1
            GALAXY_AUTO_UPDATE_CONDA: 1
            GALAXY_AUTO_UPDATE_TOOLS: "/galaxy-central/tools_1.yaml"
            BLAT_ENABLED: 1

    jbrowse:
        image: quay.io/galaxy-genome-annotation/jbrowse:v1.16.5
        volumes:
            - /data
        volumes_from:
            - "galaxy:ro"
        ports:
            - "80"

    apollo:
        image: quay.io/abretaud/apollo:bipaa
        links:
            - "apollo_db:db"
        environment:
            APOLLO_ADMIN_EMAIL: "admin_apollo@bipaa"   # internal admin user, used by some scripts/api
            APOLLO_ADMIN_PASSWORD: "XXXXXX"  # define it and adapt galaxy config above
            APOLLO_BASE_HOST: "http://localhost"
            APOLLO_PATH_PREFIX: "/sp/genus_species/apollo/"
            APOLLO_REMOTE_ADMINS: "gogepp@bipaa,abretaud@bipaa,srobin@bipaa,flegeai@bipaa"   # all ldap users that we use to connect as admin
            WEBAPOLLO_DB_USERNAME: postgres
            WEBAPOLLO_DB_PASSWORD: password
            WEBAPOLLO_DB_DRIVER: "org.postgresql.Driver"
            WEBAPOLLO_DB_DIALECT: "org.hibernate.dialect.PostgresPlusDialect"
            WEBAPOLLO_DB_URI: "jdbc:postgresql://db/postgres"
            WEBAPOLLO_FEATURE_HAS_DBXREFS: "true"
            WEBAPOLLO_FEATURE_HAS_ATTRS: "true"
            WEBAPOLLO_FEATURE_HAS_PUBMED: "true"
            WEBAPOLLO_FEATURE_HAS_GO: "true"
            WEBAPOLLO_FEATURE_HAS_COMMENTS: "true"
            WEBAPOLLO_FEATURE_HAS_STATUS: "true"
            CATALINA_OPTS: "-Xms512m -Xmx1g -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+UseConcMarkSweepGC"
        volumes_from:
            - "galaxy:ro"
        volumes:
            - ./apollo/annotation_groups.tsv:/bootstrap/canned_values.txt:ro # Other canned things are preloaded in the docker image https://github.com/abretaud/docker-apollo/blob/bipaa/bootstrap.sh
            #- ../blat/:/opt/blat/:ro # Mount the blat binary if you want to use it (could not include it in the docker image due to license issue)

    apollo_db:
        image: postgres:9.5
        environment:
            POSTGRES_PASSWORD: password
        volumes:
            - ./docker_data/apollo_db/:/var/lib/postgresql/data/

    apollo-report:  # A report app following guidelines from https://bipaa.genouest.org/is/how-to-annotate-a-genome/
        links:
            - apollo:apollo
        image: quay.io/abretaud/apollo-report:latest
        environment:
            APOLLO_EXT_URL: http://localhost/sp/genus_species/apollo/
            APOLLO_USER: admin_apollo@bipaa
            APOLLO_PASS: XXXXX # See apollo conf above
            ADMIN_USERS: login1,login2 # ldap users that should see an extended report
            APOLLO_MOUNTPOINT: /apollo-data/
        volumes:
            - ./docker_data/apollo/:/apollo-data/:ro
            - ./apollo/annotation_groups.tsv:/data/annotation_groups.tsv:ro
            - ./docker_data/apollo_report/:/data/report/

    blast:
        image: quay.io/abretaud/sf-blast:latest
        links:
            - blast_db:postgres
        #hostname: gogepp-blast.genouest.org    # Hostname declare as submit node in sge conf (for drmaa mode only)
        environment:
            UPLOAD_LIMIT: 20M
            MEMORY_LIMIT: 128M
            DB_NAME: 'postgres'
            ADMIN_EMAIL: 'xxx@example.org'  # email sender
            ADMIN_NAME: 'xxxxx'  # email sender name
            JOBS_METHOD: 'local'   # Can be local (= no sge jobs, but run inside the container) or drmaa (= to submit to a cluster)
            JOBS_WORK_DIR: '/xxxx/blast_jobs/'  # disk accessible both from compute nodes and mounted in this docker (at the same path)
            CDD_DELTA_PATH: '/db/cdd_delta/current/flat/cdd_delta'
            BLAST_TITLE: 'Genus species blast server'
            JOBS_SCHED_NAME: 'blast_gspecies'    # job names
            PRE_CMD: '. /local/env/envblast-2.6.0.sh; . /local/env/envpython-2.7.sh;'    # executed at the beginning of each job
            APACHE_RUN_USER: 'bipaaweb'   # username known by sge
            APACHE_RUN_GROUP: 'bipaa'   # group known by sge
            BASE_URL_PATH: '/sp/genus_species/blast/'
            UID: 55914  # username known by sge (for drmaa mode only)
            GID: 40259  # group known by sge (for drmaa mode only)
        volumes:
            #- ../blast-themes/xxx/:/var/www/blast/app/Resources/:ro # You can theme the app
            - /data1/sge/:/usr/local/sge/:ro # the sge install
            #- /xxxx/blast_jobs/:/xxxx/blast_jobs/ # (for drmaa mode only)
            - ./blast/banks.yml:/var/www/blast/app/config/banks.yml:ro
            - ./blast/links.yml:/etc/blast_links/links.yml:ro

    blast_db:
        image: postgres:9.5
        environment:
            - POSTGRES_PASSWORD=postgres
            - PGDATA=/var/lib/postgresql/data/
        volumes:
            - ./docker_data/blast_db/:/var/lib/postgresql/data/

    wiki:
        image: quay.io/abretaud/mediawiki
        environment:
            MEDIAWIKI_SERVER: http://localhost
            MEDIAWIKI_PROXY_PREFIX: /sp/genus_species/wiki
            MEDIAWIKI_SITENAME: Genus species
            MEDIAWIKI_SECRET_KEY: XXXXXXXXXX
            MEDIAWIKI_DB_PASSWORD: password
            MEDIAWIKI_ADMIN_USER: abretaud   # ldap user
        links:
            - wiki_db:db
        volumes:
            - ./docker_data/wiki_uploads:/images
            #- ../bipaa_wiki.png:/var/www/mediawiki/resources/assets/wiki.png:ro # To cange the logo at the top left

    wiki_db:
        image: postgres:9.5
        volumes:
            - ./docker_data/wiki_db/:/var/lib/postgresql/data/
