Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion environment/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,25 @@ func (e *Environment) Create() error {
UsernsMode: container.UsernsMode(cfg.Docker.UsernsMode),
}

if _, err := e.client.ContainerCreate(ctx, conf, hostConf, nil, nil, e.Id); err != nil {
var netConf *network.NetworkingConfig = nil //In case when no networking config is needed set nil
var serverNetConfig = config.Get().Docker.Network
if "macvlan" == serverNetConfig.Driver { //Generate networking config for macvlan driver
var defaultMapping = e.Config().Allocations().DefaultMapping
e.log().Debug("Set macvlan " + serverNetConfig.Name + " IP to " + defaultMapping.Ip)
netConf = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
serverNetConfig.Name: { //Get network name from wings config
IPAMConfig: &network.EndpointIPAMConfig{
IPv4Address: defaultMapping.Ip,
},
IPAddress: defaultMapping.Ip, //Use default mapping ip address (wings support only one network per server)
Gateway: serverNetConfig.Interfaces.V4.Gateway,
},
},
}
}
// Pass the networkings configuration or nil if none required
if _, err := e.client.ContainerCreate(ctx, conf, hostConf, netConf, nil, e.Id); err != nil {
return errors.Wrap(err, "environment/docker: failed to create container")
}

Expand Down
21 changes: 20 additions & 1 deletion server/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
dockerImage "github.com/docker/docker/api/types/image"

"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/parsers/kernel"

Expand Down Expand Up @@ -475,7 +476,25 @@ func (ip *InstallationProcess) Execute() (string, error) {
}
}()

r, err := ip.client.ContainerCreate(ctx, conf, hostConf, nil, nil, ip.Server.ID()+"_installer")
var netConf *network.NetworkingConfig = nil //In case when no networking config is needed set nil
Copy link

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify the nil initialization by declaring var netConf *network.NetworkingConfig without explicitly assigning nil.

Suggested change
var netConf *network.NetworkingConfig = nil //In case when no networking config is needed set nil
var netConf *network.NetworkingConfig // In case when no networking config is needed, defaults to nil

Copilot uses AI. Check for mistakes.
var serverNetConfig = config.Get().Docker.Network
if "macvlan" == serverNetConfig.Driver { //Generate networking config for macvlan driver
var defaultMapping = ip.Server.Config().Allocations.DefaultMapping
ip.Server.Log().Debug("Set macvlan " + serverNetConfig.Name + " IP to " + defaultMapping.Ip)
Copy link

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use formatted logging (e.g., Debugf) instead of string concatenation for better readability and performance.

Suggested change
ip.Server.Log().Debug("Set macvlan " + serverNetConfig.Name + " IP to " + defaultMapping.Ip)
ip.Server.Log().Debugf("Set macvlan %s IP to %s", serverNetConfig.Name, defaultMapping.Ip)

Copilot uses AI. Check for mistakes.
netConf = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
serverNetConfig.Name: { //Get network name from wings config
IPAMConfig: &network.EndpointIPAMConfig{
IPv4Address: defaultMapping.Ip,
},
IPAddress: defaultMapping.Ip, //Use default mapping ip address (wings support only one network per server)
Gateway: serverNetConfig.Interfaces.V4.Gateway,
},
},
}
}
// Pass the networkings configuration or nil if none required
r, err := ip.client.ContainerCreate(ctx, conf, hostConf, netConf, nil, ip.Server.ID()+"_installer")
if err != nil {
return "", err
}
Expand Down
Loading