-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathdbt_docs.py
71 lines (59 loc) · 1.97 KB
/
dbt_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
## Docs DAG
This DAG illustrates how to run `dbt docs generate` and handle the output. In this example, we're using the
`DbtDocsLocalOperator` to generate the docs, coupled with a callback. The callback will upload the docs to
S3 (if you have the S3Hook installed) or to a local directory.
"""
import os
from pathlib import Path
from airflow import DAG
from pendulum import datetime
from cosmos import ProfileConfig
from cosmos.operators import (
DbtDocsAzureStorageOperator,
DbtDocsGCSOperator,
DbtDocsS3Operator,
)
from cosmos.profiles import PostgresUserPasswordProfileMapping
DEFAULT_DBT_ROOT_PATH = Path(__file__).parent / "dbt"
DBT_ROOT_PATH = Path(os.getenv("DBT_ROOT_PATH", DEFAULT_DBT_ROOT_PATH))
profile_config = ProfileConfig(
profile_name="default",
target_name="dev",
profile_mapping=PostgresUserPasswordProfileMapping(
conn_id="example_conn",
profile_args={"schema": "public"},
),
)
with DAG(
dag_id="docs_dag",
start_date=datetime(2023, 1, 1),
schedule_interval="@daily",
doc_md=__doc__,
catchup=False,
default_args={"retries": 2},
) as dag:
generate_dbt_docs_aws = DbtDocsS3Operator(
task_id="generate_dbt_docs_aws",
project_dir=DBT_ROOT_PATH / "jaffle_shop",
profile_config=profile_config,
connection_id="aws_s3_conn",
bucket_name="cosmos-ci-docs",
install_deps=True,
)
generate_dbt_docs_azure = DbtDocsAzureStorageOperator(
task_id="generate_dbt_docs_azure",
project_dir=DBT_ROOT_PATH / "jaffle_shop",
profile_config=profile_config,
connection_id="azure_abfs_conn",
bucket_name="cosmos-ci-docs",
install_deps=True,
)
generate_dbt_docs_gcs = DbtDocsGCSOperator(
task_id="generate_dbt_docs_gcs",
project_dir=DBT_ROOT_PATH / "jaffle_shop",
profile_config=profile_config,
connection_id="gcp_gs_conn",
bucket_name="cosmos-ci-docs",
install_deps=True,
)