services:
  server:
    image: hdalab_server
    build:
      context: .
      dockerfile: docker/server/server.dockerfile
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST:-db}:${POSTGRES_PORT:-5432}/hdalab2
      DJANGO_SECRET: ${DJANGO_SECRET}
      DEBUG: ${DEBUG}
      ADMIN_EMAIL: ${ADMIN_EMAIL}
      BROKER_PASSWORD: ${BROKER_PASSWORD}
    depends_on:
      broker:
        condition: service_started
      db:
        condition: service_healthy
    volumes:
      - ./data_docker/static:/static

  worker:
    image: hdalab_worker
    build:
      context: .
      dockerfile: docker/worker/worker.dockerfile    
    command: celery worker -A hdalab --loglevel=INFO
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST:-db}:${POSTGRES_PORT:-5432}/hdalab2
      DJANGO_SECRET: ${DJANGO_SECRET}
      DEBUG: False
      ADMIN_EMAIL: ${ADMIN_EMAIL}
      BROKER_PASSWORD: ${BROKER_PASSWORD}
    volumes:
      - ./data_docker/static:/static
    depends_on:
      broker:
        condition: service_started
      db:
        condition: service_healthy

  beat:
    image: hdalab_server
    command: celery beat -A hdalab --schedule /celery/beat.db --loglevel=INFO
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST:-db}:${POSTGRES_PORT:-5432}/hdalab2
      DJANGO_SECRET: ${DJANGO_SECRET}
      DEBUG: ${DEBUG}
      ADMIN_EMAIL: ${ADMIN_EMAIL}
      BROKER_PASSWORD: ${BROKER_PASSWORD}
    volumes:
      - ./data_docker/celery:/celery
    depends_on:
      broker:
        condition: service_started
      db:
        condition: service_healthy

  broker:
    image: rabbitmq:3-alpine
    hostname: hdalab_rabbitmq
    environment: 
      RABBITMQ_DEFAULT_USER: iri
      RABBITMQ_DEFAULT_PASS: ${BROKER_PASSWORD}
      RABBITMQ_DEFAULT_VHOST: hdalab

  db:
    image: postgres
    restart: always
    volumes:
      - ./data_docker/db:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: "hdalab2"
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
      POSTGRES_USER: "${POSTGRES_USER}"
      POSTGRES_HOST_AUTH_METHOD: "md5"
      POSTGRES_INITDB_ARGS: "--auth-local=md5"
    healthcheck:
      test: [ "CMD", "pg_isready", "-U", "${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5

  es:
    image: launcher.gcr.io/google/elasticsearch2
    restart: always
    volumes:
      - ./data_docker/es:/usr/share/elasticsearch/data

  caddy:
    build:
      context: docker/web
      dockerfile: web.dockerfile
    volumes:
      - ./data_docker/static:/static
    ports:
      - "80:80"
      - "443:443"

  cache:
    image: docker.io/memcached:alpine
