1
1
package internal
2
2
3
3
import (
4
- "context"
5
4
"fmt"
6
- "io"
7
5
"os"
8
6
"path/filepath"
9
7
"strings"
@@ -81,47 +79,7 @@ type Service interface {
81
79
}
82
80
83
81
type ServiceReady interface {
84
- Ready (ouservice * service ) error
85
- }
86
-
87
- func (m * Manifest ) CompleteReady () error {
88
- for _ , s := range m .services {
89
- if readyFn , ok := s .component .(ServiceReady ); ok {
90
- if err := readyFn .Ready (s ); err != nil {
91
- return err
92
- }
93
- }
94
- }
95
- return nil
96
- }
97
-
98
- type ServiceWatchdog interface {
99
- Watchdog (out io.Writer , service * service , ctx context.Context ) error
100
- }
101
-
102
- func RunWatchdog (manifest * Manifest ) error {
103
- watchdogErr := make (chan error , len (manifest .Services ()))
104
-
105
- output , err := manifest .out .LogOutput ("watchdog" )
106
- if err != nil {
107
- return fmt .Errorf ("failed to create log output: %w" , err )
108
- }
109
-
110
- for _ , s := range manifest .Services () {
111
- if watchdogFn , ok := s .component .(ServiceWatchdog ); ok {
112
- go func () {
113
- if err := watchdogFn .Watchdog (output , s , context .Background ()); err != nil {
114
- watchdogErr <- fmt .Errorf ("service %s watchdog failed: %w" , s .Name , err )
115
- }
116
- }()
117
- }
118
- }
119
-
120
- // If any of the watchdogs fail, we return the error
121
- if err := <- watchdogErr ; err != nil {
122
- return fmt .Errorf ("failed to run watchdog: %w" , err )
123
- }
124
- return nil
82
+ Ready (instance * instance ) error
125
83
}
126
84
127
85
func (s * Manifest ) Services () []* service {
@@ -135,7 +93,7 @@ type ReleaseService interface {
135
93
136
94
func (s * Manifest ) AddService (name string , srv Service ) {
137
95
service := s .NewService (name )
138
- service .component = srv
96
+ service .componentName = srv . Name ()
139
97
srv .Run (service , s .ctx )
140
98
141
99
s .services = append (s .services , service )
@@ -191,21 +149,17 @@ func (s *Manifest) Validate() error {
191
149
}
192
150
}
193
151
194
- // download any local release artifacts for the services that require them
152
+ // validate that the mounts are correct
195
153
for _ , ss := range s .services {
196
- if ss .labels [useHostExecutionLabel ] == "true" {
197
- // If the service wants to run on the host, it must implement the ReleaseService interface
198
- // which provides functions to download the release artifact.
199
- releaseService , ok := ss .component .(ReleaseService )
200
- if ! ok {
201
- return fmt .Errorf ("service '%s' must implement the ReleaseService interface" , ss .Name )
202
- }
203
- releaseArtifact := releaseService .ReleaseArtifact ()
204
- bin , err := DownloadRelease (s .out .homeDir , releaseArtifact )
205
- if err != nil {
206
- return fmt .Errorf ("failed to download release artifact for service '%s': %w" , ss .Name , err )
154
+ for _ , fileNameRef := range ss .filesMapped {
155
+ fileLoc := filepath .Join (s .out .dst , fileNameRef )
156
+
157
+ if _ , err := os .Stat (fileLoc ); err != nil {
158
+ if os .IsNotExist (err ) {
159
+ return fmt .Errorf ("service %s includes an unknown file %s does not exist" , ss .Name , fileLoc )
160
+ }
161
+ return fmt .Errorf ("failed to stat file %s: %w" , fileLoc , err )
207
162
}
208
- s .overrides [ss .Name ] = bin
209
163
}
210
164
}
211
165
@@ -256,7 +210,8 @@ type NodeRef struct {
256
210
257
211
// serviceLogs is a service to access the logs of the running service
258
212
type serviceLogs struct {
259
- path string
213
+ logRef * os.File
214
+ path string
260
215
}
261
216
262
217
func (s * serviceLogs ) readLogs () (string , error ) {
@@ -301,9 +256,15 @@ type service struct {
301
256
filesMapped map [string ]string
302
257
volumesMapped map [string ]string
303
258
259
+ componentName string
260
+
304
261
tag string
305
262
image string
306
263
entrypoint string
264
+ }
265
+
266
+ type instance struct {
267
+ service * service
307
268
308
269
logs * serviceLogs
309
270
component Service
0 commit comments