version: "3.8"
services:

  frontend:
    image: "${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}"
    depends_on:
      - backend
    ports:
      - "80:80"
    networks:
      - net

  backend:
    image: "${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}"
    depends_on:
      - db
    ports:
      - "8080:8080"
    env_file:
      - .env
    environment:
      - PROJECT_NAME="LEIP Enterprise"
      - SERVER_HOST=${SERVER_HOST?Variable not set}
      - PORT=8080
      - BACKEND_CORS_ORIGINS=["$SERVER_HOST"]
      - POSTGRES_SERVER=db
      - POSTGRES_DB=app
      - ELASTIC_HOST=http://elasticsearch:9200
      - ELASTIC_INDEX_FOR_EVENTS=events
    networks:
      - net

  db:
    image: postgres:12
    volumes:
      - app-db-data:/var/lib/postgresql/data/pgdata
    env_file:
      - .env
    environment:
      - PGDATA=/var/lib/postgresql/data/pgdata
      - POSTGRES_DB=app
    deploy:
      placement:
        constraints:
          - node.labels.${STACK_NAME?Variable not set}.app-db-data == true
    networks:
      - net

  elasticsearch:
    image: "${DOCKER_IMAGE_ELASTIC?Variable not set}:${ELK_VERSION}"
    volumes:
      - type: volume
        source: elasticsearch
        target: /usr/share/elasticsearch/data
    env_file:
      - .env
    environment:
      ES_JAVA_OPTS: "-Xmx512m -Xms512m"
      ELASTIC_PASSWORD: "${ELASTIC_PASSWORD}"
      discovery.type: single-node
      xpack.license.self_generated.type: "basic"
      xpack.security.enabled: "true"
    networks:
      - net

  kibana:
    profiles:
      - kibana
    image: "${DOCKER_IMAGE_KIBANA?Variable not set}:${ELK_VERSION}"
    ports:
      - "5601:5601"
    environment:
      ELASTICSEARCH_USERNAME: $ELASTIC_USERNAME
      ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD
    depends_on:
      - elasticsearch
    networks:
      - net

volumes:
  app-db-data:
  elasticsearch:

networks:
  net:
