@@ -159,6 +159,7 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
159
159
testTarExporterSymlink ,
160
160
testMultipleRegistryCacheImportExport ,
161
161
testMultipleExporters ,
162
+ testMultipleImageExporters ,
162
163
testSourceMap ,
163
164
testSourceMapFromRef ,
164
165
testLazyImagePush ,
@@ -3108,6 +3109,87 @@ func testMultipleExporters(t *testing.T, sb integration.Sandbox) {
3108
3109
}
3109
3110
}
3110
3111
3112
+ func testMultipleImageExporters (t * testing.T , sb integration.Sandbox ) {
3113
+ workers .CheckFeatureCompat (t , sb , workers .FeatureOCIExporter )
3114
+ requiresLinux (t )
3115
+
3116
+ c , err := New (sb .Context (), sb .Address ())
3117
+ require .NoError (t , err )
3118
+ defer c .Close ()
3119
+
3120
+ def , err := llb .Scratch ().Marshal (context .TODO ())
3121
+ require .NoError (t , err )
3122
+
3123
+ destDir := t .TempDir ()
3124
+ ociTar := filepath .Join (destDir , "oci.tar" )
3125
+ ociOut , err := os .Create (ociTar )
3126
+ require .NoError (t , err )
3127
+ defer ociOut .Close ()
3128
+
3129
+ dockerTar := filepath .Join (destDir , "docker.tar" )
3130
+ dockerOut , err := os .Create (dockerTar )
3131
+ require .NoError (t , err )
3132
+ defer dockerOut .Close ()
3133
+
3134
+ exporters := []ExportEntry {
3135
+ {
3136
+ Type : ExporterOCI ,
3137
+ Attrs : map [string ]string {
3138
+ "dest" : ociTar ,
3139
+ },
3140
+ Output : fixedWriteCloser (ociOut ),
3141
+ },
3142
+ {
3143
+ Type : ExporterDocker ,
3144
+ Attrs : map [string ]string {
3145
+ "dest" : dockerTar ,
3146
+ },
3147
+ Output : fixedWriteCloser (dockerOut ),
3148
+ },
3149
+ }
3150
+
3151
+ ref := identity .NewID ()
3152
+ _ , err = c .Solve (sb .Context (), def , SolveOpt {
3153
+ Ref : ref ,
3154
+ Exports : exporters ,
3155
+ }, nil )
3156
+ require .NoError (t , err )
3157
+
3158
+ require .FileExists (t , filepath .Join (destDir , "oci.tar" ))
3159
+ require .FileExists (t , filepath .Join (destDir , "docker.tar" ))
3160
+
3161
+ ociConfig := extractImageConfig (t , ociTar )
3162
+ dockerConfig := extractImageConfig (t , dockerTar )
3163
+ // Validate that the image configurtion is not empty
3164
+ require .NotEmpty (t , ociConfig .Architecture , "architecture is missing" )
3165
+ require .NotEmpty (t , dockerConfig .Architecture , "architecture is missing" )
3166
+ }
3167
+
3168
+ func extractImageConfig (t * testing.T , path string ) ocispecs.Image {
3169
+ t .Helper ()
3170
+
3171
+ dt , err := os .ReadFile (path )
3172
+ require .NoError (t , err )
3173
+
3174
+ m , err := testutil .ReadTarToMap (dt , false )
3175
+ require .NoError (t , err )
3176
+
3177
+ var index ocispecs.Index
3178
+ err = json .Unmarshal (m ["index.json" ].Data , & index )
3179
+ require .NoError (t , err )
3180
+ require .NotEmpty (t , index .Manifests , "index is missing platform manifests" )
3181
+
3182
+ var manifest ocispecs.Manifest
3183
+ err = json .Unmarshal (m [filepath .Join ("blobs" , "sha256" , index .Manifests [0 ].Digest .Encoded ())].Data , & manifest )
3184
+ require .NoError (t , err )
3185
+
3186
+ var config ocispecs.Image
3187
+ err = json .Unmarshal (m [filepath .Join ("blobs" , "sha256" , manifest .Config .Digest .Encoded ())].Data , & config )
3188
+ require .NoError (t , err )
3189
+
3190
+ return config
3191
+ }
3192
+
3111
3193
func testOCIExporter (t * testing.T , sb integration.Sandbox ) {
3112
3194
workers .CheckFeatureCompat (t , sb , workers .FeatureOCIExporter )
3113
3195
requiresLinux (t )
0 commit comments