version: '2.1'
services:
    redis:
        image: 'redis:3.2.7'
        # command: redis-server --requirepass redispass

    postgres:
        image: postgres:9.6
        environment:
            - POSTGRES_USER=airflow
            - POSTGRES_PASSWORD=airflow
            - POSTGRES_DB=airflow
        # Uncomment these lines to persist data on the local filesystem.
            - PGDATA=/var/lib/postgresql/data/pgdata
        volumes:
            - ../pgdata:/var/lib/postgresql/data/pgdata

    webserver:
        image: aiscalator/airflow:latest
        restart: always
        depends_on:
            - postgres
            - redis
        environment:
            - LOAD_EX=n
            - FERNET_KEY=46BKJoQYlPPOexq0OhDZnIlNepKFf87WFwLbfzqDDho=
            - EXECUTOR=Celery
            # - POSTGRES_USER=airflow
            # - POSTGRES_PASSWORD=airflow
            # - POSTGRES_DB=airflow
            # - REDIS_PASSWORD=redispass
        volumes:
            - ../dags:/usr/local/airflow/dags
            - ./airflow.cfg:/usr/local/airflow/airflow.cfg
            # Uncomment to include custom plugins
            # - ../plugins:/usr/local/airflow/plugins
        ports:
            - "8080:8080"
        command: webserver
        healthcheck:
            test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
            interval: 30s
            timeout: 30s
            retries: 3

    flower:
        image: aiscalator/airflow:latest
        restart: always
        depends_on:
            - redis
        environment:
            - EXECUTOR=Celery
            # - REDIS_PASSWORD=redispass
        ports:
            - "5555:5555"
        command: flower

    scheduler:
        image: aiscalator/airflow:latest
        restart: always
        depends_on:
            - webserver
        volumes:
            - ../dags:/usr/local/airflow/dags
            # Uncomment to include custom plugins
            # - ../plugins:/usr/local/airflow/plugins
        environment:
            - LOAD_EX=n
            - FERNET_KEY=46BKJoQYlPPOexq0OhDZnIlNepKFf87WFwLbfzqDDho=
            - EXECUTOR=Celery
            # - POSTGRES_USER=airflow
            # - POSTGRES_PASSWORD=airflow
            # - POSTGRES_DB=airflow
            # - REDIS_PASSWORD=redispass
        command: scheduler

    worker:
        image: aiscalator/airflow:latest
        restart: always
        depends_on:
            - scheduler
        volumes:
            - ../dags:/usr/local/airflow/dags
            - .env:/usr/local/airflow/.env
            - /var/run/docker.sock:/var/run/docker.sock
            # Custom workspace folders to mount, add below
            # - workspace #
            # Uncomment to include custom plugins
            # - ../plugins:/usr/local/airflow/plugins
        environment:
            - FERNET_KEY=46BKJoQYlPPOexq0OhDZnIlNepKFf87WFwLbfzqDDho=
            - EXECUTOR=Celery
            # - POSTGRES_USER=airflow
            # - POSTGRES_PASSWORD=airflow
            # - POSTGRES_DB=airflow
            # - REDIS_PASSWORD=redispass
        env_file:
            - .env
        command: worker
