GCP,如何从私有存储库安装Python依赖项

GCP,如何从私有存储库安装Python依赖项,python,google-cloud-platform,airflow,Python,Google Cloud Platform,Airflow,对于我的数据提取项目,我选择了apacahe Airflow,它带有GCP composer和bucket storage 我在Github中的repo包中有几个模块,我的DAG文件需要访问这些模块 目前,我正在使用BashOperator检查它是否有效: #dag.py dag = DAG( dag_id='my_example_DAG', start_date=datetime(2019, 10, 17, 8, 25), schedule_interval=time

对于我的数据提取项目,我选择了apacahe Airflow,它带有GCP composer和bucket storage

我在Github中的repo包中有几个模块,我的DAG文件需要访问这些模块 目前,我正在使用BashOperator检查它是否有效:

#dag.py

dag = DAG(
    dag_id='my_example_DAG',
    start_date=datetime(2019, 10, 17, 8, 25),
    schedule_interval=timedelta(minutes=15),
    default_args=default_args,
)

t1 = BashOperator(
    task_id='example_task',
    bash_command='python /home/airflow/gcs/data/my_example_maindir/main.py ',
    dag=dag)
t1
它工作了,用test_路径启动main.py。但是您希望使用函数run_main为任务解析正确的路径和正确的YML文件

我已尝试将sys.path.dir插入模块所在的存储桶中,但出现导入错误 目录:

我的DAG文件的目录(从我的git回购中克隆)=bucket/europe-west1-eep-envxxxxxxx-bucket/dags

我的脚本/包的目录=bucket/europe-west1-eep-envxxxxxxx-bucket/data

#dag.py

import sys
sys.path.insert(0, "/home/airflow/gcs/data/Example/")
from Example import main

dag = DAG(
    dag_id='task_1_dag',
    start_date=datetime(2019, 10, 13),
    schedule_interval=timedelta(minutes=10),
    default_args=default_args,
)

t1 = PythonOperator(
   task_id='task_1',
   provide_context=True,
   python_callable=main.run_main,
   op_args={'path_name': "project_output_0184_Storgaten_33"},
   dag=dag
    )

t1



这将导致“找不到模块”错误,并且无法工作

我在GCP中进行了som阅读,发现:

从专用存储库安装Python依赖项:

这意味着我需要将它放在目录路径/config/pip中/ 示例:gs://us-central1-b1-6efannn-bucket/config/pip/pip.conf

但在我的GCP存储桶中,我没有名为config的目录。
我在创建bucket和env时曾尝试跟踪我的步骤,但我能找出我做错了什么

GCS对文件夹或目录没有真正的概念,您实际拥有的是一系列blob,它们的名称可能包含斜杠,并给出了目录的外观

要求您将其放在目录中的说明有点不清楚,但实际上您要做的是创建一个文件并给它前缀
config/pip/pip.conf

使用
gsutil
可以执行以下操作:

gsutil cp my-local-pip.conf gs://[DESTINATION_BUCKET_NAME]/config/pip/pip.conf

GCS没有文件夹或目录的真正概念,您实际上拥有的是一系列blob,它们的名称可能包含斜杠,并提供目录的外观

要求您将其放在目录中的说明有点不清楚,但实际上您要做的是创建一个文件并给它前缀
config/pip/pip.conf

使用
gsutil
可以执行以下操作:

gsutil cp my-local-pip.conf gs://[DESTINATION_BUCKET_NAME]/config/pip/pip.conf

您是否尝试手动创建目录并将文件放入其中?您是否尝试手动创建目录并将文件放入其中?谢谢,我正在考虑添加目录,但这并不容易。谢谢,我正在考虑添加目录,但这并不容易。