Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support specifying service name for compose pull/push #621

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions cmd/nerdctl/compose_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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)
}
64 changes: 64 additions & 0 deletions cmd/nerdctl/compose_pull_linux_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
11 changes: 2 additions & 9 deletions cmd/nerdctl/compose_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/composer/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/composer/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down