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

Commit a1bc5c7

Browse files
committed
Filter out one_off containers on compose logs
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent f433fb8 commit a1bc5c7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

local/compose/labels.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package compose
1818

1919
import (
2020
"fmt"
21+
"strconv"
22+
"strings"
2123

2224
"github.com/docker/compose-cli/api/compose"
2325
"github.com/docker/docker/api/types/filters"
@@ -44,6 +46,10 @@ func projectFilter(projectName string) filters.KeyValuePair {
4446
return filters.Arg("label", fmt.Sprintf("%s=%s", projectLabel, projectName))
4547
}
4648

49+
func oneOffFilter(oneOff bool) filters.KeyValuePair {
50+
return filters.Arg("label", fmt.Sprintf("%s=%s", oneoffLabel, strings.Title(strconv.FormatBool(oneOff))))
51+
}
52+
4753
func serviceFilter(serviceName string) filters.KeyValuePair {
4854
return filters.Arg("label", fmt.Sprintf("%s=%s", serviceLabel, serviceName))
4955
}

local/compose/logs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
3333
list, err := s.apiClient.ContainerList(ctx, types.ContainerListOptions{
3434
Filters: filters.NewArgs(
3535
projectFilter(projectName),
36+
oneOffFilter(false),
3637
),
3738
All: true,
3839
})
@@ -72,7 +73,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
7273
if err != nil {
7374
return err
7475
}
75-
w := getWriter(service, container.ID, consumer)
76+
w := getWriter(service, container.Name[1:], consumer)
7677
if container.Config.Tty {
7778
_, err = io.Copy(w, r)
7879
} else {

0 commit comments

Comments
 (0)