version: "3.4"

services:
  gateway:
    build:
      context: .
      target: phraseanet-nginx
      args:
        - SSH_PRIVATE_KEY=${PHRASEANET_SSH_PRIVATE_KEY}
        - PHRASEANET_PLUGINS=${PHRASEANET_PLUGINS}
    image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-nginx:$PHRASEANET_DOCKER_TAG
    restart: on-failure
    volumes:
    - ${PHRASEANET_DATA_DIR}:/var/alchemy/Phraseanet/datas:rw
    - ${PHRASEANET_THUMBNAILS_DIR}:/var/alchemy/Phraseanet/www/thumbnails:rw
    - ${PHRASEANET_CUSTOM_DIR}:/var/alchemy/Phraseanet/www/custom:rw
    - ${PHRASEANET_PLUGINS_DIR}:/var/alchemy/Phraseanet/www/plugins:rw
    depends_on:
    - phraseanet
    environment:
    - MAX_BODY_SIZE
    ports:
      - ${PHRASEANET_APP_PORT}:80

  phraseanet:
    build:
      context: .
      target: phraseanet-fpm
      args:
        - SSH_PRIVATE_KEY=${PHRASEANET_SSH_PRIVATE_KEY}
        - PHRASEANET_PLUGINS=${PHRASEANET_PLUGINS}
    image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-fpm:$PHRASEANET_DOCKER_TAG
    restart: on-failure
    depends_on:
    - db
    - redis
    - rabbitmq
    - elasticsearch
    environment:
    - PHRASEANET_PROJECT_NAME
    - MAX_BODY_SIZE
    - MAX_INPUT_VARS
    - OPCACHE_ENABLED
    - SESSION_CACHE_LIMITER
    - PHP_LOG_LEVEL
    - PHRASEANET_ADMIN_ACCOUNT_EMAIL
    - PHRASEANET_ADMIN_ACCOUNT_PASSWORD
    - PHRASEANET_DB_HOST
    - PHRASEANET_DB_PORT
    - PHRASEANET_DB_USER
    - PHRASEANET_DB_PASSWORD
    - INSTALL_DB_TEMPLATE
    - INSTALL_APPBOX
    - INSTALL_DATABOX
    - PHRASEANET_SERVER_NAME
    - PHRASEANET_RABBITMQ_USER=$RABBITMQ_DEFAULT_USER
    - PHRASEANET_RABBITMQ_PASSWORD=$RABBITMQ_DEFAULT_PASS
    - PHRASEANET_EMITTER_EMAIL
    - PHRASEANET_MAIL_OBJECT_PREFIX
    - PHRASEANET_SMTP_ENABLED
    - PHRASEANET_SMTP_HOST
    - PHRASEANET_SMTP_PORT
    - PHRASEANET_SMTP_AUTH_ENABLED
    - PHRASEANET_SMTP_SECURE_MODE
    - PHRASEANET_SMTP_USER
    - PHRASEANET_SMTP_PASSWORD
    - PHRASEANET_DOWNLOAD_DIR
    - PHRASEANET_LAZARET_DIR
    - PHRASEANET_CAPTION_DIR
    - PHRASEANET_WORKER_TMP
    - LC_MESSAGES=C.UTF-8
    - LC_COLLATE=C.UTF-8
    - LC_IDENTIFICATION=C.UTF-8
    - LANG=C.UTF-8
    - LC_MEASUREMENT=C.UTF-8   
    - LC_CTYPE=C.UTF-8
    - LC_TIME=C.UTF-8
    - LC_NAME=C.UTF-8

    volumes:
    - ${PHRASEANET_CONFIG_DIR}:/var/alchemy/Phraseanet/config:rw
    - ${PHRASEANET_LOGS_DIR}:/var/alchemy/Phraseanet/logs:rw
    - ${PHRASEANET_DATA_DIR}:/var/alchemy/Phraseanet/datas:rw
    - ${PHRASEANET_THUMBNAILS_DIR}:/var/alchemy/Phraseanet/www/thumbnails:rw
    - ${PHRASEANET_CUSTOM_DIR}:/var/alchemy/Phraseanet/www/custom:rw
    - ${PHRASEANET_PLUGINS_DIR}:/var/alchemy/Phraseanet/www/plugins:rw
    - ${PHRASEANET_CACHE_DIR}:/var/alchemy/Phraseanet/cache:rw
    - ${PHRASEANET_TMP_DIR}:/var/alchemy/Phraseanet/tmp:rw

  worker:
    build:
      context: .
      target: phraseanet-worker
      args:
        - SSH_PRIVATE_KEY=${PHRASEANET_SSH_PRIVATE_KEY}
        - PHRASEANET_PLUGINS=${PHRASEANET_PLUGINS}
    image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-worker:$PHRASEANET_DOCKER_TAG
    restart: on-failure
    depends_on:
    - db
    - redis
    - rabbitmq
    - elasticsearch
    environment:
    - PHRASEANET_PROJECT_NAME
    - MAX_BODY_SIZE
    - MAX_INPUT_VARS
    - OPCACHE_ENABLED
    - SESSION_CACHE_LIMITER
    - PHP_LOG_LEVEL
    - LC_MESSAGES=C.UTF-8
    - LC_COLLATE=C.UTF-8
    - LC_IDENTIFICATION=C.UTF-8
    - LANG=C.UTF-8
    - LC_MEASUREMENT=C.UTF-8   
    - LC_CTYPE=C.UTF-8
    - LC_TIME=C.UTF-8
    - LC_NAME=C.UTF-8

    volumes:
    - ${PHRASEANET_CONFIG_DIR}:/var/alchemy/Phraseanet/config:rw
    - ${PHRASEANET_LOGS_DIR}:/var/alchemy/Phraseanet/logs:rw
    - ${PHRASEANET_DATA_DIR}:/var/alchemy/Phraseanet/datas:rw
    - ${PHRASEANET_THUMBNAILS_DIR}:/var/alchemy/Phraseanet/www/thumbnails:rw
    - ${PHRASEANET_CUSTOM_DIR}:/var/alchemy/Phraseanet/www/custom:rw
    - ${PHRASEANET_CACHE_DIR}:/var/alchemy/Phraseanet/cache:rw
    - ${PHRASEANET_TMP_DIR}:/var/alchemy/Phraseanet/tmp:rw

  db:
    image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-db:$PHRASEANET_DOCKER_TAG
    build: ./docker/db
    restart: on-failure
    environment:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_MAX_ALLOWED_PACKET
    volumes:
    - ${PHRASEANET_DB_DIR}:/var/lib/mysql

  rabbitmq:
    image: rabbitmq:3-management
    restart: on-failure
    environment:
    - RABBITMQ_DEFAULT_USER
    - RABBITMQ_DEFAULT_PASS

  redis:
    image: redis
    restart: on-failure

  elasticsearch:
    image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-elasticsearch:$PHRASEANET_DOCKER_TAG
    build: ./docker/elasticsearch
    restart: on-failure
    volumes:
    - ${PHRASEANET_ELASTICSEARCH_DIR}:/usr/share/elasticsearch/data

  mailhog:
    image: mailhog/mailhog
    ports:
    - 1025:1025
    - 8025:8025

volumes:
  config_vol:
    driver: local
  data_vol:
    driver: local
  tmp_vol:
    driver: local
  db_vol:
    driver: local
  elasticsearch_vol:
    driver: local
  thumbnails_vol:
    driver: local
  custom_vol:
    driver: local
  plugins_dir:
    driver: local
  cache_vol:
    driver: local
  # to be replacer by stdout/stderr
  logs_vol:
    driver: local
  dev_vol:
    driver: local
