Skip to content

Commit

Permalink
remote/index_options: create new index with IndexManifest
Browse files Browse the repository at this point in the history
Signed-off-by: Husni Faiz <[email protected]>
  • Loading branch information
husni-faiz committed May 8, 2023
1 parent 1c44052 commit e267ed4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions remote/index_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package remote

import (
"github.com/buildpacks/imgutil"
v1 "github.com/google/go-containerregistry/pkg/v1"
)

type ImageIndexOption func(*indexOptions) error

type indexOptions struct {
mediaTypes imgutil.MediaTypes
manifest v1.IndexManifest
}

// WithIndexMediaTypes loads an existing index as a source.
Expand All @@ -18,3 +20,10 @@ func WithIndexMediaTypes(requested imgutil.MediaTypes) ImageIndexOption {
return nil
}
}

func WithManifest(manifest v1.IndexManifest) ImageIndexOption {
return func(opts *indexOptions) error {
opts.manifest = manifest
return nil
}
}
25 changes: 25 additions & 0 deletions remote/new_manifest_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ func NewIndex(repoName string, keychain authn.Keychain, ops ...ImageIndexOption)
}
}

if len(indexOpts.manifest.Manifests) != 0 {
index, err := emptyIndex(indexOpts.manifest.MediaType)
if err != nil {
return nil, err
}

for _, manifest_i := range indexOpts.manifest.Manifests {
img, _ := emptyImage(imgutil.Platform{
Architecture: manifest_i.Platform.Architecture,
OS: manifest_i.Platform.OS,
OSVersion: manifest_i.Platform.OSVersion,
})
index = mutate.AppendManifests(index, mutate.IndexAddendum{Add: img, Descriptor: manifest_i})
}

idx := &ImageIndex{
keychain: keychain,
repoName: repoName,
index: index,
}

return idx, nil

}

mediaType := defaultMediaType()
if indexOpts.mediaTypes.IndexManifestType() != "" {
mediaType = indexOpts.mediaTypes
Expand Down

0 comments on commit e267ed4

Please sign in to comment.