Skip to content

Commit 80d0598

Browse files
authored
fix: Python host builder base image version (knative#2965)
Signed-off-by: Matej Vašek <[email protected]>
1 parent 719b286 commit 80d0598

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/oci/python_builder.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os/exec"
1111
slashpath "path"
1212
"path/filepath"
13+
"regexp"
1314

1415
v1 "github.com/google/go-containerregistry/pkg/v1"
1516
"github.com/google/go-containerregistry/pkg/v1/tarball"
@@ -23,7 +24,17 @@ func (b pythonBuilder) Base(customBase string) string {
2324
if customBase != "" {
2425
return customBase
2526
}
26-
return defaultPythonBase
27+
cmd := exec.Command("python", "-V")
28+
out, err := cmd.CombinedOutput()
29+
if err != nil {
30+
return defaultPythonBase
31+
}
32+
re := regexp.MustCompile(`Python (\d+\.\d+)\.\d+`)
33+
subMatches := re.FindSubmatch(out)
34+
if len(subMatches) != 2 {
35+
return defaultPythonBase
36+
}
37+
return fmt.Sprintf("python:%s-slim", subMatches[1])
2738
}
2839

2940
// Configure gives the python builder a chance to mutate the final

0 commit comments

Comments
 (0)