1
0
Fork 0
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:
Cursor Agent 2026-06-10 16:02:33 +00:00
parent 37a7e85893
commit f17ec18a0c
No known key found for this signature in database
5 changed files with 126 additions and 0 deletions

View file

@ -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,