version: "3.9"

services:
  mailhog:
    image: mailhog/mailhog
    profiles: ["dev", "mailhog"]
    ports:
    - ${MAILHOG_GUI_PORT}:8025
    environment:
    - MAILHOG_GUI_PORT
    networks:
      - internal

  ftpd-server:
    image: stilliard/pure-ftpd:hardened
    profiles: ["ftp-server"]
    environment:
      FTP_USER_NAME: "dev"
      FTP_USER_PASS: "dev"
      FTP_USER_HOME: "/home/dev"
    volumes:
      - ${PHRASEANET_FTP_DIR}:/home/dev
    restart: on-failure
    networks:
      - internal

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    profiles: ["dev", "pma"]
    restart: on-failure
    ports:
      - ${PHRASEANET_PHPMYADMIN_PORT}:80
    depends_on:
      - db
    networks:
      - internal

  kibana:
    image: kibana:4.6.6
    profiles: ["elk"]
    ports:
      - 5601:5601
    links:
      - elasticsearch
    depends_on:
      - elasticsearch
    networks:
      - internal

  logstash:
    image: logstash:7.6.2
    profiles: ["elk"]
    links:
      - elasticsearch
    volumes:
      - ${PHRASEANET_CONFIG_DIR}:/var/alchemy/Phraseanet/config:rw
    command: logstash -f /var/alchemy/Phraseanet/config/logstash.conf
    depends_on:
      - elasticsearch
    restart: on-failure
    networks:
      - internal

  filebeat:
    hostname: filebeat
    image: "docker.elastic.co/beats/filebeat:7.6.2"
    profiles: ["elk"]
    volumes:
      - ${PHRASEANET_CONFIG_DIR}/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
      - ${PHRASEANET_LOGS_DIR}:/var/alchemy/Phraseanet/logs:ro
    command: filebeat run -e --strict.perms=false
    restart: on-failure
    networks:
      - internal

  db-backup:
    image: fradelg/mysql-cron-backup
    profiles: ["db-backup"]
    depends_on:
      - db
    volumes:
      - ${DB_BACKUP_VOLUME_PATH}/backup:/backup
    networks:
      - internal
    environment:
      - MYSQL_HOST=${DB_BACKUP_MYSQL_HOST}
      - MYSQL_USER=${DB_BACKUP_MYSQL_USER}
      - MYSQL_PASS=${MYSQL_ROOT_PASSWORD}
      - MAX_BACKUPS=${DB_BACKUP_MAX_BACKUPS}
      - INIT_BACKUP=${DB_BACKUP_INIT_BACKUP}
      - INIT_RESTORE_LATEST=${DB_BACKUP_INIT_RESTORE_LATEST}
      - CRON_TIME=${DB_BACKUP_CRON_TIME}
      - GZIP_LEVEL=${DB_BACKUP_GZIP_LEVEL}
    restart: unless-stopped

  phraseanet-saml-sp:
    build:
      context: .
      target: phraseanet-saml-sp
      args:
        - SSH_PRIVATE_KEY=${PHRASEANET_SSH_PRIVATE_KEY}
        - PHRASEANET_PLUGINS=${PHRASEANET_PLUGINS}
    image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-saml-sp:$PHRASEANET_DOCKER_TAG
    profiles: ["phraseanet-saml-sp"]
    restart: on-failure
    volumes:
    - ${SAML_IDP_METADATA_LOCAL_CONFIG_DIR}:/var/www/simplesamlphp-1.10.0/metadata:rw
    - ${SAML_SP_CONFIG_DIR}:/var/www/simplesamlphp-1.10.0/config:rw
    - ${SAML_SP_CERT_DIR}:/var/www/simplesamlphp-1.10.0/cert:rw
    depends_on:
    - phraseanet
    environment:
    - MAX_BODY_SIZE
    - GATEWAY_SEND_TIMEOUT
    - GATEWAY_PROXY_TIMEOUT
    - GATEWAY_FASTCGI_TIMEOUT
    - SESSION_SAVE_HANDLER
    - SESSION_SAVE_PATH
    - SAML_PHRASEANET_HOST
    - SAML_SP_AUTHSOURCES  
    - SAML_IDP_METADATA_CONFIG
    - SAML_IDP_METADATA_LOCAL_CONFIG_DIR
    - SAML_ALLOW_DEBUG

    ports:
      - 8080:8080
    networks:
      - internal

  #squid:
  #  image: sameersbn/squid:3.5.27-2
  #  profiles: ["squid"]
  #  ports:
  #    - ${PHRASEANET_SQUID_PORT}:3128
  #  volumes:
  #    - ${PHRASEANET_SQUID_DIR}:/var/spool/squid
  #    - ${PHRASEANET_SQUID_CONF}:/etc/squid/squid.conf
  #    - ${PHRASEANET_LOGS_DIR}/squid:/var/log/squid
  #  restart: always
  #  networks:
  #    - internal
