Skip to content

Commit 7c8de9d

Browse files
committed
mount the user directory instead of figuring out the python paths
1 parent acbd2ab commit 7c8de9d

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/gaiaflow/managers/mlops_manager.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
save_project_state,
3838
set_permissions,
3939
update_micromamba_env_in_docker,
40+
update_entrypoint_install_path,
4041
)
4142

4243

@@ -422,24 +423,11 @@ def _collect_volumes(self, compose_data: dict) -> list[str]:
422423
)
423424
new_volumes.append(f"{src_path}:{dst}")
424425

425-
# Collect User Python packages from their project directory to mount
426-
# them to docker containers
427-
existing_mounts = {Path(v.split(":", 1)[0]).name for v in new_volumes}
428-
python_packages = find_python_packages(self.user_project_path)
429-
430426
# Set permissions so that docker containers can execute the code in
431427
# their package
432-
for package in python_packages:
433-
set_permissions(package, 0o755)
434-
435-
for child in self.user_project_path.iterdir():
436-
if (
437-
child.is_dir()
438-
and child.name not in existing_mounts
439-
and child.name in python_packages
440-
):
441-
dst_path = f"/opt/airflow/{child.name}"
442-
new_volumes.append(f"{child.resolve().as_posix()}:{dst_path}")
428+
set_permissions(self.user_project_path, 0o755)
429+
430+
new_volumes.append(f"{self.user_project_path.resolve().as_posix()}:/opt/airflow/{self.user_project_path.name}")
443431

444432
# Add special mounts for prod_local mode
445433
kube_config = (
@@ -484,6 +472,8 @@ def _update_files(self):
484472
entrypoint_path = (
485473
self.gaiaflow_path / "_docker" / "docker-compose" / "entrypoint.sh"
486474
)
475+
update_entrypoint_install_path(entrypoint_path,
476+
str(self.user_project_path.name))
487477
set_permissions(entrypoint_path)
488478
convert_crlf_to_lf(entrypoint_path)
489479

src/gaiaflow/managers/utils.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ def set_permissions(path, mode=0o777):
225225
fs.chmod(path, mode)
226226
log_info(f"Set permissions for {path}")
227227
except Exception:
228-
log_info(f"Warning: Could not set permissions for {path}")
228+
log_error(f"Warning: Could not set permissions for {path}")
229+
log_error(f"Try running this command manually:\n chmod -R {mode:o} {path}")
230+
log_info("Continuing...")
229231

230232

231233
def create_gaiaflow_context_path(project_path: Path) -> tuple[Path, Path]:
@@ -304,3 +306,21 @@ def _update_one(cname: str):
304306
future.result()
305307
except Exception as e:
306308
log_error(f"[{cname}] Unexpected error: {e}")
309+
310+
311+
def update_entrypoint_install_path(script_path: str | Path, new_path: str) -> str:
312+
"""Update the micromamba pip install path in the given bash script."""
313+
script_path = Path(script_path)
314+
lines = script_path.read_text().splitlines()
315+
316+
new_lines = []
317+
for line in lines:
318+
if line.strip().startswith("micromamba run -n default_user_env pip install -e"):
319+
line = f'micromamba run -n default_user_env pip install -e {new_path}'
320+
new_lines.append(line)
321+
322+
updated_text = "\n".join(new_lines) + "\n"
323+
324+
script_path.write_text(updated_text)
325+
326+
return updated_text

0 commit comments

Comments
 (0)