mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Strip project prefix from docker-compose up output
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
c16943609c
commit
9c4efbdd92
@ -136,13 +136,14 @@ func getCanonicalContainerName(c moby.Container) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getContainerNameWithoutProject(c moby.Container) string {
|
func getContainerNameWithoutProject(c moby.Container) string {
|
||||||
name := getCanonicalContainerName(c)
|
|
||||||
project := c.Labels[api.ProjectLabel]
|
project := c.Labels[api.ProjectLabel]
|
||||||
prefix := fmt.Sprintf("%s_%s_", project, c.Labels[api.ServiceLabel])
|
defaultName := getDefaultContainerName(project, c.Labels[api.ServiceLabel], c.Labels[api.ContainerNumberLabel])
|
||||||
if strings.HasPrefix(name, prefix) {
|
name := getCanonicalContainerName(c)
|
||||||
return name[len(project)+1:]
|
if name != defaultName {
|
||||||
|
// service declares a custom container_name
|
||||||
|
return name
|
||||||
}
|
}
|
||||||
return name
|
return name[len(project)+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) Config(ctx context.Context, project *types.Project, options api.ConfigOptions) ([]byte, error) {
|
func (s *composeService) Config(ctx context.Context, project *types.Project, options api.ConfigOptions) ([]byte, error) {
|
||||||
|
@ -287,13 +287,17 @@ func mustRecreate(expected types.ServiceConfig, actual moby.Container, policy st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getContainerName(projectName string, service types.ServiceConfig, number int) string {
|
func getContainerName(projectName string, service types.ServiceConfig, number int) string {
|
||||||
name := strings.Join([]string{projectName, service.Name, strconv.Itoa(number)}, api.Separator)
|
name := getDefaultContainerName(projectName, service.Name, strconv.Itoa(number))
|
||||||
if service.ContainerName != "" {
|
if service.ContainerName != "" {
|
||||||
name = service.ContainerName
|
name = service.ContainerName
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDefaultContainerName(projectName, serviceName, index string) string {
|
||||||
|
return strings.Join([]string{projectName, serviceName, index}, api.Separator)
|
||||||
|
}
|
||||||
|
|
||||||
func getContainerProgressName(container moby.Container) string {
|
func getContainerProgressName(container moby.Container) string {
|
||||||
return "Container " + getCanonicalContainerName(container)
|
return "Container " + getCanonicalContainerName(container)
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ func TestBuildPlatformsWithCorrectBuildxConfig(t *testing.T) {
|
|||||||
t.Run("multi-arch up --build", func(t *testing.T) {
|
t.Run("multi-arch up --build", func(t *testing.T) {
|
||||||
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "up", "--build")
|
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "up", "--build")
|
||||||
assert.NilError(t, res.Error, res.Stderr())
|
assert.NilError(t, res.Error, res.Stderr())
|
||||||
res.Assert(t, icmd.Expected{Out: "platforms-platforms-1 exited with code 0"})
|
res.Assert(t, icmd.Expected{Out: "platforms-1 exited with code 0"})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("use DOCKER_DEFAULT_PLATFORM value when up --build", func(t *testing.T) {
|
t.Run("use DOCKER_DEFAULT_PLATFORM value when up --build", func(t *testing.T) {
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -75,18 +74,15 @@ func TestLocalComposeLogsFollow(t *testing.T) {
|
|||||||
_ = res.Cmd.Process.Kill()
|
_ = res.Cmd.Process.Kill()
|
||||||
})
|
})
|
||||||
|
|
||||||
expected := fmt.Sprintf("%s-ping-1 ", projectName)
|
poll.WaitOn(t, expectOutput(res, "ping-1 "), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(1*time.Second))
|
||||||
poll.WaitOn(t, expectOutput(res, expected), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(1*time.Second))
|
|
||||||
|
|
||||||
c.RunDockerComposeCmd(t, "-f", "./fixtures/logs-test/compose.yaml", "--project-name", projectName, "up", "-d")
|
c.RunDockerComposeCmd(t, "-f", "./fixtures/logs-test/compose.yaml", "--project-name", projectName, "up", "-d")
|
||||||
|
|
||||||
expected = fmt.Sprintf("%s-hello-1 ", projectName)
|
poll.WaitOn(t, expectOutput(res, "hello-1 "), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(1*time.Second))
|
||||||
poll.WaitOn(t, expectOutput(res, expected), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(1*time.Second))
|
|
||||||
|
|
||||||
c.RunDockerComposeCmd(t, "-f", "./fixtures/logs-test/compose.yaml", "--project-name", projectName, "up", "-d", "--scale", "ping=2", "ping")
|
c.RunDockerComposeCmd(t, "-f", "./fixtures/logs-test/compose.yaml", "--project-name", projectName, "up", "-d", "--scale", "ping=2", "ping")
|
||||||
|
|
||||||
expected = fmt.Sprintf("%s-ping-2 ", projectName)
|
poll.WaitOn(t, expectOutput(res, "ping-2 "), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(20*time.Second))
|
||||||
poll.WaitOn(t, expectOutput(res, expected), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(20*time.Second))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectOutput(res *icmd.Result, expected string) func(t poll.LogT) poll.Result {
|
func expectOutput(res *icmd.Result, expected string) func(t poll.LogT) poll.Result {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user