@@ -15,10 +15,12 @@ import (
1515 "github.com/google/go-containerregistry/pkg/registry"
1616 v1 "github.com/google/go-containerregistry/pkg/v1"
1717 "github.com/google/go-containerregistry/pkg/v1/layout"
18+ "github.com/google/go-containerregistry/pkg/v1/match"
1819 "github.com/google/go-containerregistry/pkg/v1/mutate"
1920 "github.com/google/go-containerregistry/pkg/v1/random"
2021 "github.com/google/go-containerregistry/pkg/v1/remote"
2122 "github.com/google/go-containerregistry/pkg/v1/tarball"
23+ "github.com/google/go-containerregistry/pkg/v1/types"
2224 "github.com/stretchr/testify/require"
2325 "github.com/stretchr/testify/suite"
2426)
@@ -389,6 +391,64 @@ func (s *TaskSuite) TestImageArgs() {
389391 }
390392}
391393
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" , "amd64" )
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+ // for image, builtImage := range map[v1.ImageIndex]v1.ImageIndex{
430+ // firstImage: firstBuiltIndex,
431+ // secondImage: secondBuiltIndex,
432+ // } {
433+ // layers, err := image.Layers()
434+ // s.NoError(err)
435+
436+ // builtLayers, err := builtImage.Layers()
437+ // s.NoError(err)
438+ // s.Len(builtLayers, len(layers)+1)
439+
440+ // for i := 0; i < len(layers); i++ {
441+ // digest, err := layers[i].Digest()
442+ // s.NoError(err)
443+
444+ // builtDigest, err := builtLayers[i].Digest()
445+ // s.NoError(err)
446+
447+ // s.Equal(digest, builtDigest)
448+ // }
449+ // }
450+ }
451+
392452func (s * TaskSuite ) TestImageArgsWithUppercaseName () {
393453 imagesDir , err := os .MkdirTemp ("" , "preload-images" )
394454 s .NoError (err )
@@ -673,6 +733,38 @@ func (s *TaskSuite) randomImage(byteSize, layers int64, os, arch string) v1.Imag
673733 return image
674734}
675735
736+ func (s * TaskSuite ) randomImageIndex (byteSize , layers int64 , os , arch string ) v1.ImageIndex {
737+ index , err := random .Index (byteSize , layers , 1 )
738+ s .NoError (err )
739+ manifest , err := index .IndexManifest ()
740+ s .NoError (err )
741+
742+ var image v1.Image
743+ for _ , m := range manifest .Manifests {
744+ if m .MediaType .IsImage () {
745+ image , err = index .Image (m .Digest )
746+ s .NoError (err )
747+ break
748+ }
749+ }
750+
751+ index = mutate .RemoveManifests (index , match .MediaTypes (string (types .OCIManifestSchema1 ), string (types .DockerManifestSchema2 )))
752+
753+ cf , err := image .ConfigFile ()
754+ s .NoError (err )
755+
756+ cf = cf .DeepCopy ()
757+ cf .OS = os
758+ cf .Architecture = arch
759+
760+ image , err = mutate .ConfigFile (image , cf )
761+ s .NoError (err )
762+
763+ index = mutate .AppendManifests (index , mutate.IndexAddendum {Add : image })
764+
765+ return index
766+ }
767+
676768func TestSuite (t * testing.T ) {
677769 suite .Run (t , & TaskSuite {
678770 Assertions : require .New (t ),
0 commit comments