![](/img/trans.png)
[英]How to solve dependency conflicts in requirements.txt file in Django deployment
[英]How to run independent requirements.txt file in apache airflow DAG
我有多个 aiflow dags 在 composer 环境中运行。 现在我没有机会安装任何额外的 python 包,除了 airflow 给出的包。但现在我想为两个不同的 DAG 安装 beautifulsoup 和其他打包程序。 我怎样才能做到这一点?
第一种方法:
def a():
print("Response")
return True
response = PythonVirtualenvOperator(
task_id = "response",
requirements=["lxml==4.9.1","beautifulsoup4==4.11.1"],
python_callable = a,
dag=dag,
provide_context=True
)
它安装包,但不执行代码。 简直是逃课。 我想知道后端发生了什么以及我将如何执行代码。
第二种方法:
virtual_classic = BashOperator(
task_id="virtual_classic",
bash_command="bash /home/airflow/gcs/dags/test_req/requirements.txt",
dag=dag
)
在这里,我试图从需求文件中安装所有包,然后尝试运行所需的必要代码。 但是这里我不确定如何通过 airflow 运营商安装这个文件? 在此感谢您的宝贵建议。
第三种方法:
gcloud composer environments update ENVIRONMENT_NAME \
--location LOCATION \
--update-pypi-packages-from-file gs://composer_bucket/requirements.txt
错误:
gcloud 崩溃(类型错误):无法在类似字节的 object 上使用字符串模式
请让我知道为三个中的独立 dag 安装 requirement.txt 文件的最佳方法。
默认情况下,对于Airflow
和Cloud Composer
, pypi
包安装在全局所有 DAG 的机器中。
如果你想为每个 DAG 或任务提供版本和包,你可以使用Kube.netesPodOperator
此运算符允许使用自定义Docker
图像。 在此图像中,您可以安装和隔离此任务和Python
程序所需的所有包。
operator 中使用的Docker
镜像需要在同一个项目的Container registry
中发布(我不确定是否可以使用Artifact Registry
)。
文档中此运算符的示例:
kubernetes_min_pod = KubernetesPodOperator(
# The ID specified for the task.
task_id="pod-ex-minimum",
# Name of task you want to run, used to generate Pod ID.
name="pod-ex-minimum",
# Entrypoint of the container, if not specified the Docker container's
# entrypoint is used. The cmds parameter is templated.
cmds=["echo"],
# The namespace to run within Kubernetes, default namespace is
# `default`. In Composer 1 there is the potential for
# the resource starvation of Airflow workers and scheduler
# within the Cloud Composer environment,
# the recommended solution is to increase the amount of nodes in order
# to satisfy the computing requirements. Alternatively, launching pods
# into a custom namespace will stop fighting over resources,
# and using Composer 2 will mean the environment will autoscale.
namespace="default",
# Docker image specified. Defaults to hub.docker.com, but any fully
# qualified URLs will point to a custom repository. Supports private
# gcr.io images if the Composer Environment is under the same
# project-id as the gcr.io images and the service account that Composer
# uses has permission to access the Google Container Registry
# (the default service account has permission)
image="gcr.io/gcp-runtimes/ubuntu_18_0_4",
)
你有不同的选择来在隔离环境中运行你的 dags:
/path/to/<venv1 or venv2>/bin/python some_script.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.