Skip to content

Commit bb9cf32

Browse files
committed
introduce experimental watch command (skeletton)
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 7212aaf commit bb9cf32

File tree

14 files changed

+293
-21
lines changed

14 files changed

+293
-21
lines changed

cmd/compose/alpha.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
3+
Copyright 2020 Docker Compose CLI authors
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
package compose
16+
17+
import (
18+
"github.com/docker/compose/v2/pkg/api"
19+
"github.com/spf13/cobra"
20+
)
21+
22+
// alphaCommand groups all experimental subcommands
23+
func alphaCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
24+
cmd := &cobra.Command{
25+
Short: "Experimental commands",
26+
Use: "alpha [COMMAND]",
27+
Hidden: true,
28+
}
29+
cmd.AddCommand(watchCommand(p, backend))
30+
return cmd
31+
}

cmd/compose/compose.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ func RootCommand(streams api.Streams, backend api.Service) *cobra.Command { //no
365365
pullCommand(&opts, backend),
366366
createCommand(&opts, backend),
367367
copyCommand(&opts, backend),
368+
alphaCommand(&opts, backend),
368369
)
370+
369371
c.Flags().SetInterspersed(false)
370372
opts.addProjectFlags(c.Flags())
371373
c.RegisterFlagCompletionFunc( //nolint:errcheck

cmd/compose/watch.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package compose
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"os"
23+
24+
"github.com/docker/compose/v2/pkg/api"
25+
"github.com/spf13/cobra"
26+
)
27+
28+
type watchOptions struct {
29+
*ProjectOptions
30+
quiet bool
31+
}
32+
33+
func watchCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
34+
opts := watchOptions{
35+
ProjectOptions: p,
36+
}
37+
cmd := &cobra.Command{
38+
Use: "watch [SERVICE...]",
39+
Short: "EXPERIMENTAL - Watch build context for service and rebuild/refresh containers when files are updated",
40+
PreRunE: Adapt(func(ctx context.Context, args []string) error {
41+
return nil
42+
}),
43+
RunE: Adapt(func(ctx context.Context, args []string) error {
44+
return runWatch(ctx, backend, opts, args)
45+
}),
46+
ValidArgsFunction: completeServiceNames(p),
47+
}
48+
49+
cmd.Flags().BoolVar(&opts.quiet, "quiet", false, "hide build output")
50+
return cmd
51+
}
52+
53+
func runWatch(ctx context.Context, backend api.Service, opts watchOptions, services []string) error {
54+
fmt.Fprintln(os.Stderr, "watch command is EXPERIMENTAL")
55+
project, err := opts.ToProject(nil)
56+
if err != nil {
57+
return err
58+
}
59+
60+
return backend.Watch(ctx, project, services, api.WatchOptions{})
61+
}

docs/reference/compose.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Docker Compose
77

88
| Name | Description |
99
|:--------------------------------|:------------------------------------------------------------------------|
10+
| [`alpha`](compose_alpha.md) | Experimental commands |
1011
| [`build`](compose_build.md) | Build or rebuild services |
1112
| [`convert`](compose_convert.md) | Converts the compose file to platform's canonical format |
1213
| [`cp`](compose_cp.md) | Copy files/folders between a service container and the local filesystem |

docs/reference/compose_alpha.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# docker compose alpha
2+
3+
<!---MARKER_GEN_START-->
4+
Experimental commands
5+
6+
### Subcommands
7+
8+
| Name | Description |
9+
|:----------------------------------|:-----------------------------------------------------------------------------------------------------|
10+
| [`watch`](compose_alpha_watch.md) | EXPERIMENTAL - Watch build context for service and rebuild/refresh containers when files are updated |
11+
12+
13+
14+
<!---MARKER_GEN_END-->
15+

