Skip to content

Commit fd954f2

Browse files
ndeloofglours
authored andcommitted
show build progress during watch rebuild
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent d62e210 commit fd954f2

File tree

9 files changed

+35
-10
lines changed

9 files changed

+35
-10
lines changed

cmd/compose/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func buildCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
121121
}
122122
flags := cmd.Flags()
123123
flags.BoolVar(&opts.push, "push", false, "Push service images")
124-
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Don't print anything to STDOUT")
124+
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress the build output")
125125
flags.BoolVar(&opts.pull, "pull", false, "Always attempt to pull a newer version of the image")
126126
flags.StringArrayVar(&opts.args, "build-arg", []string{}, "Set build-time variables for services")
127127
flags.StringVar(&opts.ssh, "ssh", "", "Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent)")

cmd/compose/up.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
165165
flags.BoolVar(&create.recreateDeps, "always-recreate-deps", false, "Recreate dependent containers. Incompatible with --no-recreate.")
166166
flags.BoolVarP(&create.noInherit, "renew-anon-volumes", "V", false, "Recreate anonymous volumes instead of retrieving data from the previous containers")
167167
flags.BoolVar(&create.quietPull, "quiet-pull", false, "Pull without printing progress information")
168+
flags.BoolVar(&build.quiet, "quiet-build", false, "Suppress the build output")
168169
flags.StringArrayVar(&up.attach, "attach", []string{}, "Restrict attaching to the specified services. Incompatible with --attach-dependencies.")
169170
flags.StringArrayVar(&up.noAttach, "no-attach", []string{}, "Do not attach (stream logs) to the specified services")
170171
flags.BoolVar(&up.attachDependencies, "attach-dependencies", false, "Automatically attach to log output of dependent services")

docs/reference/compose_build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ run `docker compose build` to rebuild it.
2525
| `--provenance` | `string` | | Add a provenance attestation |
2626
| `--pull` | `bool` | | Always attempt to pull a newer version of the image |
2727
| `--push` | `bool` | | Push service images |
28-
| `-q`, `--quiet` | `bool` | | Don't print anything to STDOUT |
28+
| `-q`, `--quiet` | `bool` | | Suppress the build output |
2929
| `--sbom` | `string` | | Add a SBOM attestation |
3030
| `--ssh` | `string` | | Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent) |
3131
| `--with-dependencies` | `bool` | | Also build dependencies (transitively) |

docs/reference/compose_up.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ If the process is interrupted using `SIGINT` (ctrl + C) or `SIGTERM`, the contai
4444
| `--no-recreate` | `bool` | | If containers already exist, don't recreate them. Incompatible with --force-recreate. |
4545
| `--no-start` | `bool` | | Don't start the services after creating them |
4646
| `--pull` | `string` | `policy` | Pull image before running ("always"\|"missing"\|"never") |
47+
| `--quiet-build` | `bool` | | Suppress the build output |
4748
| `--quiet-pull` | `bool` | | Pull without printing progress information |
4849
| `--remove-orphans` | `bool` | | Remove containers for services not defined in the Compose file |
4950
| `-V`, `--renew-anon-volumes` | `bool` | | Recreate anonymous volumes instead of retrieving data from the previous containers |

docs/reference/docker_compose_build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ options:
158158
shorthand: q
159159
value_type: bool
160160
default_value: "false"
161-
description: Don't print anything to STDOUT
161+
description: Suppress the build output
162162
deprecated: false
163163
hidden: false
164164
experimental: false

docs/reference/docker_compose_up.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ options:
211211
experimentalcli: false
212212
kubernetes: false
213213
swarm: false
214+
- option: quiet-build
215+
value_type: bool
216+
default_value: "false"
217+
description: Suppress the build output
218+
deprecated: false
219+
hidden: false
220+
experimental: false
221+
experimentalcli: false
222+
kubernetes: false
223+
swarm: false
214224
- option: quiet-pull
215225
value_type: bool
216226
default_value: "false"

pkg/api/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package api
1919
import (
2020
"context"
2121
"fmt"
22+
"io"
2223
"slices"
2324
"strings"
2425
"time"
@@ -176,6 +177,8 @@ type BuildOptions struct {
176177
Provenance string
177178
// SBOM generate a SBOM attestation
178179
SBOM string
180+
// Out is the stream to write build progress
181+
Out io.Writer
179182
}
180183

181184
// Apply mutates project according to build options

pkg/compose/build_bake.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ type buildStatus struct {
130130
func (s *composeService) doBuildBake(ctx context.Context, project *types.Project, serviceToBeBuild types.Services, options api.BuildOptions) (map[string]string, error) { //nolint:gocyclo
131131
eg := errgroup.Group{}
132132
ch := make(chan *client.SolveStatus)
133-
out := s.dockerCli.Out()
134133
displayMode := progressui.DisplayMode(options.Progress)
135-
if !out.IsTerminal() {
136-
displayMode = progressui.PlainMode
134+
out := options.Out
135+
if out == nil {
136+
cout := s.dockerCli.Out()
137+
if !cout.IsTerminal() {
138+
displayMode = progressui.PlainMode
139+
}
140+
out = cout
137141
}
138142
display, err := progressui.NewDisplay(out, displayMode)
139143
if err != nil {

pkg/compose/watch.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ import (
2929
gsync "sync"
3030
"time"
3131

32-
"github.com/compose-spec/compose-go/v2/types"
33-
"github.com/compose-spec/compose-go/v2/utils"
34-
ccli "github.com/docker/cli/cli/command/container"
3532
pathutil "github.com/docker/compose/v2/internal/paths"
3633
"github.com/docker/compose/v2/internal/sync"
3734
"github.com/docker/compose/v2/internal/tracing"
3835
"github.com/docker/compose/v2/pkg/api"
36+
"github.com/docker/compose/v2/pkg/progress"
37+
cutils "github.com/docker/compose/v2/pkg/utils"
3938
"github.com/docker/compose/v2/pkg/watch"
39+
40+
"github.com/compose-spec/compose-go/v2/types"
41+
"github.com/compose-spec/compose-go/v2/utils"
42+
ccli "github.com/docker/cli/cli/command/container"
4043
"github.com/docker/docker/api/types/container"
4144
"github.com/docker/docker/api/types/filters"
4245
"github.com/docker/docker/api/types/image"
@@ -61,7 +64,6 @@ func NewWatcher(project *types.Project, options api.UpOptions, w WatchFunc, cons
6164

6265
if service.Develop != nil && service.Develop.Watch != nil {
6366
build := options.Create.Build
64-
build.Quiet = true
6567
return &Watcher{
6668
project: project,
6769
options: api.WatchOptions{
@@ -598,6 +600,10 @@ func (s *composeService) rebuild(ctx context.Context, project *types.Project, se
598600
options.LogTo.Log(api.WatchLogger, fmt.Sprintf("Rebuilding service(s) %q after changes were detected...", services))
599601
// restrict the build to ONLY this service, not any of its dependencies
600602
options.Build.Services = services
603+
options.Build.Progress = progress.ModePlain
604+
options.Build.Out = cutils.GetWriter(func(line string) {
605+
options.LogTo.Log(api.WatchLogger, line)
606+
})
601607

602608
var (
603609
imageNameToIdMap map[string]string

0 commit comments

Comments
 (0)