Adding and accessing static extra files (DAG bundles)
You can bundle non-Python files or other files such as configuration files, scripts, SQL queries, and other resources directly with your DAGs.
Adding extra files
- To bundle extra files, place the files in the same Git repository that was configured during the Cloudera Workflow Orchestrator deployment for the DAGs.
- If a
subdirwas configured for the DAG bundle, only files inside that subdirectory will be synced.
Accessing files in the DAG bundle
Avoid hardcoding absolute file paths. Identify the DAG bundle path from the task instance
using the task_instance.bundle_instance.path parameter to reference the local
path dynamically.
@task()
def check_data(task_instance: TaskInstance, dag_run: DagRun):
file_name = "[***FILE_NAME***]"
with open(os.path.join(task_instance.bundle_instance.path, file_name)) as f:
print(f.read())
Example,
@task()
def check_data(task_instance: TaskInstance, dag_run: DagRun):
file_name = "test_config.conf"
with open(os.path.join(task_instance.bundle_instance.path, file_name)) as f:
print(f.read())The DAG bundle path behavior depends on the versioning configuration:
- Enabled versioning (default): Bundle versioning is enabled
by default for all DAGs in the bundle. The commit ID is added to the path
.
Example,
/tmp/airflow/dag_bundles/dags-repo/versions/f4eafd9d82a071b00d61b090e35fbe2bd5367a21 - Disabled versioning: When bundle versioning is disabled,
the path is always
/tmp/airflow/dag_bundles/dags-repo/tracking_repo. - Per-DAG opt-out: Individual DAGs opt out of bundle
versioning by setting the disable_bundle_versioning DAG parameter to
True.
