mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
watch: use official develop
section (#11026)
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
d322ad91e8
commit
805541be9d
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/Microsoft/go-winio v0.6.1
|
||||
github.com/adrg/xdg v0.4.0
|
||||
github.com/buger/goterm v1.0.4
|
||||
github.com/compose-spec/compose-go v1.18.4
|
||||
github.com/compose-spec/compose-go v1.19.0
|
||||
github.com/containerd/console v1.0.3
|
||||
github.com/containerd/containerd v1.7.6
|
||||
github.com/cucumber/godog v0.0.0-00010101000000-000000000000 // replaced; see replace for the actual version used
|
||||
|
4
go.sum
4
go.sum
@ -139,8 +139,8 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g
|
||||
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
|
||||
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
|
||||
github.com/compose-spec/compose-go v1.18.4 h1:yLYfsc3ATAYZVAJcXyx/V847/JVBmf3pfKfR13mXU4s=
|
||||
github.com/compose-spec/compose-go v1.18.4/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM=
|
||||
github.com/compose-spec/compose-go v1.19.0 h1:t68gAcwStDg0hy2kFvqHJIksf6xkqRnlSKfL45/ETqo=
|
||||
github.com/compose-spec/compose-go v1.19.0/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM=
|
||||
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
|
||||
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
|
||||
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
|
||||
|
@ -38,30 +38,12 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type DevelopmentConfig struct {
|
||||
Watch []Trigger `json:"watch,omitempty"`
|
||||
}
|
||||
|
||||
type WatchAction string
|
||||
|
||||
const (
|
||||
WatchActionSync WatchAction = "sync"
|
||||
WatchActionRebuild WatchAction = "rebuild"
|
||||
)
|
||||
|
||||
type Trigger struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
Action string `json:"action,omitempty"`
|
||||
Target string `json:"target,omitempty"`
|
||||
Ignore []string `json:"ignore,omitempty"`
|
||||
}
|
||||
|
||||
const quietPeriod = 500 * time.Millisecond
|
||||
|
||||
// fileEvent contains the Compose service and modified host system path.
|
||||
type fileEvent struct {
|
||||
sync.PathMapping
|
||||
Action WatchAction
|
||||
Action types.WatchAction
|
||||
}
|
||||
|
||||
// getSyncImplementation returns the the tar-based syncer unless it has been explicitly
|
||||
@ -95,6 +77,10 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
|
||||
return err
|
||||
}
|
||||
|
||||
if service.Develop != nil {
|
||||
config = service.Develop
|
||||
}
|
||||
|
||||
if config == nil {
|
||||
continue
|
||||
}
|
||||
@ -169,7 +155,7 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
|
||||
return eg.Wait()
|
||||
}
|
||||
|
||||
func (s *composeService) watch(ctx context.Context, project *types.Project, name string, options api.WatchOptions, watcher watch.Notify, syncer sync.Syncer, triggers []Trigger) error {
|
||||
func (s *composeService) watch(ctx context.Context, project *types.Project, name string, options api.WatchOptions, watcher watch.Notify, syncer sync.Syncer, triggers []types.Trigger) error {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
@ -223,7 +209,7 @@ func (s *composeService) watch(ctx context.Context, project *types.Project, name
|
||||
// rules.
|
||||
//
|
||||
// Any errors are logged as warnings and nil (no file event) is returned.
|
||||
func maybeFileEvent(trigger Trigger, hostPath string, ignore watch.PathMatcher) *fileEvent {
|
||||
func maybeFileEvent(trigger types.Trigger, hostPath string, ignore watch.PathMatcher) *fileEvent {
|
||||
if !watch.IsChild(trigger.Path, hostPath) {
|
||||
return nil
|
||||
}
|
||||
@ -250,7 +236,7 @@ func maybeFileEvent(trigger Trigger, hostPath string, ignore watch.PathMatcher)
|
||||
}
|
||||
|
||||
return &fileEvent{
|
||||
Action: WatchAction(trigger.Action),
|
||||
Action: trigger.Action,
|
||||
PathMapping: sync.PathMapping{
|
||||
HostPath: hostPath,
|
||||
ContainerPath: containerPath,
|
||||
@ -258,12 +244,13 @@ func maybeFileEvent(trigger Trigger, hostPath string, ignore watch.PathMatcher)
|
||||
}
|
||||
}
|
||||
|
||||
func loadDevelopmentConfig(service types.ServiceConfig, project *types.Project) (*DevelopmentConfig, error) {
|
||||
var config DevelopmentConfig
|
||||
func loadDevelopmentConfig(service types.ServiceConfig, project *types.Project) (*types.DevelopConfig, error) {
|
||||
var config types.DevelopConfig
|
||||
y, ok := service.Extensions["x-develop"]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
logrus.Warnf("x-develop is DEPRECATED, please use the official `develop` attribute")
|
||||
err := mapstructure.Decode(y, &config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -286,7 +273,7 @@ func loadDevelopmentConfig(service types.ServiceConfig, project *types.Project)
|
||||
return nil, errors.New("watch rules MUST define a path")
|
||||
}
|
||||
|
||||
if trigger.Action == string(WatchActionRebuild) && service.Build == nil {
|
||||
if trigger.Action == types.WatchActionRebuild && service.Build == nil {
|
||||
return nil, fmt.Errorf("service %s doesn't have a build section, can't apply 'rebuild' on watch", service.Name)
|
||||
}
|
||||
|
||||
@ -429,7 +416,7 @@ func (t tarDockerClient) Exec(ctx context.Context, containerID string, cmd []str
|
||||
func (s *composeService) handleWatchBatch(ctx context.Context, project *types.Project, serviceName string, build api.BuildOptions, batch []fileEvent, syncer sync.Syncer) error {
|
||||
pathMappings := make([]sync.PathMapping, len(batch))
|
||||
for i := range batch {
|
||||
if batch[i].Action == WatchActionRebuild {
|
||||
if batch[i].Action == types.WatchActionRebuild {
|
||||
fmt.Fprintf(
|
||||
s.stdinfo(),
|
||||
"Rebuilding %s after changes were detected:%s\n",
|
||||
|
@ -40,7 +40,7 @@ func TestDebounceBatching(t *testing.T) {
|
||||
|
||||
eventBatchCh := batchDebounceEvents(ctx, clock, quietPeriod, ch)
|
||||
for i := 0; i < 100; i++ {
|
||||
var action WatchAction = "a"
|
||||
var action types.WatchAction = "a"
|
||||
if i%2 == 0 {
|
||||
action = "b"
|
||||
}
|
||||
@ -124,7 +124,7 @@ func TestWatch_Sync(t *testing.T) {
|
||||
dockerCli: cli,
|
||||
clock: clock,
|
||||
}
|
||||
err := service.watch(ctx, &proj, "test", api.WatchOptions{}, watcher, syncer, []Trigger{
|
||||
err := service.watch(ctx, &proj, "test", api.WatchOptions{}, watcher, syncer, []types.Trigger{
|
||||
{
|
||||
Path: "/sync",
|
||||
Action: "sync",
|
||||
|
Loading…
x
Reference in New Issue
Block a user