Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit b6df84f

Browse files
authored
Merge pull request #1433 from docker/container_name_without_project
2 parents 0108cc5 + 949e8bb commit b6df84f

File tree

15 files changed

+57
-63
lines changed

15 files changed

+57
-63
lines changed

api/compose/api.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,22 +314,21 @@ type Stack struct {
314314

315315
// LogConsumer is a callback to process log messages from services
316316
type LogConsumer interface {
317-
Log(name, service, container, message string)
318-
Status(name, container, msg string)
319-
Register(name string, source string)
317+
Log(service, container, message string)
318+
Status(container, msg string)
319+
Register(container string)
320320
}
321321

322322
// ContainerEventListener is a callback to process ContainerEvent from services
323323
type ContainerEventListener func(event ContainerEvent)
324324

325-
// ContainerEvent notify an event has been collected on Source container implementing Service
325+
// ContainerEvent notify an event has been collected on source container implementing Service
326326
type ContainerEvent struct {
327-
Type int
328-
Source string
329-
Service string
330-
Name string
331-
Line string
332-
ExitCode int
327+
Type int
328+
Container string
329+
Service string
330+
Line string
331+
ExitCode int
333332
}
334333

335334
const (

cli/cmd/compose/up.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ func (p printer) run(ctx context.Context, cascadeStop bool, exitCodeFrom string,
399399
case compose.UserCancel:
400400
aborting = true
401401
case compose.ContainerEventAttach:
402-
consumer.Register(event.Name, event.Source)
402+
consumer.Register(event.Container)
403403
count++
404404
case compose.ContainerEventExit:
405405
if !aborting {
406-
consumer.Status(event.Name, event.Source, fmt.Sprintf("exited with code %d", event.ExitCode))
406+
consumer.Status(event.Container, fmt.Sprintf("exited with code %d", event.ExitCode))
407407
}
408408
if cascadeStop {
409409
if !aborting {
@@ -426,7 +426,7 @@ func (p printer) run(ctx context.Context, cascadeStop bool, exitCodeFrom string,
426426
}
427427
case compose.ContainerEventLog:
428428
if !aborting {
429-
consumer.Log(event.Name, event.Service, event.Source, event.Line)
429+
consumer.Log(event.Container, event.Service, event.Line)
430430
}
431431
}
432432
}

cli/formatter/logs.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ func NewLogConsumer(ctx context.Context, w io.Writer, color bool, prefix bool) c
3838
}
3939
}
4040

41-
func (l *logConsumer) Register(name string, id string) {
42-
l.register(name, id)
41+
func (l *logConsumer) Register(name string) {
42+
l.register(name)
4343
}
4444

45-
func (l *logConsumer) register(name string, id string) *presenter {
45+
func (l *logConsumer) register(name string) *presenter {
4646
cf := monochrome
4747
if l.color {
4848
cf = nextColor()
@@ -51,7 +51,7 @@ func (l *logConsumer) register(name string, id string) *presenter {
5151
colors: cf,
5252
name: name,
5353
}
54-
l.presenters[id] = p
54+
l.presenters[name] = p
5555
if l.prefix {
5656
l.computeWidth()
5757
for _, p := range l.presenters {
@@ -62,25 +62,25 @@ func (l *logConsumer) register(name string, id string) *presenter {
6262
}
6363

6464
// Log formats a log message as received from name/container
65-
func (l *logConsumer) Log(name, service, container, message string) {
65+
func (l *logConsumer) Log(container, service, message string) {
6666
if l.ctx.Err() != nil {
6767
return
6868
}
6969
p, ok := l.presenters[container]
7070
if !ok { // should have been registered, but ¯\_(ツ)_/¯
71-
p = l.register(name, container)
71+
p = l.register(container)
7272
}
7373
for _, line := range strings.Split(message, "\n") {
7474
fmt.Fprintf(l.writer, "%s %s\n", p.prefix, line) // nolint:errcheck
7575
}
7676
}
7777

78-
func (l *logConsumer) Status(name, id, msg string) {
79-
p, ok := l.presenters[id]
78+
func (l *logConsumer) Status(container, msg string) {
79+
p, ok := l.presenters[container]
8080
if !ok {
81-
p = l.register(name, id)
81+
p = l.register(container)
8282
}
83-
s := p.colors(fmt.Sprintf("%s %s\n", name, msg))
83+
s := p.colors(fmt.Sprintf("%s %s\n", container, msg))
8484
l.writer.Write([]byte(s)) // nolint:errcheck
8585
}
8686

ecs/aws.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type API interface {
6363
InspectSecret(ctx context.Context, id string) (secrets.Secret, error)
6464
ListSecrets(ctx context.Context) ([]secrets.Secret, error)
6565
DeleteSecret(ctx context.Context, id string, recover bool) error
66-
GetLogs(ctx context.Context, name string, consumer func(name string, service string, container string, message string), follow bool) error
66+
GetLogs(ctx context.Context, name string, consumer func(container string, service string, message string), follow bool) error
6767
DescribeService(ctx context.Context, cluster string, arn string) (compose.ServiceStatus, error)
6868
DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]compose.ContainerSummary, error)
6969
getURLWithPortMapping(ctx context.Context, targetGroupArns []string) ([]compose.PortPublisher, error)

ecs/aws_mock.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs/sdk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ func (s sdk) DeleteSecret(ctx context.Context, id string, recover bool) error {
805805
return err
806806
}
807807

808-
func (s sdk) GetLogs(ctx context.Context, name string, consumer func(name string, service string, container string, message string), follow bool) error {
808+
func (s sdk) GetLogs(ctx context.Context, name string, consumer func(container string, service string, message string), follow bool) error {
809809
logGroup := fmt.Sprintf("/docker-compose/%s", name)
810810
var startTime int64
811811
for {
@@ -832,7 +832,7 @@ func (s sdk) GetLogs(ctx context.Context, name string, consumer func(name string
832832

833833
for _, event := range events.Events {
834834
p := strings.Split(aws.StringValue(event.LogStreamName), "/")
835-
consumer(p[1], p[1], p[2], aws.StringValue(event.Message))
835+
consumer(p[1], p[2], aws.StringValue(event.Message))
836836
startTime = *event.IngestionTime
837837
}
838838
}

kube/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer
9696
for _, pod := range pods.Items {
9797
request := kc.client.CoreV1().Pods(kc.namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Follow: follow})
9898
service := pod.Labels[compose.ServiceTag]
99-
w := utils.GetWriter(pod.Name, service, string(pod.UID), func(event compose.ContainerEvent) {
100-
consumer.Log(event.Name, event.Service, event.Source, event.Line)
99+
w := utils.GetWriter(pod.Name, service, func(event compose.ContainerEvent) {
100+
consumer.Log(event.Container, event.Service, event.Line)
101101
})
102102

103103
eg.Go(func() error {

local/compose/attach.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
4141

4242
var names []string
4343
for _, c := range containers {
44-
names = append(names, getCanonicalContainerName(c))
44+
names = append(names, getContainerNameWithoutProject(c))
4545
}
4646

4747
fmt.Printf("Attaching to %s\n", strings.Join(names, ", "))
@@ -95,18 +95,17 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
9595

9696
func (s *composeService) attachContainer(ctx context.Context, container moby.Container, listener compose.ContainerEventListener, project *types.Project) error {
9797
serviceName := container.Labels[serviceLabel]
98-
w := utils.GetWriter(getContainerNameWithoutProject(container), serviceName, container.ID, listener)
98+
w := utils.GetWriter(getContainerNameWithoutProject(container), serviceName, listener)
9999

100100
service, err := project.GetService(serviceName)
101101
if err != nil {
102102
return err
103103
}
104104

105105
listener(compose.ContainerEvent{
106-
Type: compose.ContainerEventAttach,
107-
Source: container.ID,
108-
Name: getContainerNameWithoutProject(container),
109-
Service: container.Labels[serviceLabel],
106+
Type: compose.ContainerEventAttach,
107+
Container: getContainerNameWithoutProject(container),
108+
Service: container.Labels[serviceLabel],
110109
})
111110

112111
return s.attachContainerStreams(ctx, container.ID, service.Tty, nil, w)

local/compose/logs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
7676
return err
7777
}
7878
name := getContainerNameWithoutProject(c)
79-
w := utils.GetWriter(name, service, c.ID, func(event compose.ContainerEvent) {
80-
consumer.Log(name, event.Service, event.Name, event.Line)
79+
w := utils.GetWriter(name, service, func(event compose.ContainerEvent) {
80+
consumer.Log(name, service, event.Line)
8181
})
8282
if container.Config.Tty {
8383
_, err = io.Copy(w, r)

local/compose/start.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,14 @@ func (s *composeService) Start(ctx context.Context, project *types.Project, opti
5959

6060
func (s *composeService) waitContainer(ctx context.Context, c moby.Container, listener compose.ContainerEventListener) {
6161
statusC, errC := s.apiClient.ContainerWait(ctx, c.ID, container.WaitConditionNotRunning)
62-
name := getCanonicalContainerName(c)
62+
name := getContainerNameWithoutProject(c)
6363
select {
6464
case status := <-statusC:
6565
listener(compose.ContainerEvent{
66-
Type: compose.ContainerEventExit,
67-
Source: c.ID,
68-
Name: name,
69-
Service: c.Labels[serviceLabel],
70-
ExitCode: int(status.StatusCode),
66+
Type: compose.ContainerEventExit,
67+
Container: name,
68+
Service: c.Labels[serviceLabel],
69+
ExitCode: int(status.StatusCode),
7170
})
7271
case err := <-errC:
7372
logrus.Warnf("Unexpected API error for %s : %s", name, err.Error())

0 commit comments

Comments
 (0)