Skip to content

Commit

Permalink
Infer previous value of PATH variable from container
Browse files Browse the repository at this point in the history
rather than relying on shell variable expansion
  • Loading branch information
ckunki committed Aug 8, 2024
1 parent 5da00cd commit 9ae60e5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion exasol/ds/sandbox/lib/dss_docker/create_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ def _install_dependencies(self) -> AnsibleFacts:
ansible_repositories=ansible_repository.default_repositories,
)

def _path(self, container: DockerContainer, dir: str) -> str:
env_list = container.attrs["Config"]["Env"]
env_dict = dict(e.split("=", 1) for e in env_list)
path = env_dict.get("PATH")
return f"{path}:{dir}" if path else dir

def _commit_container(
self,
container: DockerContainer,
Expand All @@ -166,6 +172,8 @@ def _commit_container(
port = get_fact(facts, "jupyter", "port")
notebook_folder_final = get_fact(facts, "notebook_folder", "final")
notebook_folder_initial = get_fact(facts, "notebook_folder", "initial")

path = self._path(container, f"{virtualenv}/bin")
conf = {
"Entrypoint": entrypoint(facts),
"Cmd": [],
Expand All @@ -176,7 +184,7 @@ def _commit_container(
f"VIRTUAL_ENV={virtualenv}",
f"NOTEBOOK_FOLDER_FINAL={notebook_folder_final}",
f"NOTEBOOK_FOLDER_INITIAL={notebook_folder_initial}",
f"PATH=$PATH:{virtualenv}/bin",
f"PATH={path}",
],
}
img = container.commit(repository=self.image_name, conf=conf)
Expand Down

0 comments on commit 9ae60e5

Please sign in to comment.