version: '2'

services:
  service-ram:
    build: .
    image: registry.forge.grandlyon.com/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server:${TAG}
    ports:
      - ${SERVICE_API_BIND_PORT}:3000
    extra_hosts:
      - 'sen.grandlyon.com:10.128.16.229'
    environment:
      MONGO_NON_ROOT_USERNAME: ${MONGO_NON_ROOT_USERNAME}
      MONGO_NON_ROOT_PASSWORD: ${MONGO_NON_ROOT_PASSWORD}
      MONGO_DB_HOST_AND_PORT: ${MONGO_DB_HOST_AND_PORT}
      JWT_SECRET: ${JWT_SECRET}
      SALT: ${SALT}
      MAIL_URL: ${MAIL_URL}
      MAIL_TOKEN: ${MAIL_TOKEN}
      NODE_ENV: ${NODE_ENV}
      APTIC_TOKEN: ${APTIC_TOKEN}
      GHOST_HOST_AND_PORT: ${GHOST_HOST_AND_PORT}
      GHOST_ADMIN_API_KEY: ${GHOST_ADMIN_API_KEY}
      GHOST_CONTENT_API_KEY: ${GHOST_CONTENT_API_KEY}
      ELASTICSEARCH_NODE: ${ELASTICSEARCH_NODE}
      ELASTICSEARCH_USERNAME: ${ELASTICSEARCH_USERNAME}
      ELASTICSEARCH_PASSWORD: ${ELASTICSEARCH_PASSWORD}
    restart: unless-stopped
    depends_on:
      - database-ram

  database-ram:
    image: bitnami/mongodb:4.2.3
    user: root
    environment:
      MONGODB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
      MONGODB_USERNAME: ${MONGO_NON_ROOT_USERNAME}
      MONGODB_PASSWORD: ${MONGO_NON_ROOT_PASSWORD}
      MONGODB_DATABASE: ram
    restart: unless-stopped
    ports:
      - ${MONGO_PORT}:27017
    volumes:
      - db-ram:/bitnami

  mongo-express:
    image: mongo-express
    restart: unless-stopped
    depends_on:
      - database-ram
    ports:
      - ${ME_PORT}:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_ROOT_PASSWORD}
      ME_CONFIG_BASICAUTH_USERNAME: ${ME_CONFIG_BASICAUTH_USERNAME}
      ME_CONFIG_BASICAUTH_PASSWORD: ${ME_CONFIG_BASICAUTH_PASSWORD}
      ME_CONFIG_MONGODB_SERVER: database-ram

  ghost:
    image: ghost:latest
    restart: always
    ports:
      - ${GHOST_PORT}:2368
    environment:
      # see https://docs.ghost.org/docs/config#section-running-ghost-with-config-env-variables
      database__client: mysql
      database__connection__host: ghost-db
      database__connection__user: root
      database__connection__password: ${GHOST_DB_PASSWORD}
      database__connection__database: ghost
      # this url value is just an example, and is likely wrong for your environment!
      url: http://localhost:${GHOST_PORT}

  ghost-db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${GHOST_DB_PASSWORD}
    volumes:
      - db-ghost

  es01:
    image: elasticsearch:7.6.1
    restart: unless-stopped
    environment:
      node.name: es01
      cluster.name: es-docker-cluster
      discovery.type: single-node
      xpack.security.enabled: ${ELASTIC_SECURITY}
      ELASTIC_PASSWORD: ${ELASTICSEARCH_PASSWORD}
    volumes:
      - db-elastic
    networks:
      - elastic
    ports:
      - ${ELASTICSEARCH_PORT}:9200

  kib01:
    image: docker.elastic.co/kibana/kibana:7.6.1
    restart: unless-stopped
    container_name: kib01
    ports:
      - ${KIBANA_PORT}:5601
    environment:
      ELASTICSEARCH_URL: http://es01:9200
      ELASTICSEARCH_HOSTS: '["http://es01:9200"]'
      ELASTICSEARCH_USERNAME: elastic
      ELASTICSEARCH_PASSWORD: ${ELASTICSEARCH_PASSWORD}
    depends_on:
      - es01
    networks:
      - elastic

volumes:
  db-ram:
  db-ghost:
  db-elastic:

networks:
  elastic:
    driver: bridge
