-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support OS version in platform string #5614
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,7 @@ var allTests = integration.TestFuncs( | |
testStepNames, | ||
testPowershellInDefaultPathOnWindows, | ||
testOCILayoutMultiname, | ||
testPlatformWithOSVersion, | ||
) | ||
|
||
// Tests that depend on the `security.*` entitlements | ||
|
@@ -9425,6 +9426,158 @@ COPY Dockerfile /foo | |
} | ||
} | ||
|
||
func testPlatformWithOSVersion(t *testing.T, sb integration.Sandbox) { | ||
cpuguy83 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This test cannot be run on Windows currently due to `FROM scratch` and | ||
// layer formatting not being supported on Windows. | ||
integration.SkipOnPlatform(t, "windows") | ||
|
||
ctx := sb.Context() | ||
|
||
c, err := client.New(ctx, sb.Address()) | ||
require.NoError(t, err) | ||
defer c.Close() | ||
|
||
f := getFrontend(t, sb) | ||
|
||
// NOTE: currently "OS" *must* be set to "windows" for this to work. | ||
// The platform matchers only do OSVersion comparisons when the OS is set to "windows". | ||
p1 := ocispecs.Platform{ | ||
OS: "windows", | ||
OSVersion: "1.2.3", | ||
Architecture: "bar", | ||
} | ||
p2 := ocispecs.Platform{ | ||
OS: "windows", | ||
OSVersion: "1.1.0", | ||
Architecture: "bar", | ||
} | ||
|
||
p1Str := platforms.FormatAll(p1) | ||
p2Str := platforms.FormatAll(p2) | ||
|
||
registry, err := sb.NewRegistry() | ||
if errors.Is(err, integration.ErrRequirements) { | ||
t.Skip(err.Error()) | ||
} | ||
require.NoError(t, err) | ||
target := registry + "/buildkit/testplatformwithosversion:latest" | ||
|
||
dockerfile := []byte(` | ||
FROM ` + target + ` AS reg | ||
|
||
FROM scratch AS base | ||
ARG TARGETOSVERSION | ||
COPY <<EOF /osversion | ||
${TARGETOSVERSION} | ||
EOF | ||
ARG TARGETPLATFORM | ||
COPY <<EOF /targetplatform | ||
${TARGETPLATFORM} | ||
EOF | ||
`) | ||
|
||
destDir := t.TempDir() | ||
dir := integration.Tmpdir( | ||
t, | ||
fstest.CreateFile("Dockerfile", dockerfile, 0600), | ||
) | ||
|
||
// build the base target as a multi-platform image and push to the registry | ||
_, err = f.Solve(sb.Context(), c, client.SolveOpt{ | ||
FrontendAttrs: map[string]string{ | ||
"platform": p1Str + "," + p2Str, | ||
"target": "base", | ||
}, | ||
Exports: []client.ExportEntry{ | ||
{ | ||
Type: client.ExporterLocal, | ||
OutputDir: destDir, | ||
}, | ||
{ | ||
Type: client.ExporterImage, | ||
Attrs: map[string]string{ | ||
"name": target, | ||
"push": "true", | ||
}, | ||
}, | ||
}, | ||
|
||
LocalMounts: map[string]fsutil.FS{ | ||
dockerui.DefaultLocalNameDockerfile: dir, | ||
dockerui.DefaultLocalNameContext: dir, | ||
}, | ||
}, nil) | ||
|
||
require.NoError(t, err) | ||
|
||
dt, err := os.ReadFile(filepath.Join(destDir, strings.Replace(p1Str, "/", "_", 1), "osversion")) | ||
require.NoError(t, err) | ||
require.Equal(t, p1.OSVersion+"\n", string(dt)) | ||
|
||
dt, err = os.ReadFile(filepath.Join(destDir, strings.Replace(p1Str, "/", "_", 1), "targetplatform")) | ||
require.NoError(t, err) | ||
require.Equal(t, p1Str+"\n", string(dt)) | ||
|
||
dt, err = os.ReadFile(filepath.Join(destDir, strings.Replace(p2Str, "/", "_", 1), "osversion")) | ||
require.NoError(t, err) | ||
require.Equal(t, p2.OSVersion+"\n", string(dt)) | ||
|
||
dt, err = os.ReadFile(filepath.Join(destDir, strings.Replace(p2Str, "/", "_", 1), "targetplatform")) | ||
require.NoError(t, err) | ||
require.Equal(t, p2Str+"\n", string(dt)) | ||
|
||
// Now build the "reg" target, which should pull the base image from the registry | ||
// This should select the image with the requested os version. | ||
destDir = t.TempDir() | ||
_, err = f.Solve(sb.Context(), c, client.SolveOpt{ | ||
FrontendAttrs: map[string]string{ | ||
"platform": p1Str, | ||
"target": "reg", | ||
}, | ||
Exports: []client.ExportEntry{ | ||
{ | ||
Type: client.ExporterLocal, | ||
OutputDir: destDir, | ||
}, | ||
}, | ||
|
||
LocalMounts: map[string]fsutil.FS{ | ||
dockerui.DefaultLocalNameDockerfile: dir, | ||
dockerui.DefaultLocalNameContext: dir, | ||
}, | ||
}, nil) | ||
require.NoError(t, err) | ||
|
||
dt, err = os.ReadFile(filepath.Join(destDir, "osversion")) | ||
require.NoError(t, err) | ||
require.Equal(t, p1.OSVersion+"\n", string(dt)) | ||
|
||
// And again with the other os version | ||
destDir = t.TempDir() | ||
_, err = f.Solve(sb.Context(), c, client.SolveOpt{ | ||
FrontendAttrs: map[string]string{ | ||
"platform": p2Str, | ||
"target": "reg", | ||
}, | ||
Exports: []client.ExportEntry{ | ||
{ | ||
Type: client.ExporterLocal, | ||
OutputDir: destDir, | ||
}, | ||
}, | ||
|
||
LocalMounts: map[string]fsutil.FS{ | ||
dockerui.DefaultLocalNameDockerfile: dir, | ||
dockerui.DefaultLocalNameContext: dir, | ||
}, | ||
}, nil) | ||
require.NoError(t, err) | ||
|
||
dt, err = os.ReadFile(filepath.Join(destDir, "osversion")) | ||
require.NoError(t, err) | ||
require.Equal(t, p2.OSVersion+"\n", string(dt)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check that the correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a note: We discussed this on Slack and will follow-up with this after merge. |
||
} | ||
|
||
func runShell(dir string, cmds ...string) error { | ||
for _, args := range cmds { | ||
var cmd *exec.Cmd | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a little janky.
When the platform string is not exactly what was requested (i.e. no OS version) then the returned result which has the OS Version will trigger a warning.