@@ -130,7 +130,35 @@ public async Task ApiEndToEndWithLocalLoad()
130
130
[ DockerAvailableFact ]
131
131
public async Task ApiEndToEndWithArchiveWritingAndLoad ( )
132
132
{
133
- ILogger logger = _loggerFactory . CreateLogger ( nameof ( ApiEndToEndWithArchiveWritingAndLoad ) ) ;
133
+ var archiveFile = Path . Combine ( TestSettings . TestArtifactsDirectory ,
134
+ nameof ( ApiEndToEndWithArchiveWritingAndLoad ) , "app.tar.gz" ) ;
135
+
136
+ // Build the image
137
+ ( BuiltImage builtImage , SourceImageReference sourceReference , DestinationImageReference destinationReference ) =
138
+ await BuildDockerImageWithArciveDestinationAsync ( archiveFile , [ "latest" , "1.0" ] , nameof ( ApiEndToEndWithArchiveWritingAndLoad ) ) ;
139
+
140
+ // Write the image to disk
141
+ await destinationReference . LocalRegistry ! . LoadAsync ( builtImage , sourceReference , destinationReference , default ) . ConfigureAwait ( false ) ;
142
+
143
+ Assert . True ( File . Exists ( archiveFile ) , $ "File.Exists({ archiveFile } )") ;
144
+
145
+ // Load the archive
146
+ ContainerCli . LoadCommand ( _testOutput , "--input" , archiveFile )
147
+ . Execute ( )
148
+ . Should ( ) . Pass ( ) ;
149
+
150
+ // Run the image
151
+ foreach ( string tag in destinationReference . Tags )
152
+ {
153
+ ContainerCli . RunCommand ( _testOutput , "--rm" , "--tty" , $ "{ NewImageName ( ) } :{ tag } ")
154
+ . Execute ( )
155
+ . Should ( ) . Pass ( ) ;
156
+ }
157
+ }
158
+
159
+ private async Task < ( BuiltImage image , SourceImageReference sourceReference , DestinationImageReference destinationReference ) > BuildDockerImageWithArciveDestinationAsync ( string archiveFile , string [ ] tags , string testName )
160
+ {
161
+ ILogger logger = _loggerFactory . CreateLogger ( testName ) ;
134
162
string publishDirectory = BuildLocalApp ( tfm : "net8.0" ) ;
135
163
136
164
// Build the image
@@ -154,32 +182,55 @@ public async Task ApiEndToEndWithArchiveWritingAndLoad()
154
182
BuiltImage builtImage = imageBuilder . Build ( ) ;
155
183
156
184
// Write the image to disk
157
- var archiveFile = Path . Combine ( TestSettings . TestArtifactsDirectory ,
158
- nameof ( ApiEndToEndWithArchiveWritingAndLoad ) , "app.tar.gz" ) ;
159
185
var sourceReference = new SourceImageReference ( registry , DockerRegistryManager . RuntimeBaseImage , DockerRegistryManager . Net7ImageTag ) ;
160
- var destinationReference = new DestinationImageReference ( new ArchiveFileRegistry ( archiveFile ) , NewImageName ( ) , new [ ] { "latest" , "1.0" } ) ;
186
+ var destinationReference = new DestinationImageReference ( new ArchiveFileRegistry ( archiveFile ) , NewImageName ( ) , tags ) ;
161
187
162
- await destinationReference . LocalRegistry ! . LoadAsync ( builtImage , sourceReference , destinationReference , default ) . ConfigureAwait ( false ) ;
188
+ return ( builtImage , sourceReference , destinationReference ) ;
189
+ }
190
+
191
+ [ DockerAvailableFact ]
192
+ public async Task TarballsHaveCorrectStructure ( )
193
+ {
194
+ var archiveFile = Path . Combine ( TestSettings . TestArtifactsDirectory ,
195
+ nameof ( TarballsHaveCorrectStructure ) , "app.tar.gz" ) ;
196
+
197
+ // 1. Create docker image and write it to a tarball
198
+ ( BuiltImage dockerImage , SourceImageReference sourceReference , DestinationImageReference destinationReference ) =
199
+ await BuildDockerImageWithArciveDestinationAsync ( archiveFile , [ "latest" ] , nameof ( TarballsHaveCorrectStructure ) ) ;
163
200
201
+ await destinationReference . LocalRegistry ! . LoadAsync ( dockerImage , sourceReference , destinationReference , default ) . ConfigureAwait ( false ) ;
202
+
164
203
Assert . True ( File . Exists ( archiveFile ) , $ "File.Exists({ archiveFile } )") ;
165
204
166
- // Load the archive
167
- ContainerCli . LoadCommand ( _testOutput , "--input" , archiveFile )
168
- . Execute ( )
169
- . Should ( ) . Pass ( ) ;
205
+ CheckDockerTarballStructure ( archiveFile ) ;
170
206
171
- // Run the image
172
- foreach ( string tag in destinationReference . Tags )
173
- {
174
- ContainerCli . RunCommand ( _testOutput , "--rm" , "--tty" , $ "{ NewImageName ( ) } :{ tag } ")
175
- . Execute ( )
176
- . Should ( ) . Pass ( ) ;
177
- }
207
+ // 2. Convert the docker image to an OCI image and write it to a tarball
208
+ BuiltImage ociImage = ConvertToOciImage ( dockerImage ) ;
209
+
210
+ await destinationReference . LocalRegistry ! . LoadAsync ( ociImage , sourceReference , destinationReference , default ) . ConfigureAwait ( false ) ;
211
+
212
+ Assert . True ( File . Exists ( archiveFile ) , $ "File.Exists({ archiveFile } )") ;
178
213
179
- CheckForDockerTarballStructure ( archiveFile ) ;
214
+ CheckOciTarballStructure ( archiveFile ) ;
180
215
}
181
216
182
- private void CheckForDockerTarballStructure ( string tarball )
217
+ private BuiltImage ConvertToOciImage ( BuiltImage builtImage )
218
+ {
219
+ // Convert the image to an OCI image
220
+ var ociImage = new BuiltImage
221
+ {
222
+ Config = builtImage . Config ,
223
+ ImageDigest = builtImage . ImageDigest ,
224
+ ImageSha = builtImage . ImageSha ,
225
+ ImageSize = builtImage . ImageSize ,
226
+ Manifest = builtImage . Manifest ,
227
+ ManifestMediaType = SchemaTypes . OciManifestV1 ,
228
+ } ;
229
+
230
+ return ociImage ;
231
+ }
232
+
233
+ private void CheckDockerTarballStructure ( string tarball )
183
234
{
184
235
var layersCount = 0 ;
185
236
int configJson = 0 ;
@@ -218,56 +269,7 @@ private void CheckForDockerTarballStructure(string tarball)
218
269
Assert . True ( layersCount > 0 ) ;
219
270
}
220
271
221
- [ DockerAvailableFact ]
222
- public async Task ApiEndToEndOciImageWithArchiveWritingAndLoad ( )
223
- {
224
- ILogger logger = _loggerFactory . CreateLogger ( nameof ( ApiEndToEndOciImageWithArchiveWritingAndLoad ) ) ;
225
-
226
- // Build the image
227
-
228
- Registry registry = new ( DockerRegistryManager . LocalRegistry , logger , RegistryMode . Push ) ;
229
-
230
- ImageBuilder imageBuilder = await registry . GetImageManifestAsync (
231
- DockerRegistryManager . Nginx ,
232
- "latest" ,
233
- "linux-x64" ,
234
- ToolsetUtils . RidGraphManifestPicker ,
235
- cancellationToken : default ) . ConfigureAwait ( false ) ;
236
- Assert . NotNull ( imageBuilder ) ;
237
-
238
- BuiltImage builtImage = imageBuilder . Build ( ) ;
239
-
240
- // Write the image to disk
241
- var archiveFile = Path . Combine ( TestSettings . TestArtifactsDirectory ,
242
- nameof ( ApiEndToEndWithArchiveWritingAndLoad ) , "nginx.tar.gz" ) ;
243
- var sourceReference = new SourceImageReference ( registry , DockerRegistryManager . RuntimeBaseImage , DockerRegistryManager . Net7ImageTag ) ;
244
- var destinationReference = new DestinationImageReference ( new ArchiveFileRegistry ( archiveFile ) , NewImageName ( ) , [ "latest" ] ) ;
245
-
246
- await destinationReference . LocalRegistry ! . LoadAsync ( builtImage , sourceReference , destinationReference , default ) . ConfigureAwait ( false ) ;
247
-
248
- Assert . True ( File . Exists ( archiveFile ) , $ "File.Exists({ archiveFile } )") ;
249
-
250
- // Docker cannot load an OCI image, so we check for Podman
251
- if ( ContainerCli . IsPodman )
252
- {
253
- // Load the archive
254
- ContainerCli . LoadCommand ( _testOutput , "--input" , archiveFile )
255
- . Execute ( )
256
- . Should ( ) . Pass ( ) ;
257
-
258
- // Run the image
259
- foreach ( string tag in destinationReference . Tags )
260
- {
261
- ContainerCli . RunCommand ( _testOutput , "--rm" , "--tty" , $ "{ NewImageName ( ) } :{ tag } ")
262
- . Execute ( )
263
- . Should ( ) . Pass ( ) ;
264
- }
265
- }
266
-
267
- CheckForOciTarballStructure ( archiveFile ) ;
268
- }
269
-
270
- private void CheckForOciTarballStructure ( string tarball )
272
+ private void CheckOciTarballStructure ( string tarball )
271
273
{
272
274
int blobsCount = 0 ;
273
275
int ociLayoutCount = 0 ;
0 commit comments