version: "3"
volumes:
  esdata1:
  redisdata1:
services:
  db:
    image: mariadb:10.5.4-focal 
    environment:
      - MYSQL_ROOT_PASSWORD=CHANGE THIS PASSWORD
    ports:
      - "33062:3306"
    command:
      [
        "mysqld",
        "--sql-mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION",
      ]
    volumes:
      - .:/var/lib/mysql:rw
  redis:
    image: redis:5
    ports:
      - "4379:6379"
    volumes:
      - .:/var/lib/redis:rw
  es:
    image: docker.elastic.co/elasticsearch/elasticsearch:9.1.3
    ports:
      - "9201:9200"
      - "9301:9300"
      - "9401:9400"
    volumes:
      - ./elastic-data:/usr/share/elasticsearch/data:rw
    environment:
      - RAILS_ENV=production
      - cluster.name=change_me
      - node.name=change_me-node
      - http.port=9200
      - bootstrap.memory_lock=false
      - "ES_JAVA_OPTS=-Xms6g -Xmx6g"
      - discovery.type=single-node
      # Silence "security features are not enabled" warnings
      # https://github.com/elastic/elasticsearch/issues/78500
      - xpack.security.enabled=false
      - network.host=0.0.0.0
      - transport.host=0.0.0.0
      - http.host=0.0.0.0
  mc:
    image: memcached:1.5
    ports:
      - "11711:11211"
  web:
    links:
      - "es:elastic"
    profiles:
      - dev
    build:
      context: .
      dockerfile: ./config/docker/Dockerfile
    environment:
      - RAILS_ENV=production
      - ES_URL=es:9200
    command: bash -c "rm -f tmp/pids/server.pid && RAILS_ENV=production bundle exec rails server -p 3351 -b 0.0.0.0"
    volumes:
      - ./bundler_gems:/usr/local/bundle/
      - .:/otwa
    ports:
      - "3351:3351"
    depends_on:
      - db
      - redis
      - es
      - mc
  worker:
    build:
      context: .
      dockerfile: ./config/docker/Dockerfile
    environment:
      - RAILS_ENV=production
      - REDIS_URL=redis://redis:6379
    volumes:
      - ./bunder_gems:/usr/local/bundle/
      - .:/otwa
    depends_on:
      - db
      - redis
      - es
      - mc
    entrypoint: ./entrypoints/worker-entrypoint.sh
  sc:
    build:
      context: .
      dockerfile: ./config/docker/Dockerfile
    environment:
      - RAILS_ENV=production
      - REDIS_URL=redis://redis:6379
    volumes:
      - ./bunder_gems:/usr/local/bundle/
      - .:/otwa
    depends_on:
      - db
      - redis
      - es
      - mc
      - worker
    entrypoint: ./entrypoints/sc-entrypoint.sh



