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