diff --git a/api/pkg/imagebuilder/imagebuilder.go b/api/pkg/imagebuilder/imagebuilder.go index e1fac375f..d180ccc31 100644 --- a/api/pkg/imagebuilder/imagebuilder.go +++ b/api/pkg/imagebuilder/imagebuilder.go @@ -142,10 +142,6 @@ func (c *imageBuilder) validatePythonVersion(version *models.Version) error { // GetMainAppPath Returns the path to run the main.py of batch predictor, as configured via env var func (c *imageBuilder) GetMainAppPath(version *models.Version) (string, error) { - if err := c.validatePythonVersion(version); err != nil { - return "", err - } - baseImageTag := c.config.BaseImage if baseImageTag.MainAppPath == "" { return "", fmt.Errorf("mainAppPath is not set for tag %s", version.PythonVersion) @@ -202,6 +198,10 @@ func (c *imageBuilder) BuildImage(ctx context.Context, project mlp.Project, mode return imageRef, nil } + if err := c.validatePythonVersion(version); err != nil { + return "", err + } + startTime := time.Now() result := "failed" diff --git a/api/pkg/imagebuilder/imagebuilder_test.go b/api/pkg/imagebuilder/imagebuilder_test.go index 6090cf893..975750af6 100644 --- a/api/pkg/imagebuilder/imagebuilder_test.go +++ b/api/pkg/imagebuilder/imagebuilder_test.go @@ -110,6 +110,8 @@ var ( "--use-new-run", } + defaultSupportedPythonVersions = []string{"3.8.*", "3.9.*", "3.10.*"} + config = Config{ BuildNamespace: testBuildNamespace, BaseImage: cfg.BaseImageConfig{ @@ -118,13 +120,14 @@ var ( BuildContextSubPath: "python/pyfunc-server", DockerfilePath: "./Dockerfile", }, - DockerRegistry: testDockerRegistry, - BuildTimeoutDuration: timeout, - ClusterName: "my-cluster", - GcpProject: "test-project", - Environment: testEnvironmentName, - KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0", - KanikoAdditionalArgs: defaultKanikoAdditionalArgs, + DockerRegistry: testDockerRegistry, + BuildTimeoutDuration: timeout, + ClusterName: "my-cluster", + GcpProject: "test-project", + Environment: testEnvironmentName, + KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0", + KanikoAdditionalArgs: defaultKanikoAdditionalArgs, + SupportedPythonVersions: defaultSupportedPythonVersions, DefaultResources: cfg.ResourceRequestsLimits{ Requests: cfg.Resource{ CPU: "500m", @@ -156,13 +159,14 @@ var ( BuildContextSubPath: "python/pyfunc-server", DockerfilePath: "./Dockerfile", }, - DockerRegistry: testDockerRegistry, - BuildTimeoutDuration: timeout, - ClusterName: "my-cluster", - GcpProject: "test-project", - Environment: testEnvironmentName, - KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0", - KanikoAdditionalArgs: defaultKanikoAdditionalArgs, + DockerRegistry: testDockerRegistry, + BuildTimeoutDuration: timeout, + ClusterName: "my-cluster", + GcpProject: "test-project", + Environment: testEnvironmentName, + KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0", + KanikoAdditionalArgs: defaultKanikoAdditionalArgs, + SupportedPythonVersions: defaultSupportedPythonVersions, DefaultResources: cfg.ResourceRequestsLimits{ Requests: cfg.Resource{ CPU: "500m", @@ -555,14 +559,15 @@ func TestBuildImage(t *testing.T) { BuildContextSubPath: "python/pyfunc-server", DockerfilePath: "./Dockerfile", }, - DockerRegistry: testDockerRegistry, - BuildTimeoutDuration: timeout, - ClusterName: "my-cluster", - GcpProject: "test-project", - Environment: testEnvironmentName, - KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0", - KanikoAdditionalArgs: defaultKanikoAdditionalArgs, - DefaultResources: config.DefaultResources, + DockerRegistry: testDockerRegistry, + BuildTimeoutDuration: timeout, + ClusterName: "my-cluster", + GcpProject: "test-project", + Environment: testEnvironmentName, + KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0", + KanikoAdditionalArgs: defaultKanikoAdditionalArgs, + SupportedPythonVersions: defaultSupportedPythonVersions, + DefaultResources: config.DefaultResources, NodeSelectors: map[string]string{ "cloud.google.com/gke-nodepool": "image-building-job-node-pool", }, @@ -685,14 +690,15 @@ func TestBuildImage(t *testing.T) { BuildContextSubPath: "python/pyfunc-server", DockerfilePath: "./Dockerfile", }, - DockerRegistry: testDockerRegistry, - BuildTimeoutDuration: timeout, - ClusterName: "my-cluster", - GcpProject: "test-project", - Environment: testEnvironmentName, - KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0", - KanikoAdditionalArgs: defaultKanikoAdditionalArgs, - DefaultResources: config.DefaultResources, + DockerRegistry: testDockerRegistry, + BuildTimeoutDuration: timeout, + ClusterName: "my-cluster", + GcpProject: "test-project", + Environment: testEnvironmentName, + KanikoImage: "gcr.io/kaniko-project/executor:v1.1.0", + KanikoAdditionalArgs: defaultKanikoAdditionalArgs, + SupportedPythonVersions: defaultSupportedPythonVersions, + DefaultResources: config.DefaultResources, Tolerations: []v1.Toleration{ { Key: "image-build-job", @@ -821,17 +827,18 @@ func TestBuildImage(t *testing.T) { BuildContextURI: testBuildContextURL, DockerfilePath: "./Dockerfile", }, - DockerRegistry: config.DockerRegistry, - BuildTimeoutDuration: config.BuildTimeoutDuration, - ClusterName: config.ClusterName, - GcpProject: config.GcpProject, - Environment: config.Environment, - KanikoImage: config.KanikoImage, - KanikoAdditionalArgs: defaultKanikoAdditionalArgs, - DefaultResources: config.DefaultResources, - MaximumRetry: config.MaximumRetry, - NodeSelectors: config.NodeSelectors, - Tolerations: config.Tolerations, + DockerRegistry: config.DockerRegistry, + BuildTimeoutDuration: config.BuildTimeoutDuration, + ClusterName: config.ClusterName, + GcpProject: config.GcpProject, + Environment: config.Environment, + KanikoImage: config.KanikoImage, + KanikoAdditionalArgs: defaultKanikoAdditionalArgs, + SupportedPythonVersions: defaultSupportedPythonVersions, + DefaultResources: config.DefaultResources, + MaximumRetry: config.MaximumRetry, + NodeSelectors: config.NodeSelectors, + Tolerations: config.Tolerations, }, }, {