@@ -31,7 +31,7 @@ public async Task ApiEndToEndWithRegistryPushAndPull()
31
31
32
32
Registry registry = new Registry ( ContainerHelpers . TryExpandRegistryToUri ( DockerRegistryManager . LocalRegistry ) ) ;
33
33
34
- Image x = await registry . GetImageManifest ( DockerRegistryManager . BaseImage , DockerRegistryManager . BaseImageTag , "linux-x64" ) ;
34
+ Image x = await registry . GetImageManifest ( DockerRegistryManager . BaseImage , DockerRegistryManager . Net6ImageTag , "linux-x64" ) ;
35
35
36
36
Layer l = Layer . FromDirectory ( publishDirectory , "/app" ) ;
37
37
@@ -69,7 +69,7 @@ public async Task ApiEndToEndWithLocalLoad()
69
69
70
70
Registry registry = new Registry ( ContainerHelpers . TryExpandRegistryToUri ( DockerRegistryManager . LocalRegistry ) ) ;
71
71
72
- Image x = await registry . GetImageManifest ( DockerRegistryManager . BaseImage , DockerRegistryManager . BaseImageTag , "linux-x64" ) ;
72
+ Image x = await registry . GetImageManifest ( DockerRegistryManager . BaseImage , DockerRegistryManager . Net6ImageTag , "linux-x64" ) ;
73
73
74
74
Layer l = Layer . FromDirectory ( publishDirectory , "/app" ) ;
75
75
@@ -91,15 +91,15 @@ public async Task ApiEndToEndWithLocalLoad()
91
91
Assert . AreEqual ( 0 , run . ExitCode ) ;
92
92
}
93
93
94
- private static async Task < string > BuildLocalApp ( )
94
+ private static async Task < string > BuildLocalApp ( string tfm = "net6.0" , string rid = "linux-x64" )
95
95
{
96
96
DirectoryInfo d = new DirectoryInfo ( "MinimalTestApp" ) ;
97
97
if ( d . Exists )
98
98
{
99
99
d . Delete ( recursive : true ) ;
100
100
}
101
101
102
- ProcessStartInfo psi = new ( "dotnet" , "new console -f net6.0 -o MinimalTestApp" )
102
+ ProcessStartInfo psi = new ( "dotnet" , $ "new console -f { tfm } -o MinimalTestApp")
103
103
{
104
104
RedirectStandardOutput = true ,
105
105
RedirectStandardError = true ,
@@ -109,16 +109,17 @@ private static async Task<string> BuildLocalApp()
109
109
110
110
Assert . IsNotNull ( dotnetNew ) ;
111
111
await dotnetNew . WaitForExitAsync ( ) ;
112
- Assert . AreEqual ( 0 , dotnetNew . ExitCode , await dotnetNew . StandardOutput . ReadToEndAsync ( ) + await dotnetNew . StandardError . ReadToEndAsync ( ) ) ;
112
+ Assert . AreEqual ( 0 , dotnetNew . ExitCode , await dotnetNew . StandardOutput . ReadToEndAsync ( ) + Environment . NewLine + await dotnetNew . StandardError . ReadToEndAsync ( ) ) ;
113
113
114
- // Build project
115
-
116
- Process publish = Process . Start ( "dotnet" , "publish -bl MinimalTestApp -r linux-x64" ) ;
114
+ ProcessStartInfo publishPSI = rid is null ? new ( "dotnet" , $ "publish -bl MinimalTestApp") : new ( "dotnet" , $ "publish -bl MinimalTestApp -r { rid } ") ;
115
+ publishPSI . RedirectStandardOutput = true ;
116
+ publishPSI . RedirectStandardError = true ;
117
+ Process publish = Process . Start ( publishPSI ) ;
117
118
Assert . IsNotNull ( publish ) ;
118
119
await publish . WaitForExitAsync ( ) ;
119
- Assert . AreEqual ( 0 , publish . ExitCode ) ;
120
+ Assert . AreEqual ( 0 , publish . ExitCode , await publish . StandardOutput . ReadToEndAsync ( ) + Environment . NewLine + await publish . StandardError . ReadToEndAsync ( ) ) ;
120
121
121
- string publishDirectory = Path . Join ( "MinimalTestApp" , "bin" , "Debug" , "net6.0" , "linux-x64" , "publish" ) ;
122
+ string publishDirectory = Path . Join ( "MinimalTestApp" , "bin" , "Debug" , tfm , rid , "publish" ) ;
122
123
return publishDirectory ;
123
124
}
124
125
@@ -274,4 +275,56 @@ public async Task EndToEnd_NoAPI()
274
275
newProjectDir . Delete ( true ) ;
275
276
privateNuGetAssets . Delete ( true ) ;
276
277
}
278
+
279
+ [ DataRow ( "linux-x86" , false , "/app" ) ] // packaging framework-dependent because missing runtime packs for x86 linux.
280
+ [ DataRow ( "linux-x64" , true , "/app" ) ]
281
+ [ DataRow ( "linux-arm" , false , "/app" ) ] // packaging framework-dependent because emulating arm on x64 Docker host doesn't work
282
+ [ DataRow ( "linux-arm64" , false , "/app" ) ] // packaging framework-dependent because emulating arm64 on x64 Docker host doesn't work
283
+ [ DataRow ( "win-x64" , true , "C:\\ app" ) ]
284
+ [ TestMethod ]
285
+ public async Task CanPackageForAllSupportedContainerRIDs ( string rid , bool isRIDSpecific , string workingDir ) {
286
+ if ( rid == "win-x64" ) {
287
+ Assert . Inconclusive ( "Cannot run Windows containers on Linux hosts (or at the same time as Linux containers), so skipping for now" ) ;
288
+ return ;
289
+ }
290
+ string publishDirectory = await BuildLocalApp ( tfm : "net7.0" , rid : ( isRIDSpecific ? rid : null ) ) ;
291
+
292
+ // Build the image
293
+ Registry registry = new Registry ( ContainerHelpers . TryExpandRegistryToUri ( DockerRegistryManager . LocalRegistry ) ) ;
294
+
295
+ Image x = await registry . GetImageManifest ( DockerRegistryManager . BaseImage , DockerRegistryManager . Net7ImageTag , rid ) ;
296
+
297
+ Layer l = Layer . FromDirectory ( publishDirectory , "/app" ) ;
298
+
299
+ x . AddLayer ( l ) ;
300
+ x . WorkingDirectory = workingDir ;
301
+
302
+ var entryPoint = DecideEntrypoint ( rid , isRIDSpecific , "MinimalTestApp" , workingDir ) ;
303
+ x . SetEntrypoint ( entryPoint ) ;
304
+
305
+ // Load the image into the local Docker daemon
306
+
307
+ await LocalDocker . Load ( x , NewImageName ( ) , rid , DockerRegistryManager . BaseImage ) ;
308
+
309
+ // Run the image
310
+
311
+ ProcessStartInfo runInfo = new ( "docker" , $ "run --rm --tty { NewImageName ( ) } :{ rid } ") {
312
+ RedirectStandardError = true ,
313
+ RedirectStandardOutput = true ,
314
+ } ;
315
+ Process run = Process . Start ( runInfo ) ;
316
+ Assert . IsNotNull ( run ) ;
317
+ await run . WaitForExitAsync ( ) ;
318
+
319
+ Assert . AreEqual ( 0 , run . ExitCode , run . StandardOutput . ReadToEnd ( ) + Environment . NewLine + run . StandardError . ReadToEnd ( ) ) ;
320
+
321
+ string [ ] DecideEntrypoint ( string rid , bool isRIDSpecific , string appName , string workingDir ) {
322
+ var binary = rid . StartsWith ( "win" ) ? $ "{ appName } .exe" : appName ;
323
+ if ( isRIDSpecific ) {
324
+ return new [ ] { $ "{ workingDir } /{ binary } " } ;
325
+ } else {
326
+ return new [ ] { "dotnet" , $ "{ workingDir } /{ binary } .dll" } ;
327
+ }
328
+ }
329
+ }
277
330
}
0 commit comments