Files
moby/builder/builder-next/executor_windows.go
Anthony Nandaa a9ec07a005 builder-next: add buildkit executor for wcow
WCOW support on Buildkit is now coming to maturity. As part
of making this generally available, integrating it in
Docker Engine is critical for it's adoption.

This commit adds the buildkit execuitor for WCOW as the
next-builder (backend) for building Windows containers.

This will be an opt-in feature, with the end users setting
DOCKER_BUILDKIT=1 environment variable to use it.

The integration tests bit has also been handled.
https://github.com/moby/buildkit/pull/5956,
BUILDKIT_REF has been set to `master` for now, so
that the tests can run successfully. On the next
release, we will revert this back to using releases.

Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
2025-05-20 00:14:09 +03:00

95 lines
2.3 KiB
Go

package buildkit
import (
"context"
"encoding/json"
"path/filepath"
ctd "github.com/containerd/containerd/v2/client"
"github.com/containerd/log"
"github.com/docker/docker/libnetwork"
"github.com/moby/buildkit/executor"
"github.com/moby/buildkit/executor/containerdexecutor"
"github.com/moby/buildkit/executor/oci"
"github.com/moby/buildkit/solver/llbsolver/cdidevices"
"github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/network"
"github.com/moby/sys/user"
"github.com/opencontainers/runtime-spec/specs-go"
)
const networkName = "nat"
func newExecutor(
root string,
_ string,
net *libnetwork.Controller,
dns *oci.DNSConfig,
_ bool,
_ user.IdentityMapping,
_ string,
cdiManager *cdidevices.Manager,
containerdAddr string,
containerdNamespace string,
) (executor.Executor, error) {
netRoot := filepath.Join(root, "net")
np := map[pb.NetMode]network.Provider{
pb.NetMode_UNSET: &bridgeProvider{Controller: net, Root: netRoot},
pb.NetMode_NONE: network.NewNoneProvider(),
}
opt := ctd.WithDefaultNamespace(containerdNamespace)
client, err := ctd.New(containerdAddr, opt)
if err != nil {
return nil, err
}
executorOpts := containerdexecutor.ExecutorOptions{
Client: client,
Root: root,
DNSConfig: dns,
CDIManager: cdiManager,
NetworkProviders: np,
}
return containerdexecutor.New(executorOpts), nil
}
func (iface *lnInterface) Set(s *specs.Spec) error {
<-iface.ready
if iface.err != nil {
log.G(context.TODO()).WithError(iface.err).Error("failed to set networking spec")
return iface.err
}
allowUnqualifiedDNSQuery := false
var epList []string
for _, ep := range iface.sbx.Endpoints() {
data, err := ep.DriverInfo()
if err != nil {
continue
}
if data["hnsid"] != nil {
epList = append(epList, data["hnsid"].(string))
}
if data["AllowUnqualifiedDNSQuery"] != nil {
allowUnqualifiedDNSQuery = true
}
}
if s.Windows == nil {
s.Windows = &specs.Windows{}
}
if s.Windows.Network == nil {
s.Windows.Network = &specs.WindowsNetwork{}
}
s.Windows.Network.EndpointList = epList
s.Windows.Network.AllowUnqualifiedDNSQuery = allowUnqualifiedDNSQuery
if b, err := json.Marshal(s); err == nil {
log.G(context.TODO()).Debugf("Generated spec: %s", string(b))
}
return nil
}