Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions elementary/monitor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from elementary.monitor.data_monitoring.schema import FiltersSchema
from elementary.monitor.data_monitoring.selector_filter import SelectorFilter
from elementary.monitor.dbt_init import DBTInit
from elementary.monitor.debug import Debug
from elementary.tracking.anonymous_tracking import AnonymousCommandLineTracking
from elementary.utils import bucket_path
Expand All @@ -24,6 +25,7 @@ class Command:
REPORT = "monitor-report"
SEND_REPORT = "monitor-send-report"
DEBUG = "debug"
DBT_INIT = "dbt-init"


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


@monitor.command()
@click.pass_context
def dbt_init(ctx):
"""
Initializes the Elementary internal dbt project by installing its dbt deps.
Run this command after installing EDR as part of builds or CI/CD pipelines when the target
environment does not have write permissions on disk or does not have internet connection.
This command is not needed in most cases as the dbt deps are installed automatically when running `edr monitor`.
"""
config = Config()
anonymous_tracking = AnonymousCommandLineTracking(config)
anonymous_tracking.track_cli_start(Command.DEBUG, None, ctx.command.name)
dbtinit = DBTInit()
success = dbtinit.setup_internal_dbt_packages()
if not success:
sys.exit(1)
click.echo("Elementary internal dbt project has been initialized successfully. ")
anonymous_tracking.track_cli_end(Command.DEBUG, None, ctx.command.name)


if __name__ == "__main__":
monitor()
19 changes: 19 additions & 0 deletions elementary/monitor/dbt_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from elementary.clients.dbt.factory import create_dbt_runner
from elementary.monitor import dbt_project_utils


class DBTInit:
"""
Class to handle the initialization of dbt for the Elementary CLI.
This can contain all dbt static setup to avoid pulling in runtime dependencies or any other information from internet
that is internally used by edr.
"""

def setup_internal_dbt_packages(self):
"""
Run dbt deps to install internal dbt packages if needed.
It intentionally does not use self.config.run_dbt_deps_if_needed parameter in create_dbt_runner to ensure
that dbt deps is always run when setting up the internal dbt packages.
"""
dbt_runner = create_dbt_runner(dbt_project_utils.CLI_DBT_PROJECT_PATH)
return dbt_runner.deps()
Loading