airflow如何使用git sync从git分支的dag文件夹中拾取dag

brccelvz  于 2023-03-06  发布在  Git
关注(0)|答案(2)|浏览(229)

我的公司使用git-sync来同步压缩的dags到airflow。我们使用airflow helm charts来部署airflow。我想知道我是否可以让airflow只拾取特定文件夹中的压缩的dags,比如git分支中的dags-dev,而不是所有的压缩的dags?
下面是一些可能有用的参考资料。
气流舵图值文件. https://github.com/helm/charts/blob/master/stable/airflow/values.yaml
我们的dags代码如下所示:

dags:
      doNotPickle: true
      git:
        url: <git url>
        ref: master
        gitSync:
          enabled: true
          image:
            repository: <some repo>
            tag: 1.0.7
          refreshTime: 60
      initContainer:
        enabled: true
        image:
          repository: <some repo>
          tag: 1.0.7

Airflow git sync的配置如下所示:

AIRFLOW__KUBERNETES__DAGS_VOLUME_SUBPATH: repo # must match AIRFLOW__KUBERNETES__GIT_SUBPATH
AIRFLOW__KUBERNETES__GIT_REPO: <git repo>
AIRFLOW__KUBERNETES__GIT_BRANCH: master
AIRFLOW__KUBERNETES__GIT_DAGS_FOLDER_MOUNT_POINT: /opt/airflow/dags
AIRFLOW__KUBERNETES__GIT_USER: <some user>
AIRFLOW__KUBERNETES__GIT_PASSWORD: <some password>
AIRFLOW__KUBERNETES__GIT_SYNC_CONTAINER_REPOSITORY: gitlab.beno.ai:4567/eng/external-images/k8s.gcr.io/git-sync
AIRFLOW__KUBERNETES__GIT_SYNC_CONTAINER_TAG: v3.1.1
o2rvlv0m

o2rvlv0m1#

您可以使用.airflowignore file定义要忽略的文件夹/文件列表
https://airflow.apache.org/docs/apache-airflow/stable/concepts.html#airflowignore

mbjcgjjk

mbjcgjjk2#

看起来这个实现不支持git子路径,另外如果你看一下子路径方法,有一个git克隆,然后是目录过滤。作为git的一个新特性,部分克隆git-sparse-checkout还在实验中。
因此,一种解决方案是利用dags-path来指向存储库中的子目录。

###################################
# Airflow - DAGs Configs
###################################
dags:
  ## the airflow dags folder
  ##
  path: /opt/airflow/dags/repo/dir

注意:我建议将此版本转换为针对生产工作负载的任何其他维护的气流实施,因为它现在已归档,将不再进行修补。

以下是bitnami/airflow中所需选项的示例

# bitnami airflow helm values.yaml reference
repositories:
  - repository: https://gitlab.com/repo.git
    ## Branch from repository to checkout
    ##
    branch: "master"
    ## An unique identifier for repository, must be unique for each repository
    ##
    name: "dags"
    ## Path to a folder in the repository containing the dags
    ##
    path: ""

相关问题