mirror of https://github.com/docker/compose.git
Merge pull request #10620 from ndeloof/Building
do not render `Building` when no build is needed
This commit is contained in:
commit
32cf776ecd
|
@ -68,6 +68,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
||||||
// build and will lock
|
// build and will lock
|
||||||
progressCtx, cancel := context.WithCancel(context.Background())
|
progressCtx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
w, err := xprogress.NewPrinter(progressCtx, s.stdout(), os.Stdout, options.Progress)
|
w, err := xprogress.NewPrinter(progressCtx, s.stdout(), os.Stdout, options.Progress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -175,20 +176,24 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
||||||
mode = xprogress.PrinterModeQuiet
|
mode = xprogress.PrinterModeQuiet
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.prepareProjectForBuild(project, images)
|
buildRequired, err := s.prepareProjectForBuild(project, images)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
builtImages, err := s.build(ctx, project, api.BuildOptions{
|
|
||||||
Progress: mode,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, digest := range builtImages {
|
if buildRequired {
|
||||||
images[name] = digest
|
builtImages, err := s.build(ctx, project, api.BuildOptions{
|
||||||
|
Progress: mode,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, digest := range builtImages {
|
||||||
|
images[name] = digest
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set digest as com.docker.compose.image label so we can detect outdated containers
|
// set digest as com.docker.compose.image label so we can detect outdated containers
|
||||||
for i, service := range project.Services {
|
for i, service := range project.Services {
|
||||||
image := api.GetImageNameOrDefault(service, project.Name)
|
image := api.GetImageNameOrDefault(service, project.Name)
|
||||||
|
@ -203,10 +208,11 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) prepareProjectForBuild(project *types.Project, images map[string]string) error {
|
func (s *composeService) prepareProjectForBuild(project *types.Project, images map[string]string) (bool, error) {
|
||||||
|
buildRequired := false
|
||||||
err := api.BuildOptions{}.Apply(project)
|
err := api.BuildOptions{}.Apply(project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
for i, service := range project.Services {
|
for i, service := range project.Services {
|
||||||
if service.Build == nil {
|
if service.Build == nil {
|
||||||
|
@ -227,8 +233,9 @@ func (s *composeService) prepareProjectForBuild(project *types.Project, images m
|
||||||
service.Build.Platforms = []string{service.Platform}
|
service.Build.Platforms = []string{service.Platform}
|
||||||
}
|
}
|
||||||
project.Services[i] = service
|
project.Services[i] = service
|
||||||
|
buildRequired = true
|
||||||
}
|
}
|
||||||
return nil
|
return buildRequired, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) getLocalImagesDigests(ctx context.Context, project *types.Project) (map[string]string, error) {
|
func (s *composeService) getLocalImagesDigests(ctx context.Context, project *types.Project) (map[string]string, error) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ func TestPrepareProjectForBuild(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &composeService{}
|
s := &composeService{}
|
||||||
err := s.prepareProjectForBuild(&project, nil)
|
_, err := s.prepareProjectForBuild(&project, nil)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.DeepEqual(t, project.Services[0].Build.Platforms, types.StringList{"alice/32"})
|
assert.DeepEqual(t, project.Services[0].Build.Platforms, types.StringList{"alice/32"})
|
||||||
})
|
})
|
||||||
|
@ -70,7 +70,7 @@ func TestPrepareProjectForBuild(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &composeService{}
|
s := &composeService{}
|
||||||
err := s.prepareProjectForBuild(&project, nil)
|
_, err := s.prepareProjectForBuild(&project, nil)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.DeepEqual(t, project.Services[0].Build.Platforms, types.StringList{"linux/amd64"})
|
assert.DeepEqual(t, project.Services[0].Build.Platforms, types.StringList{"linux/amd64"})
|
||||||
})
|
})
|
||||||
|
@ -89,7 +89,7 @@ func TestPrepareProjectForBuild(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &composeService{}
|
s := &composeService{}
|
||||||
err := s.prepareProjectForBuild(&project, map[string]string{"foo": "exists"})
|
_, err := s.prepareProjectForBuild(&project, map[string]string{"foo": "exists"})
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, project.Services[0].Build == nil)
|
assert.Check(t, project.Services[0].Build == nil)
|
||||||
})
|
})
|
||||||
|
@ -115,7 +115,7 @@ func TestPrepareProjectForBuild(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &composeService{}
|
s := &composeService{}
|
||||||
err := s.prepareProjectForBuild(&project, nil)
|
_, err := s.prepareProjectForBuild(&project, nil)
|
||||||
assert.Check(t, err != nil)
|
assert.Check(t, err != nil)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
|
||||||
needRebuild := make(chan fileMapping)
|
needRebuild := make(chan fileMapping)
|
||||||
needSync := make(chan fileMapping)
|
needSync := make(chan fileMapping)
|
||||||
|
|
||||||
err := s.prepareProjectForBuild(project, nil)
|
_, err := s.prepareProjectForBuild(project, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue