Deploy a dbt project to Remote Execution Agents

This is feature is only available if you are on the Enterprise tier or above. See Astro Plans and Pricing.
Airflow 3
This feature is only available for Airflow 3.x Deployments.

Remote Execution Agents run tasks in your own Kubernetes infrastructure. Because Remote Execution mode doesn’t support astro dbt deploy, you must make your dbt project files available to agents through other methods.

This document covers two approaches for deploying dbt code to Remote Execution Agents, ordered by Astronomer’s recommendation.

Prerequisites

Option 1: Include the dbt project as a Git submodule (recommended)

Use Git submodules to include an external dbt project repository inside your Dag repository. This approach keeps your dbt and Airflow code in separate repositories while combining them at deploy time.

This is the recommended approach because it:

  • Preserves separation of ownership between dbt and Airflow teams.
  • Pins the dbt project to a specific commit, giving you control over which version of dbt code runs.
  • Works with GitDagBundle for automatic Dag versioning.

How it works

Your Dag repository includes the dbt project as a Git submodule. When agents fetch the Dag bundle from Git, the submodule contents are fetched alongside your Dags. Cosmos then reads the dbt project from the submodule folder to orchestrate dbt models as Airflow tasks.

Configure the Dag repository

1

Add the dbt project as a submodule

From your Dag repository root, run:

$git submodule add <dbt-repository-url> dbt/<project-name>

For example, to add a dbt project called jaffle-shop:

$git submodule add https://github.com/your-org/jaffle-shop dbt/jaffle-shop

This creates a .gitmodules file and clones the dbt repository into the dbt/jaffle-shop folder.

2

Verify the repository structure

Your Dag repository should look similar to the following:

dag-repo/
├── .gitmodules
├── dags/
│ └── dbt_dag.py
└── dbt/
└── jaffle-shop/ # Git submodule
├── models/
├── seeds/
└── dbt_project.yml
3

Create a Cosmos Dag

Create a Dag that uses Cosmos to orchestrate the dbt project. Set the dbt_project_path to reference the submodule location within the Dag bundle:

dags/dbt_dag.py
1from cosmos import DbtDag, ProjectConfig, ProfileConfig, ExecutionConfig
2from pathlib import Path
3from datetime import datetime
4
5dbt_dag = DbtDag(
6 project_config=ProjectConfig(
7 dbt_project_path=Path("/usr/local/airflow/dags/dbt/jaffle-shop"),
8 ),
9 profile_config=ProfileConfig(
10 profile_name="jaffle_shop",
11 target_name="dev",
12 profiles_yml_filepath=Path("/usr/local/airflow/dags/dbt/jaffle-shop/profiles.yml"),
13 ),
14 execution_config=ExecutionConfig(
15 dbt_executable_path="/home/astro/dbt_venv/bin/dbt",
16 ),
17 schedule="@daily",
18 start_date=datetime(2024, 1, 1),
19 catchup=False,
20 dag_id="dbt_jaffle_shop",
21)

The exact path depends on your GitDagBundle configuration. If your bundle uses a subdir parameter, adjust the path accordingly.

4

Commit and push

$git add .gitmodules dbt/jaffle-shop dags/dbt_dag.py
$git commit -m "Add dbt project as submodule with Cosmos DAG"
$git push

Configure agents to fetch submodules

By default, GitDagBundle does not recursively fetch Git submodules. You must configure the git_conn_id connection to include submodule support and ensure the agent can authenticate to the submodule repository.

If the dbt submodule repository uses the same authentication as the Dag repository, configure the Dag bundle with the same git_conn_id. If the submodule is in a public repository, no additional authentication is required.

For private submodule repositories that require separate credentials, configure an additional Git connection in your secrets backend or values.yaml.

Update the dbt submodule

When the dbt team pushes new changes, update the submodule reference in your Dag repository:

$git submodule update --remote dbt/jaffle-shop
$git add dbt/jaffle-shop
$git commit -m "Update jaffle-shop submodule to latest"
$git push

Agents pick up the change on the next GitDagBundle refresh cycle.

For more information about working with Git submodules in an Astro context, see Use Git submodules with an Astro project.

Option 2: Include dbt code in the agent client image

Build the dbt project directly into your custom agent client image. This approach works well when dbt code changes infrequently and you want a self-contained image.

1

Create a custom Dockerfile

Extend the base agent image to include your dbt project and dependencies:

Dockerfile.client
1FROM images.astronomer.cloud/baseimages/astro-remote-execution-agent:3.1-3-python-3.12-astro-agent-1.2.0
2
3# Install dbt into a virtual environment
4RUN python -m venv /home/astro/dbt_venv && \
5 source /home/astro/dbt_venv/bin/activate && \
6 pip install --no-cache-dir dbt-postgres && \
7 deactivate
8
9# Install Cosmos
10RUN pip install astronomer-cosmos
11
12# Copy dbt project into the image
13COPY dbt/jaffle-shop /usr/local/airflow/dbt/jaffle-shop
2

Build and push the image

$docker build -f Dockerfile.client -t your-registry.example.com/custom-agent:1.0.0 .
$docker push your-registry.example.com/custom-agent:1.0.0
3

Update the Helm values

Reference the custom image in your values.yaml:

1workers:
2 - name: default-worker
3 image: your-registry.example.com/custom-agent:1.0.0
4
5dagProcessor:
6 image: your-registry.example.com/custom-agent:1.0.0
7
8triggerer:
9 image: your-registry.example.com/custom-agent:1.0.0
4

Apply changes

$helm upgrade astro-agent astronomer/astro-remote-execution-agent -f values.yaml

This approach requires rebuilding and redeploying the agent image every time dbt code changes. For teams that update dbt models frequently, consider Option 1 instead.

Compare approaches

CriteriaGit submoduleAgent image
dbt and Airflow code in separate repositoriesYesYes
Independent dbt deploy cyclePartialNo
Works with GitDagBundle versioningYesNo
Requires image rebuild for dbt changesNoYes
Additional infrastructureNoneNone
Best forMost teamsInfrequent dbt changes