说明
Domino项目是一个开源任务调度平台,结合Apache Airflow使用,使Airflow的web界面更直观。
项目代码:https://github.com/Tauffer-Consulting/domino
后续更新计划
去掉对GitHub的依赖,适配主流的国内外代码平台
增加组件自定义配置,适配最新版airflow
创建文件
.env
bash
# Airflow配置
AIRFLOW_UID=50000
AIRFLOW_GID=0
# Domino配置
DOMINO_COMPOSE_DEV=true
# GitHub个人账户的令牌在GitHub网站的开发者配置里创建
DOMINO_DEFAULT_PIECES_REPOSITORY_TOKEN=GitHub个人账户的令牌
DOMINO_CREATE_DEFAULT_USER=true
# 数据库配置
POSTGRES_USER=domino
POSTGRES_PASSWORD=domino_password
POSTGRES_DB=domino
# Redis配置
REDIS_PASSWORD=redis_password
# Domino管理员配置,强制内置,不支持自定义。
DOMINO_ADMIN_EMAIL=admin@example.com
DOMINO_ADMIN_PASSWORD=admin
compose.yaml
注意,需修改domino-rest中的API URL配置。
bash
# Basic Airflow cluster configuration for CeleryExecutor with Redis and PostgreSQL.
# WARNING: This configuration is for local development. Do not use it in a production deployment.
---
x-airflow-common:
&airflow-common
image: apache/airflow:2.7.2-python3.9
environment:
&airflow-common-env
AIRFLOW__CORE__EXECUTOR: CeleryExecutor
AIRFLOW__DATABASE__SQL_ALCHEMY_CONN: postgresql+psycopg2://airflow:airflow@postgres/airflow
AIRFLOW__CORE__SQL_ALCHEMY_CONN: postgresql+psycopg2://airflow:airflow@postgres/airflow
AIRFLOW__CELERY__RESULT_BACKEND: db+postgresql://airflow:airflow@postgres/airflow
AIRFLOW__CELERY__BROKER_URL: redis://:@redis:6379/0
AIRFLOW__CORE__FERNET_KEY: ''
AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: 'true'
AIRFLOW__CORE__LOAD_EXAMPLES: 'false'
AIRFLOW__API__AUTH_BACKENDS: 'airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session'
AIRFLOW__SCHEDULER__ENABLE_HEALTH_CHECK: 'true'
AIRFLOW__SCHEDULER__DAG_DIR_LIST_INTERVAL: 10
_PIP_ADDITIONAL_REQUIREMENTS: ${_PIP_ADDITIONAL_REQUIREMENTS:-}
volumes:
- ${AIRFLOW_PROJ_DIR:-./airflow}/dags:/opt/airflow/dags
- ${AIRFLOW_PROJ_DIR:-./airflow}/logs:/opt/airflow/logs
- ${AIRFLOW_PROJ_DIR:-./airflow}/plugins:/opt/airflow/plugins
user: "${AIRFLOW_UID:-50000}:0"
depends_on:
&airflow-common-depends-on
redis:
condition: service_healthy
postgres:
condition: service_healthy
services:
postgres:
image: postgres:13
container_name: airflow-postgres
environment:
POSTGRES_USER: airflow
POSTGRES_PASSWORD: airflow
POSTGRES_DB: airflow
volumes:
- airflow_postgres_data:/var/lib/postgresql/data
healthcheck:
test: [ "CMD", "pg_isready", "-U", "airflow" ]
interval: 10s
retries: 5
start_period: 5s
restart: always
networks:
- domino-net
redis:
image: redis:latest
container_name: airflow-redis
expose:
- 6379
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 10s
timeout: 30s
retries: 50
start_period: 30s
restart: always
networks:
- domino-net
airflow-webserver:
<<: *airflow-common
container_name: airflow-webserver
command: webserver
ports:
- "8080:8080"
healthcheck:
test:
[
"CMD",
"curl",
"--fail",
"http://localhost:8080/health"
]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
restart: always
depends_on:
<<: *airflow-common-depends-on
airflow-init:
condition: service_completed_successfully
networks:
- domino-net
airflow-triggerer:
<<: *airflow-common
container_name: airflow-triggerer
command: triggerer
healthcheck:
test:
[
"CMD-SHELL",
'airflow jobs check --job-type TriggererJob --hostname "$${HOSTNAME}"'
]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
restart: always
depends_on:
<<: *airflow-common-depends-on
airflow-init:
condition: service_completed_successfully
networks:
- domino-net
airflow-init:
<<: *airflow-common
container_name: airflow-init
entrypoint: /bin/bash
command:
- -c
- |
function ver() {
printf "%04d%04d%04d%04d" $${1//./ }
}
airflow_version=$$(AIRFLOW__LOGGING__LOGGING_LEVEL=INFO && gosu airflow airflow version)
airflow_version_comparable=$$(ver $${airflow_version})
min_airflow_version=2.2.0
min_airflow_version_comparable=$$(ver $${min_airflow_version})
if (( airflow_version_comparable < min_airflow_version_comparable )); then
echo
echo -e "\033[1;31mERROR!!!: Too old Airflow version $${airflow_version}!\e[0m"
echo "The minimum Airflow version supported: $${min_airflow_version}. Only use this or higher!"
echo
exit 1
fi
if [[ -z "${AIRFLOW_UID}" ]]; then
echo
echo -e "\033[1;33mWARNING!!!: AIRFLOW_UID not set!\e[0m"
echo "If you are on Linux, you SHOULD follow the instructions below to set "
echo "AIRFLOW_UID environment variable, otherwise files will be owned by root."
echo "For other operating systems you can get rid of the warning with manually created .env file:"
echo " See: https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html#setting-the-right-airflow-user"
echo
fi
one_meg=1048576
mem_available=$$(($$(getconf _PHYS_PAGES) * $$(getconf PAGE_SIZE) / one_meg))
cpus_available=$$(grep -cE 'cpu[0-9]+' /proc/stat)
disk_available=$$(df / | tail -1 | awk '{print $$4}')
warning_resources="false"
if (( mem_available < 4000 )) ; then
echo
echo -e "\033[1;33mWARNING!!!: Not enough memory available for Docker.\e[0m"
echo "At least 4GB of memory required. You have $$(numfmt --to iec $$((mem_available * one_meg)))"
echo
warning_resources="true"
fi
if (( cpus_available < 2 )); then
echo
echo -e "\033[1;33mWARNING!!!: Not enough CPUS available for Docker.\e[0m"
echo "At least 2 CPUs recommended. You have $${cpus_available}"
echo
warning_resources="true"
fi
if (( disk_available < one_meg * 10 )); then
echo
echo -e "\033[1;33mWARNING!!!: Not enough Disk space available for Docker.\e[0m"
echo "At least 10 GBs recommended. You have $$(numfmt --to iec $$((disk_available * 1024 )))"
echo
warning_resources="true"
fi
if [[ $${warning_resources} == "true" ]]; then
echo
echo -e "\033[1;33mWARNING!!!: You have not enough resources to run Airflow (see above)!\e[0m"
echo "Please follow the instructions to increase amount of resources available:"
echo " https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html#before-you-begin"
echo
fi
mkdir -p /sources/logs /sources/dags /sources/plugins
chown -R "${AIRFLOW_UID}:0" /sources/{logs,dags,plugins}
exec /entrypoint airflow version
environment:
<<: *airflow-common-env
_AIRFLOW_DB_UPGRADE: 'true'
_AIRFLOW_WWW_USER_CREATE: 'true'
_AIRFLOW_WWW_USER_USERNAME: ${_AIRFLOW_WWW_USER_USERNAME:-airflow}
_AIRFLOW_WWW_USER_PASSWORD: ${_AIRFLOW_WWW_USER_PASSWORD:-airflow}
_PIP_ADDITIONAL_REQUIREMENTS: ''
user: "0:0"
volumes:
- ${AIRFLOW_PROJ_DIR:-./airflow}:/sources
networks:
- domino-net
airflow-cli:
<<: *airflow-common
container_name: airflow-cli
profiles:
- debug
environment:
<<: *airflow-common-env
CONNECTION_CHECK_MAX_COUNT: "0"
command:
- bash
- -c
- airflow
networks:
- domino-net
# 不用可注释掉
flower:
<<: *airflow-common
container_name: airflow-flower
command: celery flower
#profiles:
# - flower
ports:
- "5555:5555"
healthcheck:
test: [ "CMD", "curl", "--fail", "http://localhost:5555/" ]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
restart: always
depends_on:
<<: *airflow-common-depends-on
airflow-init:
condition: service_completed_successfully
networks:
- domino-net
# Modified Airflow Scheduler with Domino
airflow-scheduler:
<<: *airflow-common
image: ghcr.io/tauffer-consulting/domino-airflow-base:latest
container_name: airflow-scheduler
command: scheduler
healthcheck:
test:
[
"CMD",
"curl",
"--fail",
"http://localhost:8974/health"
]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
restart: always
environment:
<<: *airflow-common-env
DOMINO_DEPLOY_MODE: local-compose
volumes:
- ${AIRFLOW_PROJ_DIR:-./airflow}/dags:/opt/airflow/dags
- ${AIRFLOW_PROJ_DIR:-./airflow}/logs:/opt/airflow/logs
- ${AIRFLOW_PROJ_DIR:-./airflow}/plugins:/opt/airflow/plugins
depends_on:
<<: *airflow-common-depends-on
airflow-init:
condition: service_completed_successfully
networks:
- domino-net
# Modified Airflow Worker with Domino
airflow-worker:
<<: *airflow-common
image: ghcr.io/tauffer-consulting/domino-airflow-base:latest
container_name: airflow-worker
command: celery worker
healthcheck:
test:
- "CMD-SHELL"
- 'celery --app airflow.executors.celery_executor.app inspect ping -d "celery@$${HOSTNAME}"'
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
environment:
<<: *airflow-common-env
DUMB_INIT_SETSID: "0"
DOMINO_DEPLOY_MODE: local-compose
LOCAL_DOMINO_SHARED_DATA_PATH: ${PWD}/domino_data
restart: always
volumes:
- ${AIRFLOW_PROJ_DIR:-./airflow}/dags:/opt/airflow/dags
- ${AIRFLOW_PROJ_DIR:-./airflow}/logs:/opt/airflow/logs
- ${AIRFLOW_PROJ_DIR:-./airflow}/plugins:/opt/airflow/plugins
- ${PWD}/domino_data:/home/shared_storage
depends_on:
<<: *airflow-common-depends-on
airflow-init:
condition: service_completed_successfully
networks:
- domino-net
# Domino REST Api
domino_rest:
image: zhuyifeiruichuang/domino-rest:latest
container_name: domino-rest
command: bash -c "alembic upgrade heads && python -m utils.populate_first_user && uvicorn main:app --reload --workers 1 --host 0.0.0.0 --port 8000"
ports:
- 8000:8000
environment:
- DOMINO_DB_USER=postgres
- DOMINO_DB_PASSWORD=postgres
- DOMINO_DB_HOST=domino_postgres
- DOMINO_DB_PORT=5432
- DOMINO_DB_NAME=postgres
- DOMINO_DEFAULT_PIECES_REPOSITORY_TOKEN=${DOMINO_DEFAULT_PIECES_REPOSITORY_TOKEN}
- DOMINO_DEPLOY_MODE=local-compose
- AIRFLOW_ADMIN_USERNAME=airflow
- AIRFLOW_ADMIN_PASSWORD=airflow
- CREATE_DEFAULT_USER=${DOMINO_CREATE_DEFAULT_USER}
networks:
- domino-net
volumes:
- ${AIRFLOW_PROJ_DIR:-./airflow}/dags:/opt/airflow/dags
depends_on:
domino_postgres:
condition: service_healthy
# Domino Postgres
domino_postgres:
image: postgres:13
container_name: domino-postgres
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- domino_postgres_data:/var/lib/postgresql/data
networks:
- domino-net
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"
]
interval: 10s
timeout: 60s
retries: 5
start_period: 2s
ports:
- "5433:5432"
restart: always
# Domino Frontend
domino_frontend:
image: zhuyifeiruichuang/domino-frontend:compose
container_name: domino-frontend
ports:
- "3000:80"
depends_on:
domino_rest:
condition: service_started
environment:
- DOMINO_DEPLOY_MODE=local-compose
# 此处只能填写最终访问的IP和端口,无法识别容器名字。EIP场景填写EIP,NAT场景填写转发后的IP和端口。
- API_URL=http://IP:8000
networks:
- domino-net
docker-proxy:
image: alpine/socat
container_name: domino-docker-proxy
command: "TCP4-LISTEN:2375,fork,reuseaddr UNIX-CONNECT:/var/run/docker.sock"
ports:
- "2376:2375"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- domino-net
volumes:
airflow_postgres_data:
name: airflow_postgres_data
domino_postgres_data:
name: domino_postgres_data
networks:
domino-net:
name: domino-network
driver: bridge
部署
bash
docker compose up -d
访问
访问dominoIP:3000 账户admin@example.com,密码admin
访问配套的airflowIP:8080 账户密码是airflow