diff --git a/cmd/nerdctl/compose_pull.go b/cmd/nerdctl/compose_pull.go index a643204c6c6..e04ae4b98de 100644 --- a/cmd/nerdctl/compose_pull.go +++ b/cmd/nerdctl/compose_pull.go @@ -17,15 +17,13 @@ package main import ( - "fmt" - "github.com/containerd/nerdctl/pkg/composer" "github.com/spf13/cobra" ) func newComposePullCommand() *cobra.Command { var composePullCommand = &cobra.Command{ - Use: "pull [SERVICE]...", + Use: "pull [SERVICE...]", Short: "Pull service images", RunE: composePullAction, SilenceUsage: true, @@ -36,11 +34,6 @@ func newComposePullCommand() *cobra.Command { } func composePullAction(cmd *cobra.Command, args []string) error { - if len(args) != 0 { - // TODO: support specifying service names as args - return fmt.Errorf("arguments %v not supported", args) - } - client, ctx, cancel, err := newClient(cmd) if err != nil { return err @@ -58,5 +51,5 @@ func composePullAction(cmd *cobra.Command, args []string) error { po := composer.PullOptions{ Quiet: quiet, } - return c.Pull(ctx, po) + return c.Pull(ctx, po, args) } diff --git a/cmd/nerdctl/compose_pull_linux_test.go b/cmd/nerdctl/compose_pull_linux_test.go new file mode 100644 index 00000000000..be974462319 --- /dev/null +++ b/cmd/nerdctl/compose_pull_linux_test.go @@ -0,0 +1,64 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package main + +import ( + "fmt" + "testing" + + "github.com/containerd/nerdctl/pkg/testutil" +) + +func TestComposePullWithService(t *testing.T) { + base := testutil.NewBase(t) + var dockerComposeYAML = fmt.Sprintf(` +version: '3.1' + +services: + + wordpress: + image: %s + ports: + - 8080:80 + environment: + WORDPRESS_DB_HOST: db + WORDPRESS_DB_USER: exampleuser + WORDPRESS_DB_PASSWORD: examplepass + WORDPRESS_DB_NAME: exampledb + volumes: + - wordpress:/var/www/html + + db: + image: %s + environment: + MYSQL_DATABASE: exampledb + MYSQL_USER: exampleuser + MYSQL_PASSWORD: examplepass + MYSQL_RANDOM_ROOT_PASSWORD: '1' + volumes: + - db:/var/lib/mysql + +volumes: + wordpress: + db: +`, testutil.WordpressImage, testutil.MariaDBImage) + + comp := testutil.NewComposeDir(t, dockerComposeYAML) + defer comp.CleanUp() + + base.ComposeCmd("-f", comp.YAMLFullPath(), "pull", "db").AssertNoOut("wordpress") +} diff --git a/cmd/nerdctl/compose_push.go b/cmd/nerdctl/compose_push.go index b036da09f2e..816798dabee 100644 --- a/cmd/nerdctl/compose_push.go +++ b/cmd/nerdctl/compose_push.go @@ -17,15 +17,13 @@ package main import ( - "fmt" - "github.com/containerd/nerdctl/pkg/composer" "github.com/spf13/cobra" ) func newComposePushCommand() *cobra.Command { var composePushCommand = &cobra.Command{ - Use: "push [SERVICE]...", + Use: "push [SERVICE...]", Short: "Push service images", RunE: composePushAction, SilenceUsage: true, @@ -35,11 +33,6 @@ func newComposePushCommand() *cobra.Command { } func composePushAction(cmd *cobra.Command, args []string) error { - if len(args) != 0 { - // TODO: support specifying service names as args - return fmt.Errorf("arguments %v not supported", args) - } - client, ctx, cancel, err := newClient(cmd) if err != nil { return err @@ -51,5 +44,5 @@ func composePushAction(cmd *cobra.Command, args []string) error { return err } po := composer.PushOptions{} - return c.Push(ctx, po) + return c.Push(ctx, po, args) } diff --git a/pkg/composer/pull.go b/pkg/composer/pull.go index aac1dbbafe2..897565add04 100644 --- a/pkg/composer/pull.go +++ b/pkg/composer/pull.go @@ -31,8 +31,8 @@ type PullOptions struct { Quiet bool } -func (c *Composer) Pull(ctx context.Context, po PullOptions) error { - return c.project.WithServices(nil, func(svc types.ServiceConfig) error { +func (c *Composer) Pull(ctx context.Context, po PullOptions, services []string) error { + return c.project.WithServices(services, func(svc types.ServiceConfig) error { ps, err := serviceparser.Parse(c.project, svc) if err != nil { return err diff --git a/pkg/composer/push.go b/pkg/composer/push.go index 9a19639b064..6c4597d68d2 100644 --- a/pkg/composer/push.go +++ b/pkg/composer/push.go @@ -30,8 +30,8 @@ import ( type PushOptions struct { } -func (c *Composer) Push(ctx context.Context, po PushOptions) error { - return c.project.WithServices(nil, func(svc types.ServiceConfig) error { +func (c *Composer) Push(ctx context.Context, po PushOptions, services []string) error { + return c.project.WithServices(services, func(svc types.ServiceConfig) error { ps, err := serviceparser.Parse(c.project, svc) if err != nil { return err