Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit edd23d2

Browse files
author
Piotr Stankiewicz
committed
Allow setting controller image version via env
During testing, or as an occasional workaround, it would be useful to specify a model-runner controller image version. So, add the ability to supply it via an environment variable. Signed-off-by: Piotr Stankiewicz <[email protected]>
1 parent 46a3127 commit edd23d2

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

pkg/standalone/containers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
7171
var imageName string
7272
switch gpu {
7373
case gpupkg.GPUSupportCUDA:
74-
imageName = ControllerImage + ":" + controllerImageTagCUDA
74+
imageName = ControllerImage + ":" + controllerImageTagCUDA()
7575
default:
76-
imageName = ControllerImage + ":" + controllerImageTagCPU
76+
imageName = ControllerImage + ":" + controllerImageTagCPU()
7777
}
7878

7979
// Set up the container configuration.

pkg/standalone/images.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"os"
89

910
"github.com/docker/docker/api/types/image"
1011
"github.com/docker/docker/client"
@@ -15,23 +16,37 @@ import (
1516
const (
1617
// ControllerImage is the image used for the controller container.
1718
ControllerImage = "docker/model-runner"
18-
// controllerImageTagCPU is the image tag used for the controller container
19+
// defaultControllerImageTagCPU is the image tag used for the controller container
1920
// when running with the CPU backend.
20-
controllerImageTagCPU = "latest"
21-
// controllerImageTagCUDA is the image tag used for the controller container
21+
defaultControllerImageTagCPU = "latest"
22+
// defaultControllerImageTagCUDA is the image tag used for the controller container
2223
// when running with the CUDA GPU backend.
23-
controllerImageTagCUDA = "latest-cuda"
24+
defaultControllerImageTagCUDA = "latest-cuda"
2425
)
2526

27+
func controllerImageTagCPU() string {
28+
if version, ok := os.LookupEnv("MODEL_RUNNER_CONTROLLER_VERSION"); ok {
29+
return version
30+
}
31+
return defaultControllerImageTagCPU
32+
}
33+
34+
func controllerImageTagCUDA() string {
35+
if version, ok := os.LookupEnv("MODEL_RUNNER_CONTROLLER_VERSION"); ok {
36+
return version + "-cuda"
37+
}
38+
return defaultControllerImageTagCUDA
39+
}
40+
2641
// EnsureControllerImage ensures that the controller container image is pulled.
2742
func EnsureControllerImage(ctx context.Context, dockerClient *client.Client, gpu gpupkg.GPUSupport, printer StatusPrinter) error {
2843
// Determine the target image.
2944
var imageName string
3045
switch gpu {
3146
case gpupkg.GPUSupportCUDA:
32-
imageName = ControllerImage + ":" + controllerImageTagCUDA
47+
imageName = ControllerImage + ":" + controllerImageTagCUDA()
3348
default:
34-
imageName = ControllerImage + ":" + controllerImageTagCPU
49+
imageName = ControllerImage + ":" + controllerImageTagCPU()
3550
}
3651

3752
// Perform the pull.
@@ -65,13 +80,13 @@ func EnsureControllerImage(ctx context.Context, dockerClient *client.Client, gpu
6580
// PruneControllerImages removes any unused controller container images.
6681
func PruneControllerImages(ctx context.Context, dockerClient *client.Client, printer StatusPrinter) error {
6782
// Remove the standard image, if present.
68-
imageNameCPU := ControllerImage + ":" + controllerImageTagCPU
83+
imageNameCPU := ControllerImage + ":" + controllerImageTagCPU()
6984
if _, err := dockerClient.ImageRemove(ctx, imageNameCPU, image.RemoveOptions{}); err == nil {
7085
printer.Println("Removed image", imageNameCPU)
7186
}
7287

7388
// Remove the CUDA GPU image, if present.
74-
imageNameCUDA := ControllerImage + ":" + controllerImageTagCUDA
89+
imageNameCUDA := ControllerImage + ":" + controllerImageTagCUDA()
7590
if _, err := dockerClient.ImageRemove(ctx, imageNameCUDA, image.RemoveOptions{}); err == nil {
7691
printer.Println("Removed image", imageNameCUDA)
7792
}

0 commit comments

Comments
 (0)