Skip to content

Commit c20cd6c

Browse files
Merge pull request #28 from C00ldudeNoonan/deployment-fixes
update deployment logic
2 parents 5dbbca6 + 151b31a commit c20cd6c

5 files changed

Lines changed: 100 additions & 10 deletions

File tree

.github/workflows/branch_deployments.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ concurrency:
77
# Cancel in-progress deploys to same branch
88
group: ${{ github.ref }}/branch_deployments
99
cancel-in-progress: true
10+
11+
permissions:
12+
contents: read
13+
issues: write
14+
pull-requests: write
15+
1016
env:
1117
DAGSTER_CLOUD_URL: "http://noonan-econ.dagster.plus"
1218
DAGSTER_CLOUD_API_TOKEN: ${{ secrets.DAGSTER_CLOUD_API_TOKEN }}
@@ -40,6 +46,27 @@ jobs:
4046
ref: ${{ github.head_ref }}
4147
path: project-repo
4248

49+
- name: Set up Python for dbt
50+
if: steps.prerun.outputs.result == 'pex-deploy'
51+
uses: actions/setup-python@v5
52+
with:
53+
python-version: ${{ env.PYTHON_VERSION }}
54+
55+
- name: Copy dbt_project into macro_agents for deployment
56+
if: steps.prerun.outputs.result == 'pex-deploy'
57+
run: |
58+
cp -r project-repo/dbt_project project-repo/macro_agents/dbt_project
59+
# Verify the copy worked
60+
ls -la project-repo/macro_agents/dbt_project || exit 1
61+
62+
- name: Generate dbt manifest.json
63+
if: steps.prerun.outputs.result == 'pex-deploy'
64+
run: |
65+
pip install dbt-core dbt-duckdb
66+
cd project-repo/macro_agents/dbt_project
67+
dbt deps || true
68+
dbt parse --target prod || dbt parse
69+
4370
- name: Python Executable Deploy
4471
if: steps.prerun.outputs.result == 'pex-deploy'
4572
uses: dagster-io/dagster-cloud-action/actions/build_deploy_python_executable@v1.12.0

.github/workflows/deploy.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ concurrency:
99
# Cancel in-progress deploys to same branch
1010
group: ${{ github.ref }}/deploy
1111
cancel-in-progress: true
12+
13+
permissions:
14+
contents: read
15+
issues: write
16+
pull-requests: write
17+
1218
env:
1319
DAGSTER_CLOUD_URL: "http://noonan-econ.dagster.plus"
1420
DAGSTER_CLOUD_API_TOKEN: ${{ secrets.DAGSTER_CLOUD_API_TOKEN }}
@@ -53,6 +59,8 @@ jobs:
5359
if: steps.prerun.outputs.result == 'pex-deploy'
5460
run: |
5561
cp -r project-repo/dbt_project project-repo/macro_agents/dbt_project
62+
# Verify the copy worked
63+
ls -la project-repo/macro_agents/dbt_project || exit 1
5664
5765
- name: Generate dbt manifest.json
5866
if: steps.prerun.outputs.result == 'pex-deploy'

dagster_cloud.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ locations:
44
module_name: macro_agents.definitions
55
working_directory: ./macro_agents
66
build:
7-
directory: ./macro_agents
8-
env_vars:
9-
GIT_PYTHON_REFRESH: quiet
7+
directory: ./macro_agents

