Skip to content

Commit 99b7d65

Browse files
committed
fix: connect clones to the DLE internal network (#240)
1 parent 151dd73 commit 99b7d65

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pkg/services/provision/databases/postgres/postgres.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Start(r runners.Runner, c *resources.AppConfig) error {
5151
}
5252
}
5353

54-
if _, err := docker.RunContainer(r, c); err != nil {
54+
if err := docker.RunContainer(r, c); err != nil {
5555
return errors.Wrap(err, "failed to run container")
5656
}
5757

pkg/services/provision/docker/docker.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ const (
2929
var systemVolumes = []string{"/sys", "/lib", "/proc"}
3030

3131
// RunContainer runs specified container.
32-
func RunContainer(r runners.Runner, c *resources.AppConfig) (string, error) {
32+
func RunContainer(r runners.Runner, c *resources.AppConfig) error {
3333
hostInfo, err := host.Info()
3434
if err != nil {
35-
return "", errors.Wrap(err, "failed to get host info")
35+
return errors.Wrap(err, "failed to get host info")
3636
}
3737

3838
// Directly mount PGDATA if Database Lab is running without any virtualization.
@@ -43,21 +43,22 @@ func RunContainer(r runners.Runner, c *resources.AppConfig) (string, error) {
4343
// We cannot use --volumes-from because it removes the ZFS mount point.
4444
volumes, err = getMountVolumes(r, c, hostInfo.Hostname)
4545
if err != nil {
46-
return "", errors.Wrap(err, "failed to detect container volumes")
46+
return errors.Wrap(err, "failed to detect container volumes")
4747
}
4848
}
4949

5050
unixSocketCloneDir := c.Pool.SocketCloneDir(c.CloneName)
5151

5252
if err := createSocketCloneDir(unixSocketCloneDir); err != nil {
53-
return "", errors.Wrap(err, "failed to create socket clone directory")
53+
return errors.Wrap(err, "failed to create socket clone directory")
5454
}
5555

5656
containerFlags := make([]string, 0, len(c.ContainerConf))
5757
for flagName, flagValue := range c.ContainerConf {
5858
containerFlags = append(containerFlags, fmt.Sprintf("--%s=%s", flagName, flagValue))
5959
}
6060

61+
// TODO (akartasov): use Docker client instead of command execution.
6162
instancePort := strconv.Itoa(int(c.Port))
6263
dockerRunCmd := strings.Join([]string{
6364
"docker run",
@@ -68,14 +69,23 @@ func RunContainer(r runners.Runner, c *resources.AppConfig) (string, error) {
6869
strings.Join(volumes, " "),
6970
"--label", labelClone,
7071
"--label", c.Pool.Name,
71-
"--network", c.NetworkID,
7272
strings.Join(containerFlags, " "),
7373
c.DockerImage,
7474
"-p", instancePort,
7575
"-k", unixSocketCloneDir,
7676
}, " ")
7777

78-
return r.Run(dockerRunCmd, true)
78+
if _, err := r.Run(dockerRunCmd, true); err != nil {
79+
return errors.Wrap(err, "failed to run command")
80+
}
81+
82+
dockerConnectCmd := strings.Join([]string{"docker network connect", c.NetworkID, c.CloneName}, " ")
83+
84+
if _, err := r.Run(dockerConnectCmd, true); err != nil {
85+
return errors.Wrap(err, "failed to connect container to the internal DLE network")
86+
}
87+
88+
return nil
7989
}
8090

8191
func getMountVolumes(r runners.Runner, c *resources.AppConfig, containerID string) ([]string, error) {

0 commit comments

Comments
 (0)