version: "3.4"

services:
  redis:
    image: redis:alpine

  mailhog:
    image: mailhog/mailhog
    ports:
      - "1025:1025"
      - "8025:8025"

  pgdb:
    image: postgres:11.7
    environment:
      POSTGRES_PASSWORD: bad_db_passwd
      POSTGRES_USER: core_notifications
      POSTGRES_DB: core_notifications
    ports:
      - "5432:5432"
    command: [ "postgres", "-c", "log_statement=all", "-c", "fsync=off", "-c", "full_page_writes=off" ]

  pg_m:
    build:
      context: .
      dockerfile: ./migrations/Dockerfile
    env_file:
      - .env
    volumes:
      - ./migrations:/sqitch/migrations
    command: [ "--", "--verify" ]
    depends_on:
      - pgdb

  app:
    build:
      context: .
      target: deploy
    env_file:
      - .env
    volumes:
      - '.:/core-notifications'
    ports:
      - "8001:8000"
    depends_on:
      - redis
      - pgdb

  app_https:
    build:
      context: .
      target: deploy
    env_file:
      - .env
    volumes:
      - '.:/core-notifications'
    ports:
      - "443:8000"
    depends_on:
      - redis
      - pgdb
    working_dir: "/core-notifications"
    command: "/opt/venv/bin/gunicorn core_notifications.wsgi:application -c /etc/gunicorn/gunicorn_config.py --reload --certfile=local.atlas.stream.pem --keyfile=local.atlas.stream-key.pem"

  celery_worker:
    build:
      context: .
      target: deploy
    env_file:
      - .env
    volumes:
      - '.:/core-notifications'
    entrypoint: ["/opt/venv/bin/celery", "-A", "core_notifications.celery_worker.celery", "worker", "--loglevel=info"]
    depends_on:
      - redis
      - pgdb

  celery_beat:
    build:
      context: .
      target: deploy
    env_file:
      - .env
    volumes:
      - '.:/core-notifications'
    entrypoint: ["/opt/venv/bin/celery", "-A", "core_notifications.celery_worker.celery", "beat", "--loglevel=info"]
    depends_on:
      - redis
      - pgdb

  celery_flower:
    build:
      context: .
      target: deploy
    env_file:
      - .env
    volumes:
      - '.:/core-notifications'
    ports:
      - "5555:5555"
    entrypoint: [ "/opt/venv/bin/celery", "-A", "core_notifications.celery_worker.celery", "flower"]
    depends_on:
      - redis
      - pgdb
