Skip to content

Commit 823ceed

Browse files
Merge pull request #1867 from abhipalsingh/abhsingh
Fixed setup of internal dbt project used by Elementary
2 parents da033fb + d04c8e5 commit 823ceed

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

elementary/monitor/cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
from elementary.monitor.data_monitoring.schema import FiltersSchema
1313
from elementary.monitor.data_monitoring.selector_filter import SelectorFilter
14+
from elementary.monitor.dbt_init import DBTInit
1415
from elementary.monitor.debug import Debug
1516
from elementary.tracking.anonymous_tracking import AnonymousCommandLineTracking
1617
from elementary.utils import bucket_path
@@ -24,6 +25,7 @@ class Command:
2425
REPORT = "monitor-report"
2526
SEND_REPORT = "monitor-send-report"
2627
DEBUG = "debug"
28+
DBT_INIT = "dbt-init"
2729

2830

2931
# Displayed in reverse order in --help.
@@ -774,5 +776,25 @@ def debug(ctx, profiles_dir):
774776
anonymous_tracking.track_cli_end(Command.DEBUG, None, ctx.command.name)
775777

776778

779+
@monitor.command()
780+
@click.pass_context
781+
def dbt_init(ctx):
782+
"""
783+
Initializes the Elementary internal dbt project by installing its dbt deps.
784+
Run this command after installing EDR as part of builds or CI/CD pipelines when the target
785+
environment does not have write permissions on disk or does not have internet connection.
786+
This command is not needed in most cases as the dbt deps are installed automatically when running `edr monitor`.
787+
"""
788+
config = Config()
789+
anonymous_tracking = AnonymousCommandLineTracking(config)
790+
anonymous_tracking.track_cli_start(Command.DEBUG, None, ctx.command.name)
791+
dbtinit = DBTInit()
792+
success = dbtinit.setup_internal_dbt_packages()
793+
if not success:
794+
sys.exit(1)
795+
click.echo("Elementary internal dbt project has been initialized successfully. ")
796+
anonymous_tracking.track_cli_end(Command.DEBUG, None, ctx.command.name)
797+
798+
777799
if __name__ == "__main__":
778800
monitor()

elementary/monitor/dbt_init.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from elementary.clients.dbt.factory import create_dbt_runner
2+
from elementary.monitor import dbt_project_utils
3+
4+
5+
class DBTInit:
6+
"""
7+
Class to handle the initialization of dbt for the Elementary CLI.
8+
This can contain all dbt static setup to avoid pulling in runtime dependencies or any other information from internet
9+
that is internally used by edr.
10+
"""
11+
12+
def setup_internal_dbt_packages(self):
13+
"""
14+
Run dbt deps to install internal dbt packages if needed.
15+
It intentionally does not use self.config.run_dbt_deps_if_needed parameter in create_dbt_runner to ensure
16+
that dbt deps is always run when setting up the internal dbt packages.
17+
"""
18+
dbt_runner = create_dbt_runner(dbt_project_utils.CLI_DBT_PROJECT_PATH)
19+
return dbt_runner.deps()

0 commit comments

Comments
 (0)