How to Host a dbt Package in DataOps.live
The ability to manage common macros, models, and other modeling and transformation resources using dbt Packages is essential to the principles of DataOps, reducing code duplication and centralizing management. DataOps.live provides the capability to host dbt packages inside the platform with simple authentication using tokens.
...on creating dbt packages, read this dbt blog: So You Want to Build a dbt Package.
Procedure
-
Create a project in DataOps.live that contains the dbt package. There's no need for the usual DataOps template: start from an empty project and add the dbt package content.
-
Create a Git tag to set the initial version once you have content in your package. Use whichever versioning strategy works best for your organization.
-
Create a deploy token for this project, Settings > Repository > Deploy tokens, with
read_repository
access. Save the token to your secret manager for using it in a DataOps pipeline. -
In each DataOps project that will use this package, add an entry to
packages.yml
:dataops/modelling/packages.ymlpackages:
# existing package dependencies
...
- git: "https://USERNAME:{{ env_var('PACKAGE_TOKEN') }}@app.dataops.live/path/to/package-project.git"
revision: v0.1.0 -
Make sure you substitute
USERNAME
with the username you specified when creating the token and map thePACKAGE_TOKEN
variable to a path equivalent to the Parameter Store location. The revision, in this case,v0.1.0
, will be the value of the git tag you created above.Any pipeline job that uses this package, or any other you may have added to
packages.yml
, will need to have the variableTRANSFORM_FORCE_DEPS
set to1
so that the transform orchestrator will rundbt deps
before its primary action. The job, or the project's mainvariables.yml
file, will need to define thePACKAGE_TOKEN
variable that can be renamed if needed using theDATAOPS_VAULT()
syntax to retrieve the token from your secrets manager via the DataOps vault.
Example job
This example job executes a local MATE macro my_local_macro
, which utilizes another macro from a dbt package hosted in DataOps and declared in the packages.yml
injecting the necessary token PACKAGE_TOKEN
from the DataOps vault:
Run My Local Macro:
extends:
- .modelling_and_transformation_base
- .agent_tag
stage: Demo
variables:
TRANSFORM_ACTION: OPERATION
TRANSFORM_OPERATION_NAME: my_local_macro
TRANSFORM_FORCE_DEPS: 1
PACKAGE_TOKEN: DATAOPS_VAULT(PATH.TO.DATAOPS.DEPLOY_TOKEN)
script:
- /dataops
icon: ${DATAOPS_ICON}