connect to external networks by name

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2024-10-25 10:21:54 +02:00 коммит произвёл Nicolas De loof
Родитель a4ee6ca7a5
Коммит aa1ec4524c
2 изменённых файлов: 2 добавлений и 5 удалений

Просмотреть файл

@ -1363,7 +1363,6 @@ func (s *composeService) resolveExternalNetwork(ctx context.Context, n *types.Ne
switch len(networks) {
case 1:
n.Name = networks[0].ID
return nil
case 0:
enabled, err := s.isSWarmEnabled(ctx)

Просмотреть файл

@ -99,9 +99,8 @@ func TestRebuildOnDotEnvWithExternalNetwork(t *testing.T) {
errors)
}, 30*time.Second, 1*time.Second)
n := c.RunDockerCmd(t, "network", "inspect", networkName, "-f", "{{ .Id }}")
pn := c.RunDockerCmd(t, "inspect", containerName, "-f", "{{ .HostConfig.NetworkMode }}")
assert.Equal(t, pn.Stdout(), n.Stdout())
assert.Equal(t, strings.TrimSpace(pn.Stdout()), networkName)
t.Log("create a dotenv file that will be used to trigger the rebuild")
err = os.WriteFile(dotEnvFilepath, []byte("HELLO=WORLD\nTEST=REBUILD"), 0o666)
@ -119,9 +118,8 @@ func TestRebuildOnDotEnvWithExternalNetwork(t *testing.T) {
return true, fmt.Sprintf("container %s was rebuilt", containerName)
}, 30*time.Second, 1*time.Second)
n2 := c.RunDockerCmd(t, "network", "inspect", networkName, "-f", "{{ .Id }}")
pn2 := c.RunDockerCmd(t, "inspect", containerName, "-f", "{{ .HostConfig.NetworkMode }}")
assert.Equal(t, pn2.Stdout(), n2.Stdout())
assert.Equal(t, strings.TrimSpace(pn2.Stdout()), networkName)
assert.Check(t, !strings.Contains(r.Combined(), "Application failed to start after update"))