@@ -110,7 +110,7 @@ public async Task ApiEndToEndWithLocalLoad()
110110 . Should ( ) . Pass ( ) ;
111111 }
112112
113- private string BuildLocalApp ( [ CallerMemberName ] string testName = "TestName" , string tfm = "net6.0" , string rid = "linux-x64" )
113+ private string BuildLocalApp ( [ CallerMemberName ] string testName = "TestName" , string tfm = "net6.0" , string rid = "linux-x64" , string configuration = "Debug" )
114114 {
115115 string workingDirectory = Path . Combine ( TestSettings . TestArtifactsDirectory , testName ) ;
116116
@@ -126,12 +126,12 @@ private string BuildLocalApp([CallerMemberName] string testName = "TestName", st
126126 . Execute ( )
127127 . Should ( ) . Pass ( ) ;
128128
129- new DotnetCommand ( _testOutput , "publish" , "-bl" , "MinimalTestApp" , "-r" , rid , "-f" , tfm )
129+ new DotnetCommand ( _testOutput , "publish" , "-bl" , "-c" , configuration , " MinimalTestApp", "-r" , rid , "-f" , tfm )
130130 . WithWorkingDirectory ( workingDirectory )
131131 . Execute ( )
132132 . Should ( ) . Pass ( ) ;
133133
134- string publishDirectory = Path . Join ( workingDirectory , "MinimalTestApp" , "bin" , "Debug" , tfm , rid , "publish" ) ;
134+ string publishDirectory = Path . Join ( workingDirectory , "MinimalTestApp" , "bin" , configuration , tfm , rid , "publish" ) ;
135135 return publishDirectory ;
136136 }
137137
@@ -328,4 +328,49 @@ string[] DecideEntrypoint(string rid, string appName, string workingDir)
328328 return new [ ] { $ "{ workingDir } /{ binary } " } ;
329329 }
330330 }
331+
332+ [ Fact ]
333+ public async Task CanSetContainerUserAndUseRootless ( )
334+ {
335+ var rid = "linux-x64" ;
336+ string publishDirectory = BuildLocalApp ( tfm : "net8.0" , rid : rid , configuration : "Release" ) ;
337+
338+ // Build the image
339+ Registry registry = new ( ContainerHelpers . TryExpandRegistryToUri ( DockerRegistryManager . BaseImageSource ) ) ;
340+
341+ ImageBuilder ? imageBuilder = await registry . GetImageManifestAsync (
342+ DockerRegistryManager . BaseImage ,
343+ DockerRegistryManager . Net8PreviewImageTag ,
344+ rid ,
345+ ToolsetUtils . GetRuntimeGraphFilePath ( ) ,
346+ cancellationToken : default ) . ConfigureAwait ( false ) ;
347+ Assert . NotNull ( imageBuilder ) ;
348+
349+ Layer l = Layer . FromDirectory ( publishDirectory , "/app" , false ) ;
350+
351+ imageBuilder . AddLayer ( l ) ;
352+ imageBuilder . SetWorkingDirectory ( "/app" ) ;
353+
354+ imageBuilder . SetEntryPoint ( new [ ] { "/app/MinimalTestApp" } ) ;
355+ imageBuilder . SetUser ( "app" ) ;
356+ BuiltImage builtImage = imageBuilder . Build ( ) ;
357+
358+ // Load the image into the local Docker daemon
359+ var sourceReference = new ImageReference ( registry , DockerRegistryManager . BaseImage , DockerRegistryManager . Net8PreviewImageTag ) ;
360+ var destinationReference = new ImageReference ( registry , NewImageName ( ) , rid ) ;
361+ await new LocalDocker ( Console . WriteLine ) . LoadAsync ( builtImage , sourceReference , destinationReference , default ) . ConfigureAwait ( false ) ;
362+
363+ // Run the image
364+ new BasicCommand (
365+ _testOutput ,
366+ "docker" ,
367+ "run" ,
368+ "--rm" ,
369+ "--tty" ,
370+ $ "{ NewImageName ( ) } :{ rid } ")
371+ . Execute ( )
372+ . Should ( )
373+ . Pass ( ) ;
374+
375+ }
331376}
0 commit comments