@@ -49,7 +49,7 @@ type Trigger struct {
49
49
50
50
const quietPeriod = 2 * time .Second
51
51
52
- func (s * composeService ) Watch (ctx context.Context , project * types.Project , services []string , options api.WatchOptions ) error {
52
+ func (s * composeService ) Watch (ctx context.Context , project * types.Project , services []string , options api.WatchOptions ) error { //nolint:gocyclo
53
53
needRebuild := make (chan string )
54
54
needSync := make (chan api.CopyOptions , 5 )
55
55
@@ -62,27 +62,37 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
62
62
63
63
eg .Go (s .makeSyncFn (ctx , project , needSync ))
64
64
65
- err := project .WithServices (services , func (service types.ServiceConfig ) error {
65
+ ss , err := project .GetServices (services ... )
66
+ if err != nil {
67
+ return err
68
+ }
69
+ for _ , service := range ss {
66
70
config , err := loadDevelopmentConfig (service , project )
67
71
if err != nil {
68
72
return err
69
73
}
74
+ name := service .Name
70
75
if service .Build == nil {
71
- return errors .New ("can't watch a service without a build section" )
76
+ if len (services ) != 0 || len (config .Watch ) != 0 {
77
+ // watch explicitly requested on service, but no build section set
78
+ return fmt .Errorf ("service %s doesn't have a build section" , name )
79
+ }
80
+ logrus .Infof ("service %s ignored. Can't watch a service without a build section" , name )
81
+ continue
72
82
}
73
- context := service .Build .Context
83
+ bc := service .Build .Context
74
84
75
- ignore , err := watch .LoadDockerIgnore (context )
85
+ ignore , err := watch .LoadDockerIgnore (bc )
76
86
if err != nil {
77
87
return err
78
88
}
79
89
80
- watcher , err := watch .NewWatcher ([]string {context }, ignore )
90
+ watcher , err := watch .NewWatcher ([]string {bc }, ignore )
81
91
if err != nil {
82
92
return err
83
93
}
84
94
85
- fmt .Fprintf (s .stderr (), "watching %s\n " , context )
95
+ fmt .Fprintf (s .stderr (), "watching %s\n " , bc )
86
96
err = watcher .Start ()
87
97
if err != nil {
88
98
return err
@@ -113,11 +123,11 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
113
123
dest := filepath .Join (trigger .Target , rel )
114
124
needSync <- api.CopyOptions {
115
125
Source : path ,
116
- Destination : fmt .Sprintf ("%s:%s" , service . Name , dest ),
126
+ Destination : fmt .Sprintf ("%s:%s" , name , dest ),
117
127
}
118
128
case WatchActionRebuild :
119
129
logrus .Debugf ("modified file %s require image to be rebuilt" , path )
120
- needRebuild <- service . Name
130
+ needRebuild <- name
121
131
default :
122
132
return fmt .Errorf ("watch action %q is not supported" , trigger )
123
133
}
@@ -126,17 +136,13 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
126
136
}
127
137
128
138
// default
129
- needRebuild <- service . Name
139
+ needRebuild <- name
130
140
131
141
case err := <- watcher .Errors ():
132
142
return err
133
143
}
134
144
}
135
145
})
136
- return nil
137
- })
138
- if err != nil {
139
- return err
140
146
}
141
147
142
148
return eg .Wait ()
0 commit comments