diff --git a/cmd/compose/up.go b/cmd/compose/up.go index 9eb25485533..2b0810950f1 100644 --- a/cmd/compose/up.go +++ b/cmd/compose/up.go @@ -21,9 +21,8 @@ import ( "fmt" "time" - "github.com/docker/compose/v2/cmd/formatter" - "github.com/compose-spec/compose-go/types" + "github.com/docker/compose/v2/cmd/formatter" "github.com/spf13/cobra" "github.com/docker/compose/v2/pkg/api" @@ -164,15 +163,29 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create consumer = formatter.NewLogConsumer(ctx, streams.Out(), streams.Err(), !upOptions.noColor, !upOptions.noPrefix, upOptions.timestamp) } - attachTo := services + var attachTo []string if len(upOptions.attach) > 0 { attachTo = upOptions.attach } if upOptions.attachDependencies { - attachTo = project.ServiceNames() + if err = project.WithServices(attachTo, func(s types.ServiceConfig) error { + if s.Attach == nil || *s.Attach { + attachTo = append(attachTo, s.Name) + } + return nil + }); err != nil { + return err + } } if len(attachTo) == 0 { - attachTo = project.ServiceNames() + if err = project.WithServices(services, func(s types.ServiceConfig) error { + if s.Attach == nil || *s.Attach { + attachTo = append(attachTo, s.Name) + } + return nil + }); err != nil { + return err + } } attachTo = utils.Remove(attachTo, upOptions.noAttach...) diff --git a/go.mod b/go.mod index d23085172ff..26029827391 100644 --- a/go.mod +++ b/go.mod @@ -99,7 +99,7 @@ require ( github.com/hashicorp/go-memdb v1.3.2 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/imdario/mergo v0.3.15 // indirect + github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jinzhu/gorm v1.9.11 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -177,6 +177,8 @@ require ( ) replace ( + github.com/compose-spec/compose-go => github.com/ndeloof/compose-go v1.2.4-0.20230613093636-c5056633935d + // Override for e2e tests github.com/cucumber/godog => github.com/laurazard/godog v0.0.0-20220922095256-4c4b17abdae7 diff --git a/go.sum b/go.sum index b369cd62698..fe74bab5672 100644 --- a/go.sum +++ b/go.sum @@ -159,8 +159,6 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/compose-spec/compose-go v1.14.0 h1:/+tQxBEPIrfsi87Qh7/VjMzcJN3BRNER/RO71ku+u6E= -github.com/compose-spec/compose-go v1.14.0/go.mod h1:m0o4G6MQDHjjz9rY7No9FpnNi+9sKic262rzrwuCqic= github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= @@ -439,8 +437,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= -github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= +github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= +github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/in-toto/in-toto-golang v0.5.0 h1:hb8bgwr0M2hGdDsLjkJ3ZqJ8JFLL/tgYdAxF/XEFBbY= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -560,6 +558,8 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/ndeloof/compose-go v1.2.4-0.20230613093636-c5056633935d h1:uSlBk/j+hVAjK5fxbaj5o3sNaUjrXZ2s65ZxB6ZW/5s= +github.com/ndeloof/compose-go v1.2.4-0.20230613093636-c5056633935d/go.mod h1:lPCPZqX4eyq6f+6U9z08YslKtlPowrcUwh1EJOYpmQE= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=