Webhook icon
Schedule icon
Get icon
OutputValues icon
Log icon
WorkingDirectory icon
Clone icon
DbtCLI icon
Docker icon
Set icon
SlackIncomingWebhook icon

dbt slim CI that builds only modified nodes and promotes the production manifest on green

dbt Core slim CI on Kestra with DbtCLI loadManifest, an explicit KV promotion gated on a green production build, state:modified+ --defer selection, a full-build fallback and node-level reporting.

Categories
CoreData

Slim CI is the dbt pattern where a pull request builds and tests only the nodes it changed, plus everything downstream, by comparing its project against the manifest of the last production run. It needs two things an orchestrator has to own: a trustworthy production manifest, and the discipline that only a green production build may replace it. This flow does both on Kestra with the dbt plugin and the KV Store. One flow, two modes. main clones the production branch, runs dbt build in full and, when the build succeeded, stores target/manifest.json under a KV key together with a pointer record (git sha, dbt version, time, execution id). pr clones the pull request branch, has the plugin's loadManifest write the promoted manifest to target/, and runs dbt build --select state:modified+ --defer --state target --favor-state into a separate target directory. Without a promoted manifest the pr run falls back to a full build and says so. Every outcome, green or red, names the dbt nodes involved. The sample project is kestra-io/dbt-example on DuckDB; the complex-dag branch adds eleven models on top of main.

How it works

  1. production_pointer reads <manifest_key>_meta with errorOnMissing: false. Its absence means no manifest has been promoted yet.
  2. plan settles everything once: branch, optional commit, mode, whether this run is slim, the dbt selector (empty for every full build), the dbt target (prod for main, ci for pr unless dbt_target is set) and the execution URL. A GitHub push payload (trigger.body.ref, trigger.body.after) overrides the inputs: a push to production_branch is a main run, any other branch a pr run. announce logs the path taken before dbt prints a word, at WARN level for the fallback.
  3. dbt is a WorkingDirectory with two git.Clone tasks (branch or pinned commit, one runs) and two DbtCLI tasks (main or pr, one runs), selected with runIf. Both DbtCLI tasks write a DuckDB profiles.yml with a prod and a ci output as two schemas of one database file.
  4. build_production runs dbt deps and dbt build. It does not use the plugin's storeManifest: on 2.0.5 that property stores the manifest after the commands finish whether or not dbt exited 0, so a failing test would still replace the promoted manifest. The plugin does expose target/manifest.json as outputFiles['manifest.json'], and that is what the promotion reads.
  5. build_pull_request runs with loadManifest. dbt rewrites target/manifest.json while parsing, before it reads --state, so comparing against --state target from the same target directory always finds zero changes (dbt warns "state and target directories are the same"). The build therefore writes to --target-path target_ci and the selector reads the untouched target/. allowWarning keeps a pull request that changes no dbt node in SUCCESS; dbt logs that case as a WARNING.
  6. artifacts picks run_results.json, manifest.json and the git ref files out of whichever DbtCLI task ran, matching the end of each key because the key carries the project directory and the worker's path separator. results reads run_results.json with read() and shapes it with jq: counts per status, every node as type:name, the failing ones, dbt's own version, and the commit sha from .git/HEAD (following the ref to the loose ref file or packed-refs, since Clone exposes no sha output).
  7. promote_manifest (kv.Set, JSON) and promote (the pointer record) run only in main mode and only after build_production succeeded, which is what "green" means here. confirm_promotion reads the pointer back, and the summary says promoted: true only when the record names this execution.
  8. version_drift warns when the pointer's dbt version differs from the one this pr run used, because manifests from different dbt versions differ in places unrelated to the pull request and that shows up as spurious modified nodes. report writes one message for the log and Slack: production build promoted, slim CI with the node list, zero modified nodes, or full-build fallback.

How to run

Inputs: mode (pr, main), git_url, git_ref (pr branch), git_commit (optional pinned sha), production_branch, project_dir, dbt_profile, dbt_target, duckdb_path, manifest_key, kestra_api_url. Secrets: SLACK_WEBHOOK_URL and GITHUB_WEBHOOK_KEY.

  1. Install the dbt, git and Slack plugins and create the two secrets: SLACK_WEBHOOK_URL (incoming webhook) and GITHUB_WEBHOOK_KEY (any long random string; the same value goes into the GitHub webhook URL). Both DbtCLI tasks run in ghcr.io/kestra-io/dbt-duckdb:latest through the Docker runner; swap the image for your adapter's. On a worker without Docker but with dbt and dbt-duckdb on its PATH, replace both taskRunner blocks with type: io.kestra.plugin.core.runner.Process and drop containerImage.
  2. Run with the defaults (mode: pr). With no promoted manifest the run logs the fallback at WARN and builds the six sample nodes in full.
  3. Run mode: main. The manifest and the pointer are now in KV under dbt_prod_manifest and dbt_prod_manifest_meta.
  4. Run mode: pr with git_ref: complex-dag. Only the eighteen nodes the branch adds are built (eleven models and their seven tests); the six unchanged nodes are not. Run mode: pr with git_ref: main and the report says zero modified nodes.
  5. Point a GitHub push webhook at github_push using the GITHUB_WEBHOOK_KEY value, and enable nightly_promotion if you want a manifest from the current dbt version even on days with no merge.

Error handling

  • checks block the execution before it starts when git_commit is not a 7 to 40 character hex sha or project_dir leaves the repository.
  • A missing branch fails clone_branch in about a second with the git message; errors names the task. No retry on the Clone tasks: on 2.0.5 a retry on a task inside WorkingDirectory re-created the WorkingDirectory task run and the execution never finished. The two Slack tasks keep a constant retry and allowFailure: true.
  • A failing dbt node fails the DbtCLI task; its outputFiles still carry run_results.json, so errors lists the failing nodes as type:name (status), writes <manifest_key>_last_failure to KV for 30 days, logs at ERROR and posts to Slack when a webhook is set. A main run adds that nothing was promoted, and the KV manifest and pointer keep their previous revision.
  • finally logs one summary line whatever happened, with n/a for the steps that did not run, and the summary flow output carries the same fields as JSON for a parent flow.

How to adapt

  • Another warehouse: replace the profiles block of both DbtCLI tasks with your adapter and point duckdb_path at nothing. For --defer to resolve unmodified upstream models to production tables the pr run must reach the same database the main run wrote to.
  • Several dbt projects: one manifest_key per project; the pointer and the last failure follow it.
  • Stricter promotion: add a dbt source freshness or a dbt test --select tag:critical command before dbt build in build_production; the promotion still waits for the task to succeed.
  • Pull request status back to GitHub: read outputs.summary in a parent flow and call the commit status API with the git_sha it carries.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.