Rename dind container in windows provisioner to match names
This commit is contained in:
@@ -38,6 +38,7 @@ type DockerApi interface {
|
||||
GetPorts() ([]uint16, error)
|
||||
GetContainerStats(name string) (io.ReadCloser, error)
|
||||
ContainerResize(name string, rows, cols uint) error
|
||||
ContainerRename(old, new string) error
|
||||
CreateAttachConnection(name string) (net.Conn, error)
|
||||
CopyToContainer(containerName, destination, fileName string, content io.Reader) error
|
||||
DeleteContainer(id string) error
|
||||
@@ -164,6 +165,10 @@ func (d *docker) ContainerResize(name string, rows, cols uint) error {
|
||||
return d.c.ContainerResize(context.Background(), name, types.ResizeOptions{Height: rows, Width: cols})
|
||||
}
|
||||
|
||||
func (d *docker) ContainerRename(old, new string) error {
|
||||
return d.c.ContainerRename(context.Background(), old, new)
|
||||
}
|
||||
|
||||
func (d *docker) CreateAttachConnection(name string) (net.Conn, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -241,6 +246,7 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
|
||||
NetworkMode: container.NetworkMode(opts.SessionId),
|
||||
Privileged: opts.Privileged,
|
||||
AutoRemove: true,
|
||||
//PublishAllPorts: true,
|
||||
LogConfig: container.LogConfig{Config: map[string]string{"max-size": "10m", "max-file": "1"}},
|
||||
}
|
||||
|
||||
@@ -261,7 +267,8 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
|
||||
|
||||
env = append(env, fmt.Sprintf("PWD_IP_ADDRESS=%s", opts.PwdIpAddress))
|
||||
env = append(env, fmt.Sprintf("PWD_HOST_FQDN=%s", opts.HostFQDN))
|
||||
cf := &container.Config{Hostname: opts.Hostname,
|
||||
cf := &container.Config{
|
||||
Hostname: opts.Hostname,
|
||||
Image: opts.Image,
|
||||
Tty: true,
|
||||
OpenStdin: true,
|
||||
@@ -269,6 +276,12 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
Env: env,
|
||||
//ExposedPorts: nat.PortSet{
|
||||
//"2377": struct{}{},
|
||||
//"4789/udp": struct{}{},
|
||||
//"7946": struct{}{},
|
||||
//"7946/udp": struct{}{},
|
||||
//},
|
||||
}
|
||||
networkConf := &network.NetworkingConfig{
|
||||
map[string]*network.EndpointSettings{
|
||||
|
||||
@@ -54,7 +54,7 @@ func (f *localCachedFactory) GetForSession(sessionId string) (DockerApi, error)
|
||||
}
|
||||
|
||||
func (f *localCachedFactory) GetForInstance(instance *types.Instance) (DockerApi, error) {
|
||||
key := instance.SessionId + instance.Name
|
||||
key := instance.SessionId + instance.IP
|
||||
|
||||
f.irw.Lock()
|
||||
c, found := f.instanceClients[key]
|
||||
|
||||
@@ -50,6 +50,10 @@ func (m *Mock) ContainerResize(name string, rows, cols uint) error {
|
||||
args := m.Called(name, rows, cols)
|
||||
return args.Error(0)
|
||||
}
|
||||
func (m *Mock) ContainerRename(old, new string) error {
|
||||
args := m.Called(old, new)
|
||||
return args.Error(0)
|
||||
}
|
||||
func (m *Mock) CreateAttachConnection(name string) (net.Conn, error) {
|
||||
args := m.Called(name)
|
||||
return args.Get(0).(net.Conn), args.Error(1)
|
||||
|
||||
@@ -66,6 +66,7 @@ func (d *windows) InstanceNew(session *types.Session, conf types.InstanceConfig)
|
||||
}
|
||||
conf.Hostname = nodeName
|
||||
}
|
||||
|
||||
containerName := fmt.Sprintf("%s_%s", session.Id[:8], conf.Hostname)
|
||||
opts := docker.CreateContainerOpts{
|
||||
Image: conf.ImageName,
|
||||
@@ -94,9 +95,8 @@ func (d *windows) InstanceNew(session *types.Session, conf types.InstanceConfig)
|
||||
|
||||
instance := &types.Instance{}
|
||||
instance.Image = opts.Image
|
||||
instance.IP = winfo.publicIP
|
||||
instance.IP = winfo.privateIP
|
||||
instance.SessionId = session.Id
|
||||
instance.Name = containerName
|
||||
instance.WindowsId = winfo.id
|
||||
instance.Cert = conf.Cert
|
||||
instance.Key = conf.Key
|
||||
@@ -120,6 +120,11 @@ func (d *windows) InstanceNew(session *types.Session, conf types.InstanceConfig)
|
||||
return nil, err
|
||||
}
|
||||
instance.Hostname = info.Name
|
||||
instance.Name = fmt.Sprintf("%s_%s", session.Id[:8], info.Name)
|
||||
if err = dockerClient.ContainerRename(containerName, instance.Name); err != nil {
|
||||
d.InstanceDelete(session, instance)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return instance, nil
|
||||
|
||||
Reference in New Issue
Block a user