Skip to content

Commit e594bad

Browse files
author
szachovy
committed
Fix image pull overwriting pre-loaded images and missing PYTHONPATH
Two bugs: 1. pull_or_build_image always called client.images.pull() which pulls from the registry even when the image was already loaded into the node via docker save | docker load in CI. This overwrote the locally-built image (containing the /var/log/mysql fix) with the published GHCR version that lacks it, causing mysql entrypoint to fail with Permission denied. Fix: check images.get() first and only pull/build if the image is not already present locally. 2. exec_command over SSH runs in a non-login, non-interactive shell which does not load ~/.profile or PYTHONPATH, so pip --user packages at ~/.local/lib/python3.10/site-packages are not found. This caused ModuleNotFoundError: No module named 'docker' when running container.py remotely. Fix: prepend PYTHONPATH explicitly.
1 parent 9556ef2 commit e594bad

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/container.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ def __init__(self, container: str | None) -> None:
103103
@staticmethod
104104
def pull_or_build_image(client: docker.client.DockerClient, image: str, build_context: str) -> None:
105105
try:
106-
client.images.pull(image)
107-
except (docker.errors.DockerException, requests.exceptions.RequestException):
108-
client.images.build(path=build_context, tag=image)
106+
client.images.get(image)
107+
except docker.errors.ImageNotFound:
108+
try:
109+
client.images.pull(image)
110+
except (docker.errors.DockerException, requests.exceptions.RequestException):
111+
client.images.build(path=build_context, tag=image)
109112

110113
def run_command_on_the_container(
111114
self,

src/remote.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ def run_python_container_command(self, command: str) -> dict:
125125
) as memfile:
126126
source = memfile.read() + command
127127
self.upload_file(content=source, remote_file_path=f'/opt/{nonce}.py')
128-
_, stdout, stderr = self.ssh_client.exec_command(f"python3 /opt/{nonce}.py")
128+
_, stdout, stderr = self.ssh_client.exec_command(
129+
f"PYTHONPATH=/home/superset/.local/lib/python3.10/site-packages python3 /opt/{nonce}.py"
130+
)
129131
result = {
130132
"output": stdout.read().decode(),
131133
"error": stderr.read().decode()

0 commit comments

Comments
 (0)