mirror of
https://github.com/imjasonh/terraform-playground
synced 2026-07-22 08:01:06 +00:00
build: validate base interpreter against --python to catch floating-tag drift
Reads the base image's advertised PYTHON_VERSION (config env, no layer download) and fails the build when it doesn't match --python, so a base tag that slides to a new Python version can't silently produce a broken image. Documents base-pinning tradeoffs in the README. Adds unit + CLI tests. Co-authored-by: Jason Hall <imjasonh@users.noreply.github.com>
This commit is contained in:
parent
37a7e85893
commit
f17ec18a0c
5 changed files with 126 additions and 0 deletions
|
|
@ -208,6 +208,14 @@ func buildOne(ctx context.Context, f *buildFlags, reqs []lock.Requirement, platf
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// If the base advertises its interpreter version, make sure it matches the
|
||||
// requested --python. This catches a floating base tag (e.g. ":latest")
|
||||
// sliding to a Python version that the selected wheels/layout don't target,
|
||||
// which would otherwise silently produce a broken image.
|
||||
if maj, min, ok := build.InterpreterVersion(base); ok && (maj != target.PyMajor || min != target.PyMinor) {
|
||||
return nil, nil, fmt.Errorf("base %q provides Python %d.%d but --python is python%d.%d; pass --python python%d.%d (or pin a matching base)",
|
||||
f.base, maj, min, target.PyMajor, target.PyMinor, maj, min)
|
||||
}
|
||||
img, err := build.Build(build.Options{
|
||||
Base: base,
|
||||
Wheels: wheels,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue