@@ -7,81 +7,82 @@ namespace Microsoft.NET.Build.Containers;
7
7
8
8
public static class ContainerBuilder
9
9
{
10
- public static async Task Containerize ( DirectoryInfo folder , string workingDir , string registryName , string baseName , string baseTag , string [ ] entrypoint , string [ ] entrypointArgs , string imageName , string [ ] imageTags , string outputRegistry , string [ ] labels , Port [ ] exposedPorts , string [ ] envVars )
10
+ public static async Task Containerize ( DirectoryInfo folder , string workingDir , string registryName , string baseName , string baseTag , string [ ] entrypoint , string [ ] entrypointArgs , string imageName , string [ ] imageTags , string outputRegistry , string [ ] labels , Port [ ] exposedPorts , string [ ] envVars , string containerRuntimeIdentifier )
11
11
{
12
12
var isDockerPull = String . IsNullOrEmpty ( registryName ) ;
13
13
if ( isDockerPull ) {
14
14
throw new ArgumentException ( "Don't know how to pull images from local daemons at the moment" ) ;
15
15
}
16
16
Registry baseRegistry = new Registry ( ContainerHelpers . TryExpandRegistryToUri ( registryName ) ) ;
17
17
18
- Image img = await baseRegistry . GetImageManifest ( baseName , baseTag ) ;
19
- img . WorkingDirectory = workingDir ;
18
+ var img = await baseRegistry . GetImageManifest ( baseName , baseTag , containerRuntimeIdentifier ) ;
19
+ if ( img is not null ) {
20
+ img . WorkingDirectory = workingDir ;
20
21
21
- JsonSerializerOptions options = new ( )
22
- {
23
- WriteIndented = true ,
24
- } ;
25
-
26
- Layer l = Layer . FromDirectory ( folder . FullName , workingDir ) ;
22
+ JsonSerializerOptions options = new ( )
23
+ {
24
+ WriteIndented = true ,
25
+ } ;
27
26
28
- img . AddLayer ( l ) ;
27
+ Layer l = Layer . FromDirectory ( folder . FullName , workingDir ) ;
29
28
30
- img . SetEntrypoint ( entrypoint , entrypointArgs ) ;
29
+ img . AddLayer ( l ) ;
31
30
32
- var isDockerPush = String . IsNullOrEmpty ( outputRegistry ) ;
33
- Registry ? outputReg = isDockerPush ? null : new Registry ( ContainerHelpers . TryExpandRegistryToUri ( outputRegistry ) ) ;
31
+ img . SetEntrypoint ( entrypoint , entrypointArgs ) ;
34
32
35
- foreach ( var label in labels )
36
- {
37
- string [ ] labelPieces = label . Split ( '=' ) ;
33
+ var isDockerPush = String . IsNullOrEmpty ( outputRegistry ) ;
34
+ Registry ? outputReg = isDockerPush ? null : new Registry ( ContainerHelpers . TryExpandRegistryToUri ( outputRegistry ) ) ;
38
35
39
- // labels are validated by System.CommandLine API
40
- img . Label ( labelPieces [ 0 ] , labelPieces [ 1 ] ) ;
41
- }
36
+ foreach ( var label in labels )
37
+ {
38
+ string [ ] labelPieces = label . Split ( '=' ) ;
42
39
43
- foreach ( string envVar in envVars )
44
- {
45
- string [ ] envPieces = envVar . Split ( '=' , 2 ) ;
40
+ // labels are validated by System.CommandLine API
41
+ img . Label ( labelPieces [ 0 ] , labelPieces [ 1 ] ) ;
42
+ }
46
43
47
- img . AddEnvironmentVariable ( envPieces [ 0 ] , envPieces [ 1 ] ) ;
48
- }
44
+ foreach ( string envVar in envVars )
45
+ {
46
+ string [ ] envPieces = envVar . Split ( '=' , 2 ) ;
49
47
50
- foreach ( var ( number , type ) in exposedPorts )
51
- {
52
- // ports are validated by System.CommandLine API
53
- img . ExposePort ( number , type ) ;
54
- }
48
+ img . AddEnvironmentVariable ( envPieces [ 0 ] , envPieces [ 1 ] ) ;
49
+ }
55
50
56
- foreach ( var tag in imageTags )
57
- {
58
- if ( isDockerPush )
51
+ foreach ( var ( number , type ) in exposedPorts )
59
52
{
60
- try
61
- {
62
- LocalDocker . Load ( img , imageName , tag , baseName ) . Wait ( ) ;
63
- Console . WriteLine ( "Containerize: Pushed container '{0}:{1}' to Docker daemon" , imageName , tag ) ;
64
- }
65
- catch ( Exception e )
66
- {
67
- Console . WriteLine ( $ "Containerize: error CONTAINER001: Failed to push to local docker registry: { e } ") ;
68
- Environment . ExitCode = - 1 ;
69
- }
53
+ // ports are validated by System.CommandLine API
54
+ img . ExposePort ( number , type ) ;
70
55
}
71
- else
56
+
57
+ foreach ( var tag in imageTags )
72
58
{
73
- try
59
+ if ( isDockerPush )
74
60
{
75
- outputReg ? . Push ( img , imageName , tag , imageName , ( message ) => Console . WriteLine ( $ "Containerize: { message } ") ) . Wait ( ) ;
76
- Console . WriteLine ( $ "Containerize: Pushed container '{ imageName } :{ tag } ' to registry '{ outputRegistry } '") ;
61
+ try
62
+ {
63
+ LocalDocker . Load ( img , imageName , tag , baseName ) . Wait ( ) ;
64
+ Console . WriteLine ( "Containerize: Pushed container '{0}:{1}' to Docker daemon" , imageName , tag ) ;
65
+ }
66
+ catch ( Exception e )
67
+ {
68
+ Console . WriteLine ( $ "Containerize: error CONTAINER001: Failed to push to local docker registry: { e } ") ;
69
+ Environment . ExitCode = - 1 ;
70
+ }
77
71
}
78
- catch ( Exception e )
72
+ else
79
73
{
80
- Console . WriteLine ( $ "Containerize: error CONTAINER001: Failed to push to output registry: { e } ") ;
81
- Environment . ExitCode = - 1 ;
74
+ try
75
+ {
76
+ outputReg ? . Push ( img , imageName , tag , imageName , ( message ) => Console . WriteLine ( $ "Containerize: { message } ") ) . Wait ( ) ;
77
+ Console . WriteLine ( $ "Containerize: Pushed container '{ imageName } :{ tag } ' to registry '{ outputRegistry } '") ;
78
+ }
79
+ catch ( Exception e )
80
+ {
81
+ Console . WriteLine ( $ "Containerize: error CONTAINER001: Failed to push to output registry: { e } ") ;
82
+ Environment . ExitCode = - 1 ;
83
+ }
82
84
}
83
85
}
84
86
}
85
-
86
87
}
87
88
}
0 commit comments