diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go index 6940ea153..c9c613eae 100644 --- a/cmd/frontend/main.go +++ b/cmd/frontend/main.go @@ -35,7 +35,7 @@ func main() { // copy/paster's beware: [frontend.WithTargetForwardingHandler] should not be set except for the root dalec frontend. frontend.WithBuiltinHandler(azlinux.Mariner2TargetKey, azlinux.NewMariner2Handler()), frontend.WithBuiltinHandler(azlinux.AzLinux3TargetKey, azlinux.NewAzlinux3Handler()), - frontend.WithBuiltinHandler(windows.DefaultTargetKey, windows.Handle), + windows.Handlers, ubuntu.Handlers, debian.Handlers, frontend.WithTargetForwardingHandler, diff --git a/frontend/windows/handle_container.go b/frontend/windows/handle_container.go index 8d58207f2..de023765f 100644 --- a/frontend/windows/handle_container.go +++ b/frontend/windows/handle_container.go @@ -33,7 +33,7 @@ var ( } ) -func handleContainer(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) { +func (c *config) handleContainer(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) { return frontend.BuildWithPlatform(ctx, client, func(ctx context.Context, client gwclient.Client, platform *ocispecs.Platform, spec *dalec.Spec, targetKey string) (gwclient.Reference, *dalec.DockerImageSpec, error) { sOpt, err := frontend.SourceOptFromClient(ctx, client) if err != nil { @@ -65,7 +65,7 @@ func handleContainer(ctx context.Context, client gwclient.Client) (*gwclient.Res return nil, nil, fmt.Errorf("unable to build binary %w", err) } - baseImgName := getBaseOutputImage(spec, targetKey, defaultBaseImage) + baseImgName := getBaseOutputImage(spec, targetKey, c.baseImage) baseImage := llb.Image(baseImgName, llb.Platform(targetPlatform)) out := baseImage. @@ -86,7 +86,7 @@ func handleContainer(ctx context.Context, client gwclient.Client) (*gwclient.Res imgRef := dalec.GetBaseOutputImage(spec, targetKey) if imgRef == "" { - imgRef = defaultBaseImage + imgRef = c.baseImage } _, _, dt, err := client.ResolveImageConfig(ctx, imgRef, sourceresolver.Opt{ diff --git a/frontend/windows/handler.go b/frontend/windows/handler.go index 01a7102e5..d0cdc9951 100644 --- a/frontend/windows/handler.go +++ b/frontend/windows/handler.go @@ -15,7 +15,6 @@ import ( ) const ( - DefaultTargetKey = "windowscross" outputKey = "windows" workerImgRef = "mcr.microsoft.com/mirror/docker/library/ubuntu:jammy" WindowscrossWorkerContextName = "dalec-windowscross-worker" @@ -44,7 +43,34 @@ var ( } ) -func Handle(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) { +var ( + windowscross_1809 = &config{baseImage: "mcr.microsoft.com/windows/nanoserver:1809"} + windowscross_ltsc2019 = &config{baseImage: "mcr.microsoft.com/windows/nanoserver:ltsc2019"} + windowscross_ltsc2022 = &config{baseImage: "mcr.microsoft.com/windows/nanoserver:ltsc2022"} + windowscross_ltsc2025 = &config{baseImage: "mcr.microsoft.com/windows/nanoserver:ltsc2025"} + windowscross_20H2 = &config{baseImage: "mcr.microsoft.com/windows/nanoserver:20H2"} + windowscross_1909 = &config{baseImage: "mcr.microsoft.com/windows/nanoserver:1909"} + windowscross_2004 = &config{baseImage: "mcr.microsoft.com/windows/nanoserver:2004"} +) + +func Handlers(ctx context.Context, client gwclient.Client, m *frontend.BuildMux) error { + targets := map[string]gwclient.BuildFunc{ + "windowscross-1809": windowscross_1809.Handle, + "windowscross-ltsc2019": windowscross_ltsc2019.Handle, + "windowscross-ltsc2022": windowscross_ltsc2022.Handle, + "windowscross-ltsc2025": windowscross_ltsc2025.Handle, + "windowscross-20H2": windowscross_20H2.Handle, + "windowscross-1909": windowscross_1909.Handle, + "windowscross-2004": windowscross_2004.Handle, + } + return frontend.LoadBuiltinTargets(targets)(ctx, client, m) +} + +type config struct { + baseImage string +} + +func (c *config) Handle(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) { var mux frontend.BuildMux mux.Add("zip", handleZip, &bktargets.Target{ @@ -52,7 +78,7 @@ func Handle(ctx context.Context, client gwclient.Client) (*gwclient.Result, erro Description: "Builds binaries combined into a zip file", }) - mux.Add("container", handleContainer, &bktargets.Target{ + mux.Add("container", c.handleContainer, &bktargets.Target{ Name: "container", Description: "Builds binaries and installs them into a Windows base image", Default: true, diff --git a/test/windows_test.go b/test/windows_test.go index e5c6fae1f..5d9186f37 100644 --- a/test/windows_test.go +++ b/test/windows_test.go @@ -16,29 +16,32 @@ import ( "golang.org/x/exp/maps" ) -var windowsAmd64 = ocispecs.Platform{OS: "windows", Architecture: "amd64"} +var ( + windowsAmd64 = ocispecs.Platform{OS: "windows", Architecture: "amd64"} + windowscrossTarget = "windowscross-1809" +) func TestWindows(t *testing.T) { t.Parallel() ctx := startTestSpan(baseCtx, t) testWindows(ctx, t, targetConfig{ - Package: "windowscross/zip", - Container: "windowscross/container", + Package: windowscrossTarget + "/zip", + Container: windowscrossTarget + "/container", ListExpectedSignFiles: func(spec *dalec.Spec, platform ocispecs.Platform) []string { return maps.Keys(spec.Artifacts.Binaries) }, }) tcfg := targetConfig{ - Container: "windowscross/container", + Container: windowscrossTarget + "/container", // The way the test uses the package target is to generate a package which // it then feeds back into a custom repo and adds that package as a build dep // to another package. - // We don't build system packages for the windowscross base image. + // We don't build system packages for the windowscross- base image. // So... use jammy to create a deb which we'll use to create a repo. Package: "jammy/deb", - Worker: "windowscross/worker", + Worker: windowscrossTarget + "/worker", FormatDepEqual: func(ver, rev string) string { return ver + "-ubuntu22.04u" + rev }, @@ -326,7 +329,7 @@ echo "$BAR" > bar.txt t.Fatal(err) } - post := spec.GetImagePost("windowscross") + post := spec.GetImagePost(windowscrossTarget) for srcPath, l := range post.Symlinks { b1, err := ref.ReadFile(ctx, gwclient.ReadRequest{ Filename: srcPath, @@ -432,7 +435,7 @@ echo "$BAR" > bar.txt func prepareWindowsSigningState(ctx context.Context, t *testing.T, gwc gwclient.Client, spec *dalec.Spec, extraSrOpts ...srOpt) llb.State { zipper := getZipperState(ctx, t, gwc) - srOpts := []srOpt{withSpec(ctx, t, spec), withBuildTarget("windowscross/zip"), withWindowsAmd64} + srOpts := []srOpt{withSpec(ctx, t, spec), withBuildTarget(windowscrossTarget + "/zip"), withWindowsAmd64} srOpts = append(srOpts, extraSrOpts...) sr := newSolveRequest(srOpts...)