33
33
34
34
const (
35
35
vmNamePrefix = "cirrus-cli-"
36
- macOSAutomountDirectoryPath = "/Volumes/My Shared Files "
36
+ macOSAutomountDirectoryPath = "$HOME/working-dir "
37
37
macOSAutomountDirectoryItem = "working-dir"
38
38
)
39
39
@@ -50,7 +50,9 @@ type Tart struct {
50
50
display string
51
51
volumes []* api.Isolation_Tart_Volume
52
52
53
- vm * VM
53
+ vm * VM
54
+ initializeHooks []remoteagent.WaitForAgentHook
55
+ terminateHooks []remoteagent.WaitForAgentHook
54
56
}
55
57
56
58
func New (
@@ -101,14 +103,15 @@ func (tart *Tart) Warmup(
101
103
additionalEnvironment map [string ]string ,
102
104
logger * echelon.Logger ,
103
105
) error {
104
- return tart .bootVM (ctx , ident , additionalEnvironment , "" , logger )
106
+ return tart .bootVM (ctx , ident , additionalEnvironment , "" , false , logger )
105
107
}
106
108
107
109
func (tart * Tart ) bootVM (
108
110
ctx context.Context ,
109
111
ident string ,
110
112
additionalEnvironment map [string ]string ,
111
113
automountDir string ,
114
+ lazyPull bool ,
112
115
logger * echelon.Logger ,
113
116
) error {
114
117
ctx , prepareInstanceSpan := tracer .Start (ctx , "prepare-instance" )
@@ -128,7 +131,7 @@ func (tart *Tart) bootVM(
128
131
tmpVMName := vmNamePrefix + identToBeInjected + uuid .NewString ()
129
132
vm , err := NewVMClonedFrom (ctx ,
130
133
tart .vmName , tmpVMName ,
131
- false , // always clone from the base image
134
+ lazyPull ,
132
135
additionalEnvironment ,
133
136
logger ,
134
137
)
@@ -143,11 +146,17 @@ func (tart *Tart) bootVM(
143
146
144
147
var directoryMounts []directoryMount
145
148
if automountDir != "" {
149
+ tag := fmt .Sprintf ("tart.virtiofs.%s" , macOSAutomountDirectoryItem )
150
+
146
151
directoryMounts = append (directoryMounts , directoryMount {
147
152
Name : macOSAutomountDirectoryItem ,
148
153
Path : automountDir ,
154
+ Tag : tag ,
149
155
ReadOnly : false ,
150
156
})
157
+
158
+ tart .initializeHooks = append (tart .initializeHooks , mountWorkingDirectoryHook (tag , logger ))
159
+ tart .terminateHooks = append (tart .terminateHooks , unmountWorkingDirectoryHook (logger ))
151
160
}
152
161
153
162
// Convert volumes to directory mounts
@@ -237,7 +246,7 @@ func (tart *Tart) Run(ctx context.Context, config *runconfig.RunConfig) (err err
237
246
automountProjectDir = config .ProjectDir
238
247
}
239
248
err = tart .bootVM (ctx , strconv .FormatInt (config .TaskID , 10 ), config .AdditionalEnvironment ,
240
- automountProjectDir , config .Logger ())
249
+ automountProjectDir , config .TartOptions . LazyPull , config . Logger ())
241
250
if err != nil {
242
251
return err
243
252
}
@@ -249,8 +258,8 @@ func (tart *Tart) Run(ctx context.Context, config *runconfig.RunConfig) (err err
249
258
return err
250
259
}
251
260
252
- initializeHooks := tart .initializeHooks (config )
253
- terminateHooks := tart .terminateHooks (config )
261
+ initializeHooks := tart .getInitializeHooks (config )
262
+ terminateHooks := tart .getTerminateHooks (config )
254
263
255
264
addTartListBreadcrumb (ctx )
256
265
addDHCPDLeasesBreadcrumb (ctx )
@@ -333,7 +342,7 @@ func Cleanup() error {
333
342
return nil
334
343
}
335
344
336
- func (tart * Tart ) initializeHooks (config * runconfig.RunConfig ) []remoteagent.WaitForAgentHook {
345
+ func (tart * Tart ) getInitializeHooks (config * runconfig.RunConfig ) []remoteagent.WaitForAgentHook {
337
346
var hooks []remoteagent.WaitForAgentHook
338
347
339
348
if config .ProjectDir != "" && ! config .DirtyMode {
@@ -365,12 +374,14 @@ func (tart *Tart) initializeHooks(config *runconfig.RunConfig) []remoteagent.Wai
365
374
366
375
sshSess , err := sshClient .NewSession ()
367
376
if err != nil {
377
+ syncLogger .Finish (false )
368
378
return err
369
379
}
370
380
371
381
if err := sshSess .Run (command ); err != nil {
372
382
_ = sshSess .Close ()
373
383
384
+ syncLogger .Finish (false )
374
385
return err
375
386
}
376
387
@@ -382,10 +393,10 @@ func (tart *Tart) initializeHooks(config *runconfig.RunConfig) []remoteagent.Wai
382
393
})
383
394
}
384
395
385
- return hooks
396
+ return append ( tart . initializeHooks , hooks ... )
386
397
}
387
398
388
- func (tart * Tart ) terminateHooks (config * runconfig.RunConfig ) []remoteagent.WaitForAgentHook {
399
+ func (tart * Tart ) getTerminateHooks (config * runconfig.RunConfig ) []remoteagent.WaitForAgentHook {
389
400
var hooks []remoteagent.WaitForAgentHook
390
401
391
402
targetfulVolumes := lo .Filter (tart .volumes , func (volume * api.Isolation_Tart_Volume , index int ) bool {
@@ -420,7 +431,7 @@ func (tart *Tart) terminateHooks(config *runconfig.RunConfig) []remoteagent.Wait
420
431
})
421
432
}
422
433
423
- return hooks
434
+ return append ( tart . terminateHooks , hooks ... )
424
435
}
425
436
426
437
func addTartListBreadcrumb (ctx context.Context ) {
0 commit comments