version: '3.2'

networks:
  {{ epas_haproxy_public_net }}:
    external: true
  {{ epas_docker_network }}:

volumes:
  {{ epas_attachments_volume }}:
    driver: local
    driver_opts:
      type: nfs4
      o: "nfsvers=4,addr=146.48.123.250,rw"
      device: ":/nfs/epas_prod_attachments_data"
{% if epas_dockerized_db %}
  {{ epas_pg_backups_volume }}:
  {{ epas_db_volume }}:
{% endif %}

services:
  {{ epas_docker_service_server_name }}:
    image: {{ epas_docker_server_image }}
    networks:
      - {{ epas_docker_network }}
      - {{ epas_haproxy_public_net }}
    volumes:
      - {{ epas_attachments_volume }}:/home/epas/epas/data/attachments
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    environment:
      - VIRTUAL_HOST={{ epas_server_hostname }}
      - PROTOCOL=https                         # default: http  -- (http,https)
      #      - EPAS_SHIB_LOGIN=                      # default: false  -- (true,false)
      - JOBS_ACTIVE=true                       # default: false  -- (true,false) --  Se forzato a true abilita l'esecuzione di tutti i job
      #      - SKIP_IP_CHECK=                        # default: false -- (true,false) -- Disabilita il controllo sugli indirizzi ip delle richieste
      ######## LOGS ###########
      - LOG_LEVEL={{ epas_log_level }}                            # Opzionale. default: INFO   -- (OFF,FATAL,ERROR,WARN,INFO,DEBUG,TRACE,ALL)
      - APPENDERS={{ epas_log_appenders }}                        # Opzionale. default: stdout, stderr -- (stdout, stderr, file, graylog2). Abilita i log sulla console, file e server graylog
      #      - GRAYLOG_HOST=                         # Obbligatorio se attivato log sull'appender graylog2. default: null
      #      - GRAYLOG_PORT=                         # Opzionale. default: 3514
      #      - GRAYLOG_ORIGIN_HOST=                  # Opzionale. default: valore in VIRTUAL_HOST
      ###### Container ########
      #      - BACKUP_CRON=                          # default: disattivato. (utilizzare il format del crontab. Es. 0 0 * * *)
      #      - CERT_NAME=                            # default: valore specificato in VIRTUAL_HOST -- Specifica un nome diverso per i file del certificato SSL
      - TZ=Europe/Rome
      #### Connessione DB ####
      - DB_HOST={{ epas_db_host }}                     # default: indirizzo assegnato al container postgres linkato
      - DB_NAME={{ epas_db_name }}                     # default: epas
      - DB_PASS={{ epas_db_pwd }}                     # default: "non necessaria"
      - DB_PORT=5432                           # default: 5432
      - DB_USER={{ epas_db_user }}                     # default: postgres
      #### Teleworker
      - TELEWORK_ACTIVE={{ epas_teleworker_server_active }}   # default: false
      - TELEWORK_BASEURL={{ epas_teleworker_server_baseurl }}   # default: http://teleworkerepas.isti.cnr.it:8080
      - TELEWORK_USER={{ epas_teleworker_server_user }}   # default: app.epas
      - TELEWORK_PASS={{ epas_teleworker_server_password }}   # default: chiedere al team di sviluppo
      #### server SMTP ####
      - SMTP_HOST={{ epas_smtp_server }}                # default: smtp.cnr.it
      - SMTP_PORT={{ epas_smtp_port }}                # default: 25 se SMTP_CHANNEL è impostato clear o starttls; 465 se impostato su ssl
      - SMTP_CHANNEL={{ epas_smtp_channel }}          # default: clear -- (clear, ssl ,starttls)
      - SMTP_FROM={{ epas_smtp_from }}                # default: epas@cnr.it -- Indirizzo utilizzato per il campo mittente delle mail inviate dal sistema
      - SMTP_PROTOCOL={{ epas_smtp_protocol}}        # default: smtp -- (smtp, smtps)
{% if epas_smtp_authentication %}
      - SMTP_USER={{ epas_smtp_user }}                # user utilizzato per l'autenticazione sul server smtp (se necessario)
      - SMTP_PASS={{ epas_smtp_password }}                # password utilizzato per l'autenticazione sul server smtp (se necessaria)
{% endif %}
      #### Autenticazione LDAP ####
      - LDAP_LOGIN={{ epas_ldap_login }}                       # default: false. Impostare a true per attivare l'autenticazione tramite LDAP
      - LDAP_URL={{ epas_ldap_url }}                  # url del server LDAP, per esempio ldap://ldap.cnr.it:389
      - LDAP_STARTTLS={{ epas_ldap_starttls_enabled }} # Deve valere true quando è richiesto TLS sulla porta 389. False quando viene usato ldaps sulla 636
      - LDAP_TIMEOUT={{ epas_ldap_timeout }}          # default: 1000. Time in millisecondi della connessione LDAP.
      - LDAP_DN_BASE={{ epas_ldap_base_dn }}          # DN per la ricerca degli utenti su LDAP, per esempio ou=People,dc=iit,dc=cnr,dc=it
      - LDAP_LOGIN_RETURN={{ epas_ldap_login_return_uri }} # default: /. Indirizzo relativo di reindirizzamento dopo il login LDAP.
      - LDAP_EPPN_ATTRIBUTE_NAME={{ epas_ldap_eppn_attribute_name }}  # default: eduPersonPrincipalName. Campo LDAP utilizzato per il mapping con il campo eppn presente in ePAS.
{% if epas_ldap_authenticated_bind %}
      - LDAP_BIND_DN={{ epas_ldap_bind_dn }}
      - LDAP_BIND_CREDENTIALS={{ epas_ldap_bind_credentials }}
      - LDAP_AUTHENTICATE_USER_SEARCH_DN={{ epas_ldap_authenticate_user_search_dn }}
{% endif %}
{% if epas_flows_enabled %}
      - FLOWS_ACTIVE=true                     # defalut: false --(true,false) -- se impostato a true abilita l'utilizzo dei flussi interni a ePAS
      - URL_ATTESTATI={{ epas_attestati_url }}                        # default: https://attestativ2.rm.cnr.it
      - URL_USER={{ epas_attestati_user }}
      - URL_PASS={{ epas_attestati_password }}
{% endif %}
      #### Invio Segnalazioni via email
      #- REPORT_TO=${REPORT_TO}                 # default: epas@iit.cnr.it
      #- REPORT_FROM=${REPORT_FROM}             # default: segnalazioni@epas.tools.iit.cnr.it
      #- REPORT_SUBJECT=${REPORT_SUBJECT}       # default: Segnalazione ePAS
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: dnsrr
      placement:
        constraints:
          - node.role == worker
          - {{ epas_node_constraints }}
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
    logging:
      driver: 'journald'

{% if epas_dockerized_db %}
  postgres:
    image: {{ epas_db_image }}
    environment:
      POSTGRES_PASSWORD: {{ epas_db_pwd }}
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PORT: 5432
      PGDATA: /var/lib/postgresql/data/pg_data
    networks:
      - {{ epas_docker_network }}
    volumes:
      - {{ epas_pg_data_volume }}:/var/lib/postgresql/data/pg_data
      - {{ epas_pg_backups_volume }}:/tmp:ro
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: dnsrr
      placement:
        constraints: {{ epas_db_constraints }}
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
    logging:
      driver: 'journald'
{% endif %}