【问题标题】:Airflow Cloud Build Operator not executing python functionAirflow Cloud Build Operator 未执行 python 函数
【发布时间】:2021-01-28 10:45:52
【问题描述】:

我无法执行第二个 arg 语句:

"python", "-c", "from main import foo;print(foo('hello'))"

我正在使用 Airflow 运算符 CloudBuildCreateBuildOperator 触发 Cloud Build。 触发 DAG 和 Cloud Build 均返回成功。

根据 Cloud Build 返回的日志消息,安装 requirements.txt 文件的第一个参数似乎可以工作:

Requirement already satisfied: setuptools>=40.3.0 in /usr/local/lib/python3.7/site-packages (from google-auth>=1.2->gcsfs>=0.6.2

我的功能是使用 gcsfs 包。我在问题中使用的功能只是为了演示。

在使用 Airflow 之前,我在 yaml 文件中进行了这项工作。 尝试了多种不同的方式来陈述论点,例如:

"args":["-c","pip install -V -r requirements.txt; python -c from main import foo;print(foo('hello'))"]

但现在在绕圈子。

我将非常感谢任何帮助使该 args 语句正常工作。

这是来自 DAG 的 CloudBuildCreateBuildOperator:

create_build_from_storage_body = {
  "source": {
    "repoSource": {
      "projectId": "dev-6767",
      "repoName": "bq-pipeline",
      "branchName": "master",
    }
  },
  "steps": [{
    "name": "docker.io/library/python:3.7",
    "entrypoint": "/bin/bash",
    "args": ["-c", "pip install -V -r requirements.txt",
      "python", "-c", "from main import foo;print(foo('hello'))"
    ],
  }],
}

【问题讨论】:

  • 嗨@BPsinoza 你能按照这个例子here中使用的模式试一试吗?如图所示,您似乎需要将 args 拆分为多个 args 以便更好地执行。
  • 嗨@gso_gabriel 感谢您的链接。该示例使用了 && ,它允许我链接命令。这现在有效:“args”:[“-c”,“pip install -r requirements.txt && python main.py”]
  • 嗨@BSpnioza 很高兴听到它对你有帮助!你介意我发表我的评论 - 提供更多信息 - 作为答案,以便你接受吗?
  • 嗨@gso_gabriel,请接受,很高兴接受。
  • 我已经发布了。谢谢@BSpinoza!

标签: python google-cloud-platform yaml airflow google-cloud-build


【解决方案1】:

正如本示例中所解释的here,使用 Python 链接命令和发送多个args 的最佳方法是在它们之间添加一个&&

以下是如何使用这种格式发送参数的示例,用于命令链。

#testing1
steps:
- name: 'docker.io/library/python:3.7'
  id: Test
  entrypoint: /bin/sh
  args:
  - -c
  - 'pip install pytest && pip install -r requirements.txt && pytest test/*_test.py'
- name: gcr.io/google.com/cloudsdktool/cloud-sdk

这样,可以在 Cloud Build 触发器中使用多个参数。

【讨论】:

    猜你喜欢
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 2021-09-08
    • 2017-07-17
    • 1970-01-01
    • 2023-04-06
    • 2021-04-04
    相关资源
    最近更新 更多