14
14
* limitations under the License.
15
15
*/
16
16
17
+ using System . Diagnostics ;
17
18
using System . Globalization ;
18
- using Amazon . Runtime . Internal . Transform ;
19
19
using Ardalis . GuardClauses ;
20
20
using Docker . DotNet ;
21
21
using Docker . DotNet . Models ;
@@ -364,9 +364,14 @@ private CreateContainerParameters BuildContainerSpecification(IList<ContainerVol
364
364
{
365
365
Runtime = Strings . RuntimeNvidia ,
366
366
Mounts = volumeMounts ,
367
- }
367
+ } ,
368
368
} ;
369
369
370
+ if ( Event . TaskPluginArguments . ContainsKey ( Keys . User ) )
371
+ {
372
+ parameters . User = Event . TaskPluginArguments [ Keys . User ] ;
373
+ }
374
+
370
375
return parameters ;
371
376
}
372
377
@@ -406,6 +411,7 @@ private async Task<List<ContainerVolumeMount>> SetupInputs(CancellationToken can
406
411
// eg: /monai/input
407
412
var volumeMount = new ContainerVolumeMount ( input , Event . TaskPluginArguments [ input . Name ] , inputHostDirRoot , inputContainerDirRoot ) ;
408
413
volumeMounts . Add ( volumeMount ) ;
414
+ _logger . InputVolumeMountAdded ( inputHostDirRoot , inputContainerDirRoot ) ;
409
415
410
416
// For each file, download from bucket and store in Task Manager Container.
411
417
foreach ( var obj in objects )
@@ -424,6 +430,8 @@ private async Task<List<ContainerVolumeMount>> SetupInputs(CancellationToken can
424
430
}
425
431
}
426
432
433
+ SetPermission ( containerPath ) ;
434
+
427
435
return volumeMounts ;
428
436
}
429
437
@@ -436,7 +444,10 @@ private ContainerVolumeMount SetupIntermediateVolume()
436
444
437
445
Directory . CreateDirectory ( containerPath ) ;
438
446
439
- return new ContainerVolumeMount ( Event . IntermediateStorage , Event . TaskPluginArguments [ Keys . WorkingDirectory ] , hostPath , containerPath ) ;
447
+ var volumeMount = new ContainerVolumeMount ( Event . IntermediateStorage , Event . TaskPluginArguments [ Keys . WorkingDirectory ] , hostPath , containerPath ) ;
448
+ _logger . IntermediateVolumeMountAdded ( hostPath , containerPath ) ;
449
+ SetPermission ( containerPath ) ;
450
+ return volumeMount ;
440
451
}
441
452
442
453
return default ! ;
@@ -465,11 +476,32 @@ private List<ContainerVolumeMount> SetupOutputs()
465
476
Directory . CreateDirectory ( containerPath ) ;
466
477
467
478
volumeMounts . Add ( new ContainerVolumeMount ( output , Event . TaskPluginArguments [ output . Name ] , hostPath , containerPath ) ) ;
479
+ _logger . OutputVolumeMountAdded ( hostPath , containerPath ) ;
468
480
}
469
481
482
+ SetPermission ( containerRootPath ) ;
483
+
470
484
return volumeMounts ;
471
485
}
472
486
487
+ private void SetPermission ( string path )
488
+ {
489
+ if ( Event . TaskPluginArguments . ContainsKey ( Keys . User ) )
490
+ {
491
+ if ( ! System . OperatingSystem . IsWindows ( ) )
492
+ {
493
+ var process = Process . Start ( "chown" , $ "-R { Event . TaskPluginArguments [ Keys . User ] } { path } ") ;
494
+ process . WaitForExit ( ) ;
495
+
496
+ if ( process . ExitCode != 0 )
497
+ {
498
+ _logger . ErrorSettingDirectoryPermission ( path , Event . TaskPluginArguments [ Keys . User ] ) ;
499
+ throw new SetPermissionException ( $ "chown command exited with code { process . ExitCode } ") ;
500
+ }
501
+ }
502
+ }
503
+ }
504
+
473
505
protected override void Dispose ( bool disposing )
474
506
{
475
507
if ( ! DisposedValue && disposing )
0 commit comments