Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Decouple hook executor from the operator, add Cloud Build execution and adjust testing #45

Closed
wants to merge 17 commits into from

Conversation

dinigo
Copy link

@dinigo dinigo commented Oct 18, 2021

Closes #44

This extracts the execution from the DbtHook. Defaults the Operators behaviour. It does not break the API. But in case the user needs another environment you can pass it a different hook with custom configuration.

@dinigo dinigo changed the title Decouple hook executor from the operator, add Cloud Build execution and adjust testing WIP: Decouple hook executor from the operator, add Cloud Build execution and adjust testing Oct 18, 2021
The Airflow bash executor will run the command isolated in the worker.
To be able to locate the profiles and code we have to tell dbt with the
new implemented flag
`dbt run --project-dir /path/to/my/project_dir --profiles-dir
/path/to/profile.yaml`
 `
That comes useful when running the command inside cloud run, since the
entrypoint for the command is already `dbt`, and this `dbt` is already
in the PATH of the image
Local execution might not take place in the same folder. It depends on
the underlying hook implementation. This way we ensure we're pointing to
the folder with an absolute path even if run outside the project folder
@dinigo dinigo changed the title WIP: Decouple hook executor from the operator, add Cloud Build execution and adjust testing Decouple hook executor from the operator, add Cloud Build execution and adjust testing Oct 22, 2021
@dinigo
Copy link
Author

dinigo commented Oct 22, 2021

Hello! The functionality is there. We've tested it with a DAG like this

with DAG('dbt_dag_example', start_date=datetime(2021, 10, 1)) as dag:
    # If no hook is provided, it defaults to the local execution hook
    DbtRunOperator(
        task_id='run_dbt_cli',
        project_dir=abspath('./jaffle-shop'),
        profiles_dir=abspath('.'),
        dbt_bin='/home/airflow/.local/bin/dbt',
        # local environment need to define the env variable for auth
        env={ 'GOOGLE_APPLICATION_CREDENTIALS': '/run/secrets/gcp_credentials.json'},
    )
    DbtRunOperator(
        task_id='run_dbt_cloud_build',
        project_dir='jaffle-shop',
        profiles_dir='jaffle-shop',
        dbt_hook=DbtCloudBuildHook(
            project_id='datatonic-uk-dop-dev',
            gcs_staging_location='gs://some_bucket/jaffle-shop.tar.gz',
        )
    )

Also make the command build function more idiomatic by using `append`
to append single commands (flags) and `extend` when we want to append
several.
@dinigo dinigo mentioned this pull request Oct 22, 2021
@dinigo
Copy link
Author

dinigo commented Oct 22, 2021

@andrewrjones @etoulas : Could you assist me in getting this PR merged? if this repo is not going to be maintained I'll be happy to do so

@dinigo
Copy link
Author

dinigo commented Oct 22, 2021

This was closed when I renamed the main branch In my repo :/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Abstract execution environment
1 participant