pgoslatara / dbt-cloud-jobs

https://pypi.org/project/dbt-cloud-jobs/
MIT License
2 stars 0 forks source link

dbt-cloud-jobs

pypi version shield CI Publish Python versions License: MIT

Version control your dbt Cloud jobs with YML.

Installation

pip install dbt-cloud-jobs

Quickstart

  1. Create an API token in dbt Cloud:

  2. Set an environment variable with the value of the token:

    export DBT_API_TOKEN="<VALUE_FROM_PREVIOUS_STEP>"
  3. Set an environment variable for the region where your dbt Cloud account is hosted. The value must be one of "AU", "Europe" or "US" (see docs here):

    export DBT_CLOUD_REGION="<REGION>"
  4. Import your existing dbt Cloud jobs:

    dbt_cloud_jobs --import --account-id 123456 --file dbt_cloud_jobs.yml
  5. Edit the definition of your jobs in dbt_cloud_jobs.yml.

  6. Sync the updated definitions to dbt Cloud:

    dbt_cloud_jobs --sync --file dbt_cloud_jobs.yml

Recommended usage in CI/CD

CI

In CI dbt-cloud-jobs should be used to verify that the provided YML file is valid. For example:

    - name: Install dbt_cloud_jobs
      run: pip install dbt-cloud-jobs

    - name: Validate `dbt_cloud_jobs.yml`
      run: dbt_cloud_jobs --validate --file dbt_cloud_jobs.yml

CD

In CD dbt-cloud-jobs should be used to sync the provided YML file to dbt Cloud. For example:

    - name: Install dbt_cloud_jobs
      run: pip install dbt-cloud-jobs

    - name: Sync `dbt_cloud_jobs.yml`
      run: dbt_cloud_jobs --sync --file dbt_cloud_jobs.yml

Example

For an example of how this package can be used, take a look at dbt-cloud-jobs-example-repo, specifically:

Limitations/Warnings

Development

To setup your development environment, fork this repository and run:

poetry shell
poetry install

Set the following environment variables:

export DBT_ACCOUNT_ID=<DBT_ACCOUNT_ID>
export DBT_CLOUD_REGION="<DBT_CLOUD_REGION>"
export DBT_ENVIRONMENT_ID=<DBT_ENVIRONMENT_ID>
export DBT_PROJECT_ID=<DBT_PROJECT_ID>
export DBT_API_TOKEN="<DBT_API_TOKEN>"

It is highly recommended that a dedicated dbt Cloud environment be used for development.

All tests can be run via:

make test

Release

Trigger the Publish to PyPi workflow, inputting the version to publish to PyPi. This workflow will:

Publications