docs/reference/compose_alpha_watch.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# docker compose alpha watch
2+
3+
<!---MARKER_GEN_START-->
4+
EXPERIMENTAL - Watch build context for service and rebuild/refresh containers when files are updated
5+
6+
### Options
7+
8+
| Name | Type | Default | Description |
9+
|:----------|:-----|:--------|:------------------|
10+
| `--quiet` | | | hide build output |
11+
12+
13+
<!---MARKER_GEN_END-->
14+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
command: docker compose alpha
2+
short: Experimental commands
3+
long: Experimental commands
4+
pname: docker compose
5+
plink: docker_compose.yaml
6+
cname:
7+
- docker compose alpha watch
8+
clink:
9+
- docker_compose_alpha_watch.yaml
10+
deprecated: false
11+
experimental: false
12+
experimentalcli: false
13+
kubernetes: false
14+
swarm: false
15+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
command: docker compose alpha watch
2+
short: |
3+
EXPERIMENTAL - Watch build context for service and rebuild/refresh containers when files are updated
4+
long: |
5+
EXPERIMENTAL - Watch build context for service and rebuild/refresh containers when files are updated
6+
usage: docker compose alpha watch [SERVICE...]
7+
pname: docker compose alpha
8+
plink: docker_compose_alpha.yaml
9+
options:
10+
- option: quiet
11+
value_type: bool
12+
default_value: "false"
13+
description: hide build output
14+
deprecated: false
15+
hidden: false
16+
experimental: false
17+
experimentalcli: false
18+
kubernetes: false
19+
swarm: false
20+
deprecated: false
21+
experimental: false
22+
experimentalcli: false
23+
kubernetes: false
24+
swarm: false
25+

