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 (
1516const (
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.
2742func 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.
6681func 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