Explorar el Código

support compose build --pull

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof hace 4 años
padre
commit
6f73007265
Se han modificado 8 ficheros con 24 adiciones y 10 borrados
  1. 1 1
      aci/compose.go
  2. 1 1
      api/client/compose.go
  3. 7 1
      api/compose/api.go
  4. 6 1
      cli/cmd/compose/build.go
  5. 2 2
      ecs/local/compose.go
  6. 1 1
      ecs/up.go
  7. 1 1
      kube/compose.go
  8. 5 2
      local/compose/build.go

+ 1 - 1
aci/compose.go

@@ -44,7 +44,7 @@ func newComposeService(ctx store.AciContext) aciComposeService {
 	}
 }
 
-func (cs *aciComposeService) Build(ctx context.Context, project *types.Project) error {
+func (cs *aciComposeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error {
 	return errdefs.ErrNotImplemented
 }
 

+ 1 - 1
api/client/compose.go

@@ -28,7 +28,7 @@ import (
 type composeService struct {
 }
 
-func (c *composeService) Build(ctx context.Context, project *types.Project) error {
+func (c *composeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error {
 	return errdefs.ErrNotImplemented
 }
 

+ 7 - 1
api/compose/api.go

@@ -28,7 +28,7 @@ import (
 // Service manages a compose project
 type Service interface {
 	// Build executes the equivalent to a `compose build`
-	Build(ctx context.Context, project *types.Project) error
+	Build(ctx context.Context, project *types.Project, options BuildOptions) error
 	// Push executes the equivalent ot a `compose push`
 	Push(ctx context.Context, project *types.Project) error
 	// Pull executes the equivalent of a `compose pull`
@@ -65,6 +65,12 @@ type Service interface {
 	UnPause(ctx context.Context, project *types.Project) error
 }
 
+// BuildOptions group options of the Build API
+type BuildOptions struct {
+	// Pull always attempt to pull a newer version of the image
+	Pull bool
+}
+
 // CreateOptions group options of the Create API
 type CreateOptions struct {
 	// Remove legacy containers for services that are not defined in the project

+ 6 - 1
cli/cmd/compose/build.go

@@ -18,6 +18,7 @@ package compose
 
 import (
 	"context"
+	"github.com/docker/compose-cli/api/compose"
 	"os"
 
 	"github.com/spf13/cobra"
@@ -30,6 +31,7 @@ type buildOptions struct {
 	*projectOptions
 	composeOptions
 	quiet bool
+	pull  bool
 }
 
 func buildCommand(p *projectOptions) *cobra.Command {
@@ -51,6 +53,7 @@ func buildCommand(p *projectOptions) *cobra.Command {
 		},
 	}
 	cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Don't print anything to STDOUT")
+	cmd.Flags().BoolVar(&opts.pull, "pull", false, "Always attempt to pull a newer version of the image.")
 	return cmd
 }
 
@@ -66,7 +69,9 @@ func runBuild(ctx context.Context, opts buildOptions, services []string) error {
 	}
 
 	_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
-		return "", c.ComposeService().Build(ctx, project)
+		return "", c.ComposeService().Build(ctx, project, compose.BuildOptions{
+			Pull: opts.pull,
+		})
 	})
 	return err
 }

+ 2 - 2
ecs/local/compose.go

@@ -32,8 +32,8 @@ import (
 	"github.com/docker/compose-cli/api/errdefs"
 )
 
-func (e ecsLocalSimulation) Build(ctx context.Context, project *types.Project) error {
-	return e.compose.Build(ctx, project)
+func (e ecsLocalSimulation) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error {
+	return e.compose.Build(ctx, project, options)
 }
 
 func (e ecsLocalSimulation) Push(ctx context.Context, project *types.Project) error {

+ 1 - 1
ecs/up.go

@@ -31,7 +31,7 @@ import (
 	"github.com/compose-spec/compose-go/types"
 )
 
-func (b *ecsAPIService) Build(ctx context.Context, project *types.Project) error {
+func (b *ecsAPIService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error {
 	return errdefs.ErrNotImplemented
 }
 

+ 1 - 1
kube/compose.go

@@ -124,7 +124,7 @@ func (s *composeService) List(ctx context.Context, opts compose.ListOptions) ([]
 }
 
 // Build executes the equivalent to a `compose build`
-func (s *composeService) Build(ctx context.Context, project *types.Project) error {
+func (s *composeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error {
 	return errdefs.ErrNotImplemented
 }
 

+ 5 - 2
local/compose/build.go

@@ -19,6 +19,7 @@ package compose
 import (
 	"context"
 	"fmt"
+	"github.com/docker/compose-cli/api/compose"
 	"os"
 	"path"
 	"strings"
@@ -32,14 +33,16 @@ import (
 	bclient "github.com/moby/buildkit/client"
 )
 
-func (s *composeService) Build(ctx context.Context, project *types.Project) error {
+func (s *composeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error {
 	opts := map[string]build.Options{}
 	imagesToBuild := []string{}
 	for _, service := range project.Services {
 		if service.Build != nil {
 			imageName := getImageName(service, project.Name)
 			imagesToBuild = append(imagesToBuild, imageName)
-			opts[imageName] = s.toBuildOptions(service, project.WorkingDir, imageName)
+			buildOptions := s.toBuildOptions(service, project.WorkingDir, imageName)
+			buildOptions.Pull = options.Pull
+			opts[imageName] = buildOptions
 		}
 	}