Skip to content

Commit 7c2a9f8

Browse files
added util to use minikube docker env to store model deploy images
1 parent c5d6796 commit 7c2a9f8

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

tests/tests_end_to_end/test_from_project_creation_to_model_predict.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import string
1515
import subprocess
1616
import time
17+
import os
1718

1819
import mlflow
1920
import mlflow.sklearn
@@ -97,6 +98,36 @@ def _skip_if_mlflow_not_ready():
9798
# --- Debug helpers to surface CI failures ---
9899

99100

101+
def _setup_minikube_docker_env():
102+
"""Ensure we're using minikube's docker daemon for image builds."""
103+
try:
104+
# Get minikube docker env
105+
result = subprocess.run(
106+
["minikube", "docker-env", "--shell", "bash"],
107+
capture_output=True,
108+
text=True,
109+
timeout=30,
110+
)
111+
if result.returncode == 0:
112+
# Parse the env vars from minikube docker-env output
113+
env_lines = [line.strip() for line in result.stdout.split("\n") if line.startswith("export ")]
114+
for line in env_lines:
115+
if "=" in line:
116+
# Extract VAR=value from "export VAR=value"
117+
var_assignment = line.replace("export ", "", 1)
118+
if "=" in var_assignment:
119+
key, value = var_assignment.split("=", 1)
120+
# Remove quotes from value if present
121+
value = value.strip("\"'")
122+
os.environ[key] = value
123+
print(f"[DEBUG] Set {key}={value}")
124+
print("[DEBUG] Minikube docker environment configured")
125+
else:
126+
print(f"[DEBUG] Failed to get minikube docker-env: {result.stderr}")
127+
except Exception as exc:
128+
print(f"[DEBUG] Error setting up minikube docker env: {exc}")
129+
130+
100131
def _run_debug_cmd(label, cmd):
101132
print(f"[DEBUG] {label}: {' '.join(cmd)}")
102133
try:
@@ -137,7 +168,11 @@ def _dump_deployment_debug_info(deployment_name):
137168
pod_name = _first_pod_name(PROJECT_NAME)
138169
if pod_name:
139170
_run_debug_cmd("kubectl describe pod", ["kubectl", "describe", "pod", pod_name, "-n", PROJECT_NAME])
140-
_run_debug_cmd("kubectl logs", ["kubectl", "logs", pod_name, "-n", PROJECT_NAME])
171+
_run_debug_cmd("kubectl logs current", ["kubectl", "logs", pod_name, "-n", PROJECT_NAME])
172+
_run_debug_cmd("kubectl logs previous", ["kubectl", "logs", pod_name, "-n", PROJECT_NAME, "--previous"])
173+
174+
# Also check available images in minikube
175+
_run_debug_cmd("minikube image ls", ["minikube", "image", "ls"])
141176

142177

143178
def _dump_registry_status():
@@ -174,7 +209,16 @@ def test_train_and_push_model_to_mlflow():
174209
def test_deploy_model():
175210
"""Test model deployment."""
176211
_skip_if_mlflow_not_ready()
212+
# Ensure we use minikube's docker daemon for image builds
213+
_setup_minikube_docker_env()
177214
result = run_cli("projects", "deploy", PROJECT_NAME, "--model-name", MODEL_NAME, "--model-version", MODEL_VERSION)
215+
216+
# Check if image exists in minikube after deployment
217+
expected_image_name = (
218+
f"{PROJECT_NAME.lower().replace('_', '-')}-{MODEL_NAME.lower().replace('_', '-')}-{MODEL_VERSION}-ctr:latest"
219+
)
220+
_run_debug_cmd("minikube image ls", ["minikube", "image", "ls"])
221+
178222
assert result.returncode == 0, f"Deploy failed: {result.stderr}"
179223

180224

0 commit comments

Comments
 (0)