macro_agents/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ dev = [
4343
requires = ["hatchling"]
4444
build-backend = "hatchling.build"
4545

46+
[tool.hatch.build.targets.wheel]
47+
packages = ["src/macro_agents"]
48+
include = [
49+
"dbt_project/**/*",
50+
]
51+
4652
[tool.dg]
4753
directory_type = "project"
4854

macro_agents/src/macro_agents/defs/transformation/dbt.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,77 @@ def get_automation_condition(
4747
)
4848
else:
4949
current_file = Path(__file__).resolve()
50+
# Try to find macro_agents package root (where dbt_project is copied during deployment)
51+
# Go up from: macro_agents/defs/transformation/dbt.py -> macro_agents/defs/transformation -> macro_agents/defs -> macro_agents
52+
macro_agents_root = current_file.parent.parent.parent
5053
repo_root = current_file.parent.parent.parent.parent.parent
54+
cwd = Path.cwd()
55+
56+
# In Dagster Cloud, the working_directory is set to ./macro_agents
57+
# The dbt_project should be copied there during deployment
58+
# The working directory at runtime is typically working_directory/root
59+
# So dbt_project should be at working_directory/root/dbt_project (i.e., cwd/dbt_project)
5160
possible_dbt_project_paths = [
52-
Path.cwd() / "dbt_project",
61+
# First priority: current working directory (Dagster Cloud runtime: working_directory/root)
62+
# This is where the working_directory contents are extracted
63+
cwd / "dbt_project",
64+
# Second: if we're in a "root" subdirectory, check parent
65+
cwd.parent / "dbt_project" if cwd.name == "root" else None,
66+
# Third: check if dbt_project is in the parent of root (working_directory level)
67+
cwd.parent.parent / "dbt_project" if cwd.parent.name == "root" else None,
68+
# Fourth: check relative to macro_agents package location (if bundled in wheel)
69+
macro_agents_root / "dbt_project",
70+
# Fifth: check if dbt_project is alongside the package
71+
macro_agents_root.parent / "dbt_project",
72+
# Sixth: check in macro_agents subdirectory (if working directory is repo root)
73+
cwd / "macro_agents" / "dbt_project",
74+
# Seventh: check in repo root (fallback)
5375
repo_root / "dbt_project",
54-
Path.cwd().parent / "dbt_project",
76+
# Eighth: check parent of working directory
77+
cwd.parent / "dbt_project",
78+
]
79+
80+
# Filter out None values
81+
possible_dbt_project_paths = [
82+
p for p in possible_dbt_project_paths if p is not None
5583
]
5684

5785
dbt_project_dir = None
5886
for path in possible_dbt_project_paths:
59-
abs_path = path.resolve()
60-
if abs_path.exists() and abs_path.is_dir():
61-
dbt_project_dir = abs_path
62-
break
87+
try:
88+
abs_path = path.resolve()
89+
if abs_path.exists() and abs_path.is_dir():
90+
# Verify it's actually a dbt project by checking for dbt_project.yml
91+
if (abs_path / "dbt_project.yml").exists() or (
92+
abs_path / "dbt_project.yaml"
93+
).exists():
94+
dbt_project_dir = abs_path
95+
break
96+
except (OSError, RuntimeError):
97+
# Skip paths that can't be resolved (e.g., broken symlinks)
98+
continue
6399

64100
if dbt_project_dir is None:
65-
tried_paths = [str(p.resolve()) for p in possible_dbt_project_paths]
101+
tried_paths = []
102+
for p in possible_dbt_project_paths:
103+
try:
104+
tried_paths.append(str(p.resolve()))
105+
except (OSError, RuntimeError):
106+
tried_paths.append(str(p))
107+
108+
# Also list what actually exists in the working directory for debugging
109+
cwd_contents = []
110+
try:
111+
cwd_contents = [str(p) for p in cwd.iterdir()] if cwd.exists() else []
112+
except (OSError, PermissionError):
113+
pass
114+
66115
raise FileNotFoundError(
67116
f"Could not find dbt_project directory.\n"
68117
f"Current working directory: {Path.cwd().resolve()}\n"
118+
f"Working directory contents: {cwd_contents}\n"
69119
f"Module file location: {current_file}\n"
120+
f"Macro agents root (calculated): {macro_agents_root}\n"
70121
f"Repo root (calculated): {repo_root}\n"
71122
f"Tried paths: {tried_paths}\n"
72123
f"Please ensure dbt_project directory exists relative to the repository root, "

0 commit comments

Comments
 (0)