运行 Airflow 中的 DBT 通过 Docker 运算符

Running DBT within Airflow through the Docker Operator

我的问题基于 , I am currently running airflow and syncing the dags via git. I am considering different option to include DBT within my workflow. One suggestion by louis_guitton is to Dockerize the DBT project, and run it in Airflow via the Docker Operator

我之前没有在 Airflow 或一般 DBT 中使用 Docker 运算符的经验。我想知道是否有人尝试过或可以提供一些关于他们结合该工作流程的经验的见解,我的主要问题是:

  1. DBT作为一个整体项目应该运行作为一个Docker容器,还是被分解? (例如:测试 运行 是与 dbt 任务分开的容器吗?)
  2. 当通过 Docker 运算符 运行 时,来自 DBT 的日志和 UI 是否可以访问 and/or 仍然有用?
  3. 部分流水线如何 运行? (示例:只想 运行 管道的一部分)

根据您的问题判断,尝试独立于气流 dockerise dbt 会使您受益。你的很多问题都会消失。但无论如何,这是我的答案。

  1. Should DBT as a whole project be run as one Docker container, or is it broken down? (for example: are tests ran as a separate container from dbt tasks?)

我建议您为整个项目构建一个 docker 图像。 docker 镜像可以基于 python 镜像,因为 dbt 是一个 python CLI 工具。然后,您可以将 docker 图像的 CMD 参数用于 运行 您在 docker 之外 运行 的任何 dbt 命令。 请记住 docker run 的语法(与 dbt 无关):你可以在调用时指定任何你想要的命令 运行

$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

此外,“docker dbt”在 Google 上的第一个命中是 this dockerfile,可以帮助您入门

  1. Are logs and the UI from DBT accessible and/or still useful when run via the Docker Operator?

同样,这不是 dbt 问题,而是 docker 问题或气流问题。

使用 DockerOperator 时,您能在 airflow UI 中看到日志吗?是的,see this how to blog post with screenshots.

您可以从 docker 容器访问日志吗?是的,Docker 容器将日志发送到 stdoutstderr 输出流(您可以在气流中看到,因为气流会拾取它)。但日志也存储在主机上 /var/lib/docker/containers/ 文件夹中的 JSON 文件中。如果您有任何高级需求,您可以使用工具(或简单的 BashOperator 或 PythonOperator)获取这些日志,并使用它执行您需要的操作。

  1. How would partial pipelines be run? (example: wanting to run only a part of the pipeline)

参见答案 1,您将 运行 您的 docker dbt 图像使用命令

$ docker run my-dbt-image dbt run -m stg_customers