I want to run a Docker Operator in Airflow with an environment variable download_path that gets set in a previous task. How can I achieve that? Via Xcom? Minimal example:
# define python function
def make_folder(folder_path:str, date:str):
download_path= folder_path + date
return(download_path)
os.mkdir(download_path)
# Python operator
task_1 = PythonOperator(
task_id="make_folder",
provide_context=False,
python_callable=make_folder,
op_kwargs={'folder_path': '/my_path_', 'date': 'str(datetime.date(datetime.today()))'},
xcom_push=True,
xcom_all=True
)
# docker operator with download_path as a necessary env variable
task_2 = DockerOperator(
task_id='docker',
image='file_processor:latest',
api_version='auto',
auto_remove=False,
command='',
environment={
'DPATH': **download_path**
},
docker_url="unix://var/run/docker.sock",
network_mode="bridge",
xcom_push=True,
xcom_all=True
)
task_1 >> task_2