From e441fbba5a6b185d2f6fd62ac4f719793dd80b2a Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Thu, 26 Nov 2020 15:45:17 +0100 Subject: [PATCH] Add compose labels for network Signed-off-by: Guillaume Tardif --- local/compose.go | 3 +++ local/e2e/compose_test.go | 26 +++++++++++++++++++++++--- local/labels.go | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/local/compose.go b/local/compose.go index 5b2595533..a666be7f8 100644 --- a/local/compose.go +++ b/local/compose.go @@ -55,6 +55,9 @@ func (s *local) Up(ctx context.Context, project *types.Project, detach bool) err network.Name = fmt.Sprintf("%s_%s", project.Name, k) project.Networks[k] = network } + network.Labels = network.Labels.Add(networkLabel, k) + network.Labels = network.Labels.Add(projectLabel, project.Name) + network.Labels = network.Labels.Add(versionLabel, ComposeVersion) err := s.ensureNetwork(ctx, network) if err != nil { return err diff --git a/local/e2e/compose_test.go b/local/e2e/compose_test.go index d7cf202ba..0bba3e857 100644 --- a/local/e2e/compose_test.go +++ b/local/e2e/compose_test.go @@ -37,9 +37,12 @@ func TestLocalBackendComposeUp(t *testing.T) { t.Run("up", func(t *testing.T) { c.RunDockerCmd("compose", "up", "-f", "../../tests/composefiles/demo_multi_port.yaml", "--project-name", projectName) - t.Cleanup(func() { - _ = c.RunDockerCmd("compose", "down", "--project-name", projectName) - }) + }) + t.Cleanup(func() { + _ = c.RunDockerCmd("compose", "down", "--project-name", projectName) + }) + + t.Run("check running project", func(t *testing.T) { res := c.RunDockerCmd("compose", "ps", "-p", projectName) res.Assert(t, icmd.Expected{Out: `web`}) @@ -47,4 +50,21 @@ func TestLocalBackendComposeUp(t *testing.T) { output := HTTPGetWithRetry(t, endpoint+"/words/noun", http.StatusOK, 2*time.Second, 20*time.Second) assert.Assert(t, strings.Contains(output, `"word":`)) }) + + t.Run("check compose labels", func(t *testing.T) { + res := c.RunDockerCmd("--context", "default", "inspect", projectName+"_web_1") + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.container-number": "1"`}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project": "compose-e2e-demo"`}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.oneoff": "False",`}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.config-hash":`}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project.config_files":`}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project.working_dir":`}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.service": "web"`}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.version":`}) + + res = c.RunDockerCmd("--context", "default", "network", "inspect", projectName+"_default") + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.network": "default"`}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project": `}) + res.Assert(t, icmd.Expected{Out: `"com.docker.compose.version": `}) + }) } diff --git a/local/labels.go b/local/labels.go index 876482b90..318ac633e 100644 --- a/local/labels.go +++ b/local/labels.go @@ -33,6 +33,7 @@ const ( serviceLabel = "com.docker.compose.service" versionLabel = "com.docker.compose.version" configHashLabel = "com.docker.compose.config-hash" + networkLabel = "com.docker.compose.network" //ComposeVersion Compose version ComposeVersion = "1.0-alpha"