go.mod

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ require (
88
github.com/compose-spec/compose-go v1.8.2
99
github.com/containerd/console v1.0.3
1010
github.com/containerd/containerd v1.6.15
11+
github.com/cucumber/godog v0.0.0-00010101000000-000000000000
1112
github.com/distribution/distribution/v3 v3.0.0-20221201083218-92d136e113cf
1213
github.com/docker/buildx v0.9.1 // when updating, also update the replace rules accordingly
1314
github.com/docker/cli v20.10.20+incompatible // replaced; see replace rule for actual version
1415
github.com/docker/cli-docs-tool v0.5.1
1516
github.com/docker/docker v20.10.20+incompatible // replaced; see replace rule for actual version
1617
github.com/docker/go-connections v0.4.0
1718
github.com/docker/go-units v0.5.0
19+
github.com/fsnotify/fsnotify v1.6.0
1820
github.com/golang/mock v1.6.0
1921
github.com/hashicorp/go-multierror v1.1.1
2022
github.com/hashicorp/go-version v1.6.0
21-
github.com/mattn/go-isatty v0.0.16 // indirect
2223
github.com/mattn/go-shellwords v1.0.12
24+
github.com/mitchellh/mapstructure v1.5.0
2325
github.com/moby/buildkit v0.10.4 // replaced; see replace rule for actual version
2426
github.com/moby/term v0.0.0-20221128092401-c43b287e0e0f
2527
github.com/morikuni/aec v1.0.0
@@ -42,11 +44,15 @@ require (
4244
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
4345
github.com/Microsoft/go-winio v0.5.2 // indirect
4446
github.com/beorn7/perks v1.0.1 // indirect
47+
github.com/bugsnag/bugsnag-go v1.5.0 // indirect
4548
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
4649
github.com/cespare/xxhash/v2 v2.1.2 // indirect
50+
github.com/cloudflare/cfssl v1.4.1 // indirect
4751
github.com/containerd/continuity v0.3.0 // indirect
4852
github.com/containerd/ttrpc v1.1.0 // indirect
4953
github.com/containerd/typeurl v1.0.2 // indirect
54+
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
55+
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
5056
github.com/davecgh/go-spew v1.1.1 // indirect
5157
github.com/docker/distribution v2.8.1+incompatible // indirect
5258
github.com/docker/docker-credential-helpers v0.7.0 // indirect
@@ -57,6 +63,7 @@ require (
5763
github.com/go-logr/logr v1.2.3 // indirect
5864
github.com/go-logr/stdr v1.2.2 // indirect
5965
github.com/gofrs/flock v0.8.0 // indirect
66+
github.com/gofrs/uuid v4.2.0+incompatible // indirect
6067
github.com/gogo/googleapis v1.4.1 // indirect
6168
github.com/gogo/protobuf v1.3.2 // indirect
6269
github.com/golang/protobuf v1.5.2 // indirect
@@ -68,17 +75,21 @@ require (
6875
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
6976
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
7077
github.com/hashicorp/errwrap v1.1.0 // indirect
78+
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
79+
github.com/hashicorp/go-memdb v1.3.2 // indirect
80+
github.com/hashicorp/golang-lru v0.5.4 // indirect
7181
github.com/imdario/mergo v0.3.13 // indirect
7282
github.com/inconshreveable/mousetrap v1.0.1 // indirect
83+
github.com/jinzhu/gorm v1.9.11 // indirect
7384
github.com/json-iterator/go v1.1.12 // indirect
7485
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
7586
github.com/klauspost/compress v1.15.9 // indirect
7687
github.com/mattn/go-colorable v0.1.12 // indirect
88+
github.com/mattn/go-isatty v0.0.16 // indirect
7789
github.com/mattn/go-runewidth v0.0.14 // indirect
7890
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
7991
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
8092
github.com/miekg/pkcs11 v1.1.1 // indirect
81-
github.com/mitchellh/mapstructure v1.5.0 // indirect
8293
github.com/moby/locker v1.0.1 // indirect
8394
github.com/moby/patternmatcher v0.5.0 // indirect
8495
github.com/moby/spdystream v0.2.0 // indirect
@@ -96,6 +107,7 @@ require (
96107
github.com/prometheus/procfs v0.7.3 // indirect
97108
github.com/rivo/uniseg v0.2.0 // indirect
98109
github.com/serialx/hashring v0.0.0-20190422032157-8b2912629002 // indirect
110+
github.com/spf13/viper v1.4.0 // indirect
99111
github.com/tonistiigi/fsutil v0.0.0-20220930225714-4638ad635be5 // indirect
100112
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect
101113
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f // indirect
@@ -119,7 +131,7 @@ require (
119131
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect
120132
golang.org/x/net v0.4.0 // indirect
121133
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
122-
golang.org/x/sys v0.3.0 // indirect
134+
golang.org/x/sys v0.4.0 // indirect
123135
golang.org/x/term v0.3.0 // indirect
124136
golang.org/x/text v0.6.0 // indirect
125137
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
@@ -137,21 +149,6 @@ require (
137149
sigs.k8s.io/yaml v1.2.0 // indirect
138150
)
139151

140-
require github.com/cucumber/godog v0.0.0-00010101000000-000000000000
141-
142-
require (
143-
github.com/bugsnag/bugsnag-go v1.5.0 // indirect
144-
github.com/cloudflare/cfssl v1.4.1 // indirect
145-
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
146-
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
147-
github.com/gofrs/uuid v4.2.0+incompatible // indirect
148-
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
149-
github.com/hashicorp/go-memdb v1.3.2 // indirect
150-
github.com/hashicorp/golang-lru v0.5.4 // indirect
151-
github.com/jinzhu/gorm v1.9.11 // indirect
152-
github.com/spf13/viper v1.4.0 // indirect
153-
)
154-
155152
replace (
156153
// Override for e2e tests
157154
github.com/cucumber/godog => github.com/laurazard/godog v0.0.0-20220922095256-4c4b17abdae7

go.sum

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD
206206
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
207207
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
208208
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
209-
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
210209
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
210+
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
211+
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
211212
github.com/fvbommel/sortorder v1.0.2 h1:mV4o8B2hKboCdkJm+a7uX/SIpZob4JzUpc5GGnM45eo=
212213
github.com/fvbommel/sortorder v1.0.2/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
213214
github.com/getsentry/raven-go v0.0.0-20180121060056-563b81fc02b7/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
@@ -903,8 +904,9 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
903904
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
904905
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
905906
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
906-
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
907-
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
907+
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
908+
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
909+
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
908910
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
909911
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
910912
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

0 commit comments

Comments
 (0)