Add DNS support for PWD instances (#94)
* Add DNS support for PWD instances * Store IP address of PWD in all session networks and restore it with the same IP address * Remove unnecesary print * Change url format to pwd<ip>-port for better DNS filtering * Make PWD listen on 80 and 443 for DNS resolve to work
This commit is contained in:
committed by
GitHub
parent
9c4df837a8
commit
f816be6f69
@@ -135,17 +135,33 @@ func CreateNetwork(name string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
func ConnectNetwork(containerId, networkId string) error {
|
||||
err := c.NetworkConnect(context.Background(), networkId, containerId, &network.EndpointSettings{})
|
||||
func ConnectNetwork(containerId, networkId, ip string) (string, error) {
|
||||
settings := &network.EndpointSettings{}
|
||||
if ip != "" {
|
||||
settings.IPAddress = ip
|
||||
}
|
||||
err := c.NetworkConnect(context.Background(), networkId, containerId, settings)
|
||||
|
||||
if err != nil && !strings.Contains(err.Error(), "already exists") {
|
||||
log.Printf("Connection container to network err [%s]\n", err)
|
||||
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
return nil
|
||||
// Obtain the IP of the PWD container in this network
|
||||
container, err := c.ContainerInspect(context.Background(), containerId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
n, found := container.NetworkSettings.Networks[networkId]
|
||||
if !found {
|
||||
return "", fmt.Errorf("Container [%s] connected to the network [%s] but couldn't obtain it's IP address", containerId, networkId)
|
||||
}
|
||||
|
||||
return n.IPAddress, nil
|
||||
}
|
||||
|
||||
func DisconnectNetwork(containerId, networkId string) error {
|
||||
err := c.NetworkDisconnect(context.Background(), networkId, containerId, true)
|
||||
|
||||
@@ -217,7 +233,15 @@ func CreateInstance(session *Session, dindImage string) (*Instance, error) {
|
||||
break
|
||||
}
|
||||
}
|
||||
conf := &container.Config{Hostname: nodeName, Image: dindImage, Tty: true, OpenStdin: true, AttachStdin: true, AttachStdout: true, AttachStderr: true}
|
||||
conf := &container.Config{Hostname: nodeName,
|
||||
Image: dindImage,
|
||||
Tty: true,
|
||||
OpenStdin: true,
|
||||
AttachStdin: true,
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
Env: []string{fmt.Sprintf("PWD_IP_ADDRESS=%s", session.PwdIpAddress)},
|
||||
}
|
||||
networkConf := &network.NetworkingConfig{
|
||||
map[string]*network.EndpointSettings{
|
||||
session.Id: &network.EndpointSettings{Aliases: []string{nodeName}},
|
||||
|
||||
Reference in New Issue
Block a user