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