Cloud Composer 缺少变量文件

Cloud Composer missing variables file

我一直在尝试使用 airflow CLI 将环境变量的 JSON 文件导入新创建的 Cloud Composer 实例,但是当 运行 出现以下错误时: Missing variables file.

gcloud composer environments run ${COMPOSER_NAME} \
    --location=${COMPOSER_LOCATION} \
    variables -- \
    -i ${VARIABLES_JSON}

the source 来看,这似乎是在预期位置不存在环境变量文件时发生的。这是因为 Cloud Composer 在不同的位置设置了它的变量,所以这个 CLI 不起作用吗?我注意到在实例的 GCS 存储桶上创建了一个 env_var.json 文件,我意识到我可以覆盖该文件,但这似乎不是最佳做法。

这感觉像是一个 hack,但我将 variables.json 复制到我的 Composer 的 GCS 存储桶数据文件夹中,然后它起作用了。

这是由于 os.path.exists() 检查 Airflow 运行 所在的容器。我选择这种方法而不是覆盖 env_var.json 因为我用这种方法得到了 Airflow 的 UI 中的变量。

任何感兴趣的人的脚本:

COMPOSER_DATA_FOLDER=/home/airflow/gcs/data

COMPOSER_GCS_BUCKET=$(gcloud composer environments describe ${COMPOSER_NAME} --location ${COMPOSER_LOCATION} | grep 'dagGcsPrefix' | grep -Eo "\S+/")

gsutil cp ${ENV_VARIABLES_JSON_FILE} ${COMPOSER_GCS_BUCKET}data

gcloud composer environments run ${COMPOSER_NAME} \
    --location ${COMPOSER_LOCATION} variables -- \
    -i ${COMPOSER_DATA_FOLDER}/variables.json