@@ -15,10 +15,12 @@ import (
15
15
"github.com/google/go-containerregistry/pkg/registry"
16
16
v1 "github.com/google/go-containerregistry/pkg/v1"
17
17
"github.com/google/go-containerregistry/pkg/v1/layout"
18
+ "github.com/google/go-containerregistry/pkg/v1/match"
18
19
"github.com/google/go-containerregistry/pkg/v1/mutate"
19
20
"github.com/google/go-containerregistry/pkg/v1/random"
20
21
"github.com/google/go-containerregistry/pkg/v1/remote"
21
22
"github.com/google/go-containerregistry/pkg/v1/tarball"
23
+ "github.com/google/go-containerregistry/pkg/v1/types"
22
24
"github.com/stretchr/testify/require"
23
25
"github.com/stretchr/testify/suite"
24
26
)
@@ -389,6 +391,42 @@ func (s *TaskSuite) TestImageArgs() {
389
391
}
390
392
}
391
393
394
+ func (s * TaskSuite ) TestImageArgsWithOCIImages () {
395
+ imagesDir , err := os .MkdirTemp ("" , "preload-images" )
396
+ s .NoError (err )
397
+
398
+ defer os .RemoveAll (imagesDir )
399
+
400
+ firstImage := s .randomImageIndex (1024 , 2 , "linux" , "amd64" )
401
+ firstPath := filepath .Join (imagesDir , "first" )
402
+ _ , err = layout .Write (firstPath , firstImage )
403
+ s .NoError (err )
404
+
405
+ secondImage := s .randomImageIndex (1024 , 2 , "linux" , "arm64" )
406
+ secondPath := filepath .Join (imagesDir , "second" )
407
+ _ , err = layout .Write (secondPath , secondImage )
408
+ s .NoError (err )
409
+
410
+ s .req .Config .ContextDir = "testdata/image-args"
411
+ s .req .Config .AdditionalTargets = []string {"first" }
412
+ s .req .Config .ImageArgs = []string {
413
+ "first_image=" + firstPath ,
414
+ "second_image=" + secondPath ,
415
+ }
416
+
417
+ err = os .Mkdir (s .outputPath ("first" ), 0755 )
418
+ s .NoError (err )
419
+
420
+ _ , err = s .build ()
421
+ s .NoError (err )
422
+
423
+ _ , err = tarball .ImageFromPath (s .outputPath ("first" , "image.tar" ), nil )
424
+ s .NoError (err )
425
+
426
+ _ , err = tarball .ImageFromPath (s .outputPath ("image" , "image.tar" ), nil )
427
+ s .NoError (err )
428
+ }
429
+
392
430
func (s * TaskSuite ) TestImageArgsWithUppercaseName () {
393
431
imagesDir , err := os .MkdirTemp ("" , "preload-images" )
394
432
s .NoError (err )
@@ -673,6 +711,38 @@ func (s *TaskSuite) randomImage(byteSize, layers int64, os, arch string) v1.Imag
673
711
return image
674
712
}
675
713
714
+ func (s * TaskSuite ) randomImageIndex (byteSize , layers int64 , os , arch string ) v1.ImageIndex {
715
+ index , err := random .Index (byteSize , layers , 1 )
716
+ s .NoError (err )
717
+ manifest , err := index .IndexManifest ()
718
+ s .NoError (err )
719
+
720
+ var image v1.Image
721
+ for _ , m := range manifest .Manifests {
722
+ if m .MediaType .IsImage () {
723
+ image , err = index .Image (m .Digest )
724
+ s .NoError (err )
725
+ break
726
+ }
727
+ }
728
+
729
+ index = mutate .RemoveManifests (index , match .MediaTypes (string (types .OCIManifestSchema1 ), string (types .DockerManifestSchema2 )))
730
+
731
+ cf , err := image .ConfigFile ()
732
+ s .NoError (err )
733
+
734
+ cf = cf .DeepCopy ()
735
+ cf .OS = os
736
+ cf .Architecture = arch
737
+
738
+ image , err = mutate .ConfigFile (image , cf )
739
+ s .NoError (err )
740
+
741
+ index = mutate .AppendManifests (index , mutate.IndexAddendum {Add : image })
742
+
743
+ return index
744
+ }
745
+
676
746
func TestSuite (t * testing.T ) {
677
747
suite .Run (t , & TaskSuite {
678
748
Assertions : require .New (t ),
0 commit comments