#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
services:
  hive:
    image: apache/gravitino-playground:hive-2.7.3
    ports:
      - "3307:3306"
      - "19000:9000"
      - "19083:9083"
      - "60070:50070"
    container_name: playground-hive
    environment:
      - HADOOP_USER_NAME=root
    entrypoint: /bin/bash /tmp/hive/init.sh
    volumes:
      - ./init/hive:/tmp/hive
    healthcheck:
      test: ["CMD", "/tmp/check-status.sh"]
      interval: 10s
      timeout: 60s
      retries: 5
      start_period: 20s

  gravitino:
    image: apache/gravitino:0.6.1-incubating
    entrypoint: /bin/bash /tmp/gravitino/init.sh
    ports:
      - "8090:8090"
      - "9001:9001"
    container_name: playground-gravitino
    depends_on:
      hive :
        condition: service_healthy
      mysql :
        condition: service_healthy
    volumes:
      - ./healthcheck:/tmp/healthcheck
      - ./init/gravitino:/tmp/gravitino
    healthcheck:
      test: ["CMD", "/tmp/healthcheck/gravitino-healthcheck.sh"]
      interval: 5s
      timeout: 60s
      retries: 5
      start_period: 20s

  trino:
    image: apache/gravitino-playground:trino-435-gravitino-0.6.1-incubating
    ports:
      - "18080:8080"
    container_name: playground-trino
    environment:
      - HADOOP_USER_NAME=root
      - GRAVITINO_HOST_IP=gravitino
      - GRAVITINO_HOST_PORT=8090
      - GRAVITINO_METALAKE_NAME=metalake_demo
      - HIVE_HOST_IP=hive
    entrypoint:  /bin/bash /tmp/trino/init.sh
    volumes:
      - ./init/trino:/tmp/trino
      - ./init/common:/tmp/common
      - ./healthcheck:/tmp/healthcheck
    depends_on:
      hive :
        condition: service_healthy
      gravitino :
        condition: service_healthy
    healthcheck:
      test: ["CMD", "/tmp/healthcheck/trino-healthcheck.sh"]
      interval: 10s
      timeout: 60s
      retries: 5
      start_period: 20s

  postgresql:
    image: postgres:13
    container_name: playground-postgresql
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      ALLOW_IP_RANGE: 0.0.0.0/0
    ports:
      - "15432:5432"
    volumes:
      - ./init/postgres:/docker-entrypoint-initdb.d/

  mysql:
    image: mysql:8.0
    container_name: playground-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=mysql
      - MYSQL_USER=mysql
      - MYSQL_PASSWORD=mysql
      - MYSQL_DATABASE=db
    ports:
      - "13306:3306"
    volumes:
      - ./init/mysql:/docker-entrypoint-initdb.d/
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h localhost -pmysql"]
      interval: 5s
      timeout: 60s
      retries: 5
      start_period: 20s

  spark:
    image: spark:3.4.1-scala2.12-java11-ubuntu
    container_name: playground-spark
    entrypoint: /bin/bash /tmp/spark/init.sh
    environment:
      - HADOOP_USER_NAME=root
    ports:
      - "14040:4040"
    volumes:
      - ./init/spark:/tmp/spark
      - ./init/common:/tmp/common

  jupyter:
    image: jupyter/pyspark-notebook:spark-3.4.1
    container_name: playground-jupyter
    ports:
      - 18888:8888
    volumes:
      - ./init/jupyter:/tmp/gravitino
    entrypoint: /bin/bash /tmp/gravitino/init.sh
    depends_on:
      hive :
        condition: service_healthy
      gravitino :
        condition: service_healthy

volumes:
  spark_jars: