Skip to content

Commit

Permalink
add windowscross version handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBrito committed Dec 11, 2024
1 parent ed7390b commit f905172
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions frontend/windows/handle_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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{
Expand Down
32 changes: 29 additions & 3 deletions frontend/windows/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

const (
DefaultTargetKey = "windowscross"
outputKey = "windows"
workerImgRef = "mcr.microsoft.com/mirror/docker/library/ubuntu:jammy"
WindowscrossWorkerContextName = "dalec-windowscross-worker"
Expand Down Expand Up @@ -44,15 +43,42 @@ 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{
Name: "zip",
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,
Expand Down
19 changes: 11 additions & 8 deletions test/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-<version> 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
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit f905172

Please sign in to comment.