mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Filter out one_off containers on compose logs
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
f433fb89d1
commit
a1bc5c721d
@ -18,6 +18,8 @@ package compose
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
@ -44,6 +46,10 @@ func projectFilter(projectName string) filters.KeyValuePair {
|
|||||||
return filters.Arg("label", fmt.Sprintf("%s=%s", projectLabel, projectName))
|
return filters.Arg("label", fmt.Sprintf("%s=%s", projectLabel, projectName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func oneOffFilter(oneOff bool) filters.KeyValuePair {
|
||||||
|
return filters.Arg("label", fmt.Sprintf("%s=%s", oneoffLabel, strings.Title(strconv.FormatBool(oneOff))))
|
||||||
|
}
|
||||||
|
|
||||||
func serviceFilter(serviceName string) filters.KeyValuePair {
|
func serviceFilter(serviceName string) filters.KeyValuePair {
|
||||||
return filters.Arg("label", fmt.Sprintf("%s=%s", serviceLabel, serviceName))
|
return filters.Arg("label", fmt.Sprintf("%s=%s", serviceLabel, serviceName))
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
|
|||||||
list, err := s.apiClient.ContainerList(ctx, types.ContainerListOptions{
|
list, err := s.apiClient.ContainerList(ctx, types.ContainerListOptions{
|
||||||
Filters: filters.NewArgs(
|
Filters: filters.NewArgs(
|
||||||
projectFilter(projectName),
|
projectFilter(projectName),
|
||||||
|
oneOffFilter(false),
|
||||||
),
|
),
|
||||||
All: true,
|
All: true,
|
||||||
})
|
})
|
||||||
@ -72,7 +73,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := getWriter(service, container.ID, consumer)
|
w := getWriter(service, container.Name[1:], consumer)
|
||||||
if container.Config.Tty {
|
if container.Config.Tty {
|
||||||
_, err = io.Copy(w, r)
|
_, err = io.Copy(w, r)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user