@@ -38,30 +38,12 @@ import (
38
38
"golang.org/x/sync/errgroup"
39
39
)
40
40
41
- type DevelopmentConfig struct {
42
- Watch []Trigger `json:"watch,omitempty"`
43
- }
44
-
45
- type WatchAction string
46
-
47
- const (
48
- WatchActionSync WatchAction = "sync"
49
- WatchActionRebuild WatchAction = "rebuild"
50
- )
51
-
52
- type Trigger struct {
53
- Path string `json:"path,omitempty"`
54
- Action string `json:"action,omitempty"`
55
- Target string `json:"target,omitempty"`
56
- Ignore []string `json:"ignore,omitempty"`
57
- }
58
-
59
41
const quietPeriod = 500 * time .Millisecond
60
42
61
43
// fileEvent contains the Compose service and modified host system path.
62
44
type fileEvent struct {
63
45
sync.PathMapping
64
- Action WatchAction
46
+ Action types. WatchAction
65
47
}
66
48
67
49
// 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
95
77
return err
96
78
}
97
79
80
+ if service .Develop != nil {
81
+ config = service .Develop
82
+ }
83
+
98
84
if config == nil {
99
85
continue
100
86
}
@@ -169,7 +155,7 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
169
155
return eg .Wait ()
170
156
}
171
157
172
- func (s * composeService ) watch (ctx context.Context , project * types.Project , name string , options api.WatchOptions , watcher watch.Notify , syncer sync.Syncer , triggers []Trigger ) error {
158
+ 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 {
173
159
ctx , cancel := context .WithCancel (ctx )
174
160
defer cancel ()
175
161
@@ -223,7 +209,7 @@ func (s *composeService) watch(ctx context.Context, project *types.Project, name
223
209
// rules.
224
210
//
225
211
// Any errors are logged as warnings and nil (no file event) is returned.
226
- func maybeFileEvent (trigger Trigger , hostPath string , ignore watch.PathMatcher ) * fileEvent {
212
+ func maybeFileEvent (trigger types. Trigger , hostPath string , ignore watch.PathMatcher ) * fileEvent {
227
213
if ! watch .IsChild (trigger .Path , hostPath ) {
228
214
return nil
229
215
}
@@ -250,20 +236,21 @@ func maybeFileEvent(trigger Trigger, hostPath string, ignore watch.PathMatcher)
250
236
}
251
237
252
238
return & fileEvent {
253
- Action : WatchAction ( trigger .Action ) ,
239
+ Action : trigger .Action ,
254
240
PathMapping : sync.PathMapping {
255
241
HostPath : hostPath ,
256
242
ContainerPath : containerPath ,
257
243
},
258
244
}
259
245
}
260
246
261
- func loadDevelopmentConfig (service types.ServiceConfig , project * types.Project ) (* DevelopmentConfig , error ) {
262
- var config DevelopmentConfig
247
+ func loadDevelopmentConfig (service types.ServiceConfig , project * types.Project ) (* types. DevelopConfig , error ) {
248
+ var config types. DevelopConfig
263
249
y , ok := service .Extensions ["x-develop" ]
264
250
if ! ok {
265
251
return nil , nil
266
252
}
253
+ logrus .Warnf ("x-develop is DEPRECATED, please use the official `develop` attribute" )
267
254
err := mapstructure .Decode (y , & config )
268
255
if err != nil {
269
256
return nil , err
@@ -286,7 +273,7 @@ func loadDevelopmentConfig(service types.ServiceConfig, project *types.Project)
286
273
return nil , errors .New ("watch rules MUST define a path" )
287
274
}
288
275
289
- if trigger .Action == string ( WatchActionRebuild ) && service .Build == nil {
276
+ if trigger .Action == types . WatchActionRebuild && service .Build == nil {
290
277
return nil , fmt .Errorf ("service %s doesn't have a build section, can't apply 'rebuild' on watch" , service .Name )
291
278
}
292
279
@@ -429,7 +416,7 @@ func (t tarDockerClient) Exec(ctx context.Context, containerID string, cmd []str
429
416
func (s * composeService ) handleWatchBatch (ctx context.Context , project * types.Project , serviceName string , build api.BuildOptions , batch []fileEvent , syncer sync.Syncer ) error {
430
417
pathMappings := make ([]sync.PathMapping , len (batch ))
431
418
for i := range batch {
432
- if batch [i ].Action == WatchActionRebuild {
419
+ if batch [i ].Action == types . WatchActionRebuild {
433
420
fmt .Fprintf (
434
421
s .stdinfo (),
435
422
"Rebuilding %s after changes were detected:%s\n " ,
0 commit comments