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 10, 2024
1 parent ed7390b commit 47c4796
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 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
31 changes: 29 additions & 2 deletions frontend/windows/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,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

0 comments on commit 47c4796

Please sign in to comment.