Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manifest List Interface #191

Merged
merged 189 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
9eb407f
index: add Image Index interface
husni-faiz Apr 3, 2023
816341c
remote: index: function to create new index
husni-faiz Apr 3, 2023
fefd9bc
bugfix: index: Remove mutating media type to DockerManifestList
husni-faiz Apr 9, 2023
05456ff
index: optimize: get image from descriptor
husni-faiz Apr 9, 2023
13989a3
index: check for image architecture
husni-faiz Apr 9, 2023
dc5c024
index: add default path to Save()
husni-faiz Apr 9, 2023
02d354b
index: add keychain to new index
husni-faiz Apr 9, 2023
db82b69
index: add image index types
husni-faiz Apr 9, 2023
cdb04c9
indexOptions for creating image index
husni-faiz Apr 9, 2023
d87b7d1
index: path and mediatype options for creating index
husni-faiz Apr 9, 2023
7842116
index: add remove index method
husni-faiz Apr 9, 2023
390546a
remote: index: remove path option
husni-faiz Apr 25, 2023
aa43a59
remote: index: user docker mediatype by default
husni-faiz Apr 25, 2023
21a4790
remote: index: remove saving to layout
husni-faiz Apr 25, 2023
74f8e44
remote: index: save index to registry
husni-faiz Apr 25, 2023
d91432c
index: local: annotate and add functionality
husni-faiz May 2, 2023
bccd2af
remote/index: return error instead of calling panic
husni-faiz May 7, 2023
e24cebc
remote/index: return a wrapped error if fetcing an image fails
husni-faiz May 7, 2023
c17b6d9
local/index: return error instead of calling panic
husni-faiz May 7, 2023
add9675
remote/new_index: validate index name
husni-faiz May 7, 2023
db2e406
local/index: refactor interface functions to use the index path
husni-faiz May 8, 2023
3464e40
local/index_options: create new index with IndexManifest
husni-faiz May 8, 2023
08653dd
remote/index_options: create new index with IndexManifest
husni-faiz May 8, 2023
c941979
remote/new_index: rename file
husni-faiz May 8, 2023
9d284ea
get IndexManifest from ggcr index
husni-faiz May 15, 2023
2752977
remote/index/save: return error if platform information is missing
husni-faiz May 17, 2023
a4589d4
remote/index: ImageIndexTest to be used in unit tests
husni-faiz May 17, 2023
8c5d049
remote/index_test: setup a registry for test
husni-faiz May 17, 2023
4f9c64b
remote/index_test: basic tests for remote index
husni-faiz May 17, 2023
85b8899
remote/new_index: NewIndexTest function to create a test index
husni-faiz May 17, 2023
6a0c434
remote/new_index: use index in registry if already exists
husni-faiz May 17, 2023
8653514
remote/index: remove ManifestSize unused function
husni-faiz May 20, 2023
93861df
index: add brief comments to all index functions
husni-faiz May 21, 2023
afaa657
index: remove returning error when platform information is missing
husni-faiz May 21, 2023
2f6f5c9
local/index: remove AppendManifet wrapper function
husni-faiz May 21, 2023
d558685
local/index: save indent formatted json output
husni-faiz May 26, 2023
adae788
local/index save: use os module instead of layout package
husni-faiz May 27, 2023
7e6c885
local/index: delete method to remove index from local storage
husni-faiz May 27, 2023
54343a5
local/index: wrap GetIndexManifest errors
husni-faiz May 28, 2023
191f664
new_index: check for local index first
husni-faiz Jun 1, 2023
fcb5ade
local/index: copy referenced images to same registry as index
husni-faiz Jun 1, 2023
51609ae
index: fix github action tests failing
husni-faiz Jun 1, 2023
818f3a2
fix linter error: io/ioutil deprecated
husni-faiz Nov 20, 2023
8fdc89d
Merge branch 'main' into dev-image-index
husni-faiz Nov 25, 2023
b31a1ee
WIP added image-index methods
WYGIN Dec 8, 2023
186495b
fWIP fix lint and run format
WYGIN Dec 15, 2023
0c5a954
removed ,gitpod.yml file
WYGIN Dec 15, 2023
bd7af69
WIP removed ImageIndexHandler
WYGIN Dec 15, 2023
85fd5dc
WIP fix some missing logic
WYGIN Dec 15, 2023
f6f80f1
WIP added registry and insecure fields to IndexAddOptions
WYGIN Jan 10, 2024
20568f7
WIP added empty test cases
WYGIN Jan 11, 2024
51446eb
WIP added tests but failing
WYGIN Jan 13, 2024
334b72a
WIP removed oci layout test files
WYGIN Jan 13, 2024
4e79960
WIP removed cnb dir from local
WYGIN Jan 13, 2024
3b842ab
WIP refactor code to improve readability
WYGIN Jan 19, 2024
bd05301
WIP added fake index with empty test cases
WYGIN Jan 20, 2024
39a6fa3
WIP added few tests for fake index
WYGIN Jan 20, 2024
45d6b75
WIP fixed fake index tests
WYGIN Jan 20, 2024
e8c303a
WIP defined errors at one place
WYGIN Jan 20, 2024
00a8a80
WIP trying to fix error when saving index
WYGIN Jan 20, 2024
01db00c
WIP fix: imgutil#Save() and annotations bugs
WYGIN Jan 21, 2024
592a65c
WIP fix: all bugs fixed except image hash change when adding image to…
WYGIN Jan 21, 2024
9ec2c8c
WIP added tests for all indexes
WYGIN Jan 22, 2024
324a62a
WIP made index.NewIndex to return imgutil.ImageIndex instead of imgut…
WYGIN Jan 22, 2024
95b0df4
WIP improved test coverage
WYGIN Jan 26, 2024
3ca7018
WIP improved test coverage by adding #Save
WYGIN Jan 27, 2024
fe02008
WIP fix failing tests for #Add
WYGIN Jan 28, 2024
ab15c33
WIP fix all bugs except mutated configFile and Manifest of image when…
WYGIN Jan 29, 2024
fd3d91c
WIP fix bug except #Save urls
WYGIN Jan 30, 2024
13c3f65
WIP fix all bugs except #Save URLs
WYGIN Jan 31, 2024
d01eaf4
WIP fix: SetURLs for #Save
WYGIN Feb 5, 2024
e158f8d
WIP bug fixes
WYGIN Feb 6, 2024
8d76f28
WIP added goroutines to improve performance
WYGIN Feb 8, 2024
cdd16f8
WIP minor bug fixes
WYGIN Feb 9, 2024
921a22f
WIP added manifestOnly handler
WYGIN Feb 12, 2024
9edc6be
WIP minor changes to ImageIndex#Push
WYGIN Feb 12, 2024
e7cfa9c
WIP fix: use latest index when pushing index
WYGIN Feb 12, 2024
c98cea9
WIP added TaggableIndex to push IndexManifest only
WYGIN Feb 12, 2024
fad6445
WIP fix: added decribable methods to TaggableIndex
WYGIN Feb 12, 2024
0b018df
WIP added documentation, fix: IndexHandler#Push iissue
WYGIN Feb 13, 2024
1d563fd
WIP added tests for index.NewIndex
WYGIN Feb 13, 2024
8656617
Merge branch 'main' into dev-image-index
jjbustamante Feb 13, 2024
da80ffb
Merge branch 'dev-image-index' into image-index
WYGIN Feb 14, 2024
d071ec2
WIP formatted code after Merge upstream branch
WYGIN Feb 14, 2024
2f20186
WIP: fix bugs
WYGIN Feb 19, 2024
d57cc75
fix: tests making 'pack manifest' fail
WYGIN Feb 29, 2024
5f5ff95
fix: return error when setters called on unknown digest of fake index
WYGIN Feb 29, 2024
658b7ff
refactor: improved error messages
WYGIN Feb 29, 2024
363020d
fix: bug causing local images to fail annotate
WYGIN Mar 1, 2024
2b39c6a
fix: manifest handler not saved annotated images
WYGIN Mar 1, 2024
052db76
refactor: removed IndexHandler
WYGIN Mar 2, 2024
96558aa
refactor: remove dead code
WYGIN Mar 2, 2024
38da26f
refactor: improve ManifestHandler#Save readability
WYGIN Mar 2, 2024
2dad2cc
refactor: nit all methods except #Add
WYGIN Mar 2, 2024
0bf93b7
refactor: nit nil pointer handling
WYGIN Mar 2, 2024
3a656df
refactor: ManifestHandler tests
WYGIN Mar 2, 2024
1c3b05e
feat: added #Features #OSFeatures #URLs #Annotations methods to imgut…
WYGIN Mar 4, 2024
abfcabf
refactor: remove IndexHandler
WYGIN Mar 4, 2024
439fac9
fix: removed duplicate stringSlices for features, osFeatures, urls
WYGIN Mar 14, 2024
6e77fba
refactor: change imgutil.Platform to v1.Platform
WYGIN Mar 15, 2024
49941ee
refactor: local imaages added to index should implement EdditableImage
WYGIN Mar 15, 2024
3acfd71
fix: add local images return index not found error
WYGIN Mar 25, 2024
b5aab10
WIP: added tests for imgutil#MutateManifest
WYGIN Mar 28, 2024
5a8a519
WIP: added tests
SaikiranIndia Mar 30, 2024
3eb4bc6
fix: test
SaikiranIndia Mar 30, 2024
c709d08
WIP: refactor: improve code readability
SaikiranIndia Mar 30, 2024
ce6569d
Merge pull request #2 from WYGIN/image-index
jjbustamante Apr 2, 2024
9e2d51b
fixing some linting errors that are preventing the tests to be executed
jjbustamante Apr 2, 2024
9153420
Fixing failing unit tests
jjbustamante Apr 2, 2024
6550208
Fixing unit test
jjbustamante Apr 2, 2024
6745c1c
Running Manifest Handler tests in Parallel
jjbustamante Apr 2, 2024
d7596e5
Running the rest of the tests in Parallel
jjbustamante Apr 2, 2024
59056e1
fix: layout image concurrency issue while saving
SaikiranIndia Apr 3, 2024
9533f44
chore: revert changes from v1.Platform to imgutil.Platform
WYGIN Apr 3, 2024
75b7c54
Merge pull request #3 from WYGIN/husni-image-index
jjbustamante Apr 3, 2024
103e126
running layout and sparse tests in parallel
jjbustamante Apr 3, 2024
b85e83c
merging latest changes from main
jjbustamante Apr 9, 2024
ba1701d
restoring imgutil.MakeFileSafeName method to convert the image name t…
jjbustamante Apr 9, 2024
1db264b
skipping some test for windows because we don't have Indexes availabl…
jjbustamante Apr 9, 2024
b437d70
fixing windows error message and skipping one more test
jjbustamante Apr 9, 2024
eac7a17
Skipping test with alpine on windows
jjbustamante Apr 9, 2024
ae178ae
Updating doc comments and removing some logic that I think we don't n…
jjbustamante Apr 10, 2024
96301fa
Merge branch 'main' into dev-image-index
jjbustamante Apr 10, 2024
fc5c913
Fixing lint errors
jjbustamante Apr 10, 2024
897ad17
Fixing lint error
jjbustamante Apr 10, 2024
1d0faab
Fixing unit test after cleaning a little bit
jjbustamante Apr 10, 2024
5ff17bd
Refactoring packages, removing fake implemenatation because it is not…
jjbustamante Apr 11, 2024
6fd707e
Merging latest changes from main 04/11
jjbustamante Apr 11, 2024
b7d201c
Merge branch 'main' into dev-image-index
jjbustamante Apr 11, 2024
d8861b6
removing unused files
jjbustamante Apr 11, 2024
53dd3a9
Removing fake implementation, we don't need it right now, if we do ne…
jjbustamante Apr 11, 2024
1c7c3ec
Removing fake implementation, we don't need it right now, if we do ne…
jjbustamante Apr 11, 2024
a0a34ed
Removing more fake implementations
jjbustamante Apr 11, 2024
cedf3ad
restoring from main branch
jjbustamante Apr 11, 2024
50d54c8
refactoring layout image index implementation to be similar to our im…
jjbustamante Apr 12, 2024
ebde93a
Merge branch 'main' into dev-image-index
jjbustamante Apr 12, 2024
5cd3d3e
refactoring the image index options to follow the same pattern we use…
jjbustamante Apr 12, 2024
d038320
Merge branch 'main' into dev-image-index
jjbustamante Apr 12, 2024
0f3054e
adding assertions for checking an ImageIndex that was saved on disk
jjbustamante Apr 12, 2024
c87bd7a
adding #Save, #Add, #Push test scenarios
jjbustamante Apr 13, 2024
fd63c31
adding #Save, #Add, #Push test scenarios
jjbustamante Apr 13, 2024
530a05d
adding #Inspect and #Remove test cases
jjbustamante Apr 13, 2024
d0e9f35
Removing URL() method from index interface, it is not clear to me if …
jjbustamante Apr 15, 2024
1dfd895
removing index package all the implementation is under cnb_index.go, …
jjbustamante Apr 15, 2024
6eb1a70
Removing URLs method in other places
jjbustamante Apr 15, 2024
2c63503
Merge branch 'main' into dev-image-index
jjbustamante Apr 16, 2024
02e8bfa
Remove unneeded setters
natalieparellano Apr 17, 2024
718dd15
Remove unneeded things from local package
natalieparellano Apr 17, 2024
974fe62
Remove features, we don't care about it for now
natalieparellano Apr 17, 2024
0898f25
Remove annotations as a field on the image struct,
natalieparellano Apr 17, 2024
c98f11b
Merge pull request #5 from buildpacks/image-index
jjbustamante Apr 17, 2024
8426835
Remove mutate manifest functions, these should not be needed
natalieparellano Apr 17, 2024
ff8f39f
Remove focus
natalieparellano Apr 17, 2024
d8821bf
Fix failing test
natalieparellano Apr 17, 2024
531abe9
Merge pull request #6 from buildpacks/image-index
jjbustamante Apr 17, 2024
ffa9fbc
Cleanup imgutil.Image interface to organize methods by manifest, conf…
natalieparellano Apr 17, 2024
ad4eec6
Merge pull request #7 from buildpacks/image-index
jjbustamante Apr 17, 2024
9b2f042
Remove the option to add an index to another index,
natalieparellano Apr 17, 2024
bae2d77
Merge pull request #8 from buildpacks/image-index
jjbustamante Apr 17, 2024
88cde47
Prune more stuff from cnb_index.go, but add back setters!
natalieparellano Apr 18, 2024
ba33b6b
Merge pull request #9 from buildpacks/image-index
jjbustamante Apr 18, 2024
289f30c
Fix format
natalieparellano Apr 18, 2024
ea2a3cb
Revert "Fix format"
natalieparellano Apr 18, 2024
55ed46a
Remove CNBIndex.Format as it's not used
natalieparellano Apr 18, 2024
b25226d
Fix a few tests by updating the fixtures
natalieparellano Apr 18, 2024
811ca75
WIP: try to fix tests by overriding path.AppendIndex, but now there's…
natalieparellano Apr 18, 2024
31615f7
Revert "WIP: try to fix tests by overriding path.AppendIndex, but now…
natalieparellano Apr 18, 2024
0d6d63a
WIP: fix all but RemoveManifest test
natalieparellano Apr 18, 2024
c46fcc1
Merge pull request #10 from buildpacks/image-index
jjbustamante Apr 18, 2024
614338e
Fix in-memory part
natalieparellano Apr 18, 2024
e767856
Merge remote-tracking branch 'buildpacks/image-index' into dev-image-…
jjbustamante Apr 18, 2024
e9716db
fixing the remove manifest test, we need to create an empty index on …
jjbustamante Apr 18, 2024
725d3c9
Override Image method instead of renaming us
natalieparellano Apr 19, 2024
d382bdb
Remove insecure as it is not used
natalieparellano Apr 19, 2024
3255562
Try to simplify index options by putting them all on one struct
natalieparellano Apr 19, 2024
ddc5be8
Merge pull request #11 from buildpacks/image-index
jjbustamante Apr 19, 2024
697ac4c
Merge branch 'buildpacks:main' into dev-image-index
jjbustamante Apr 22, 2024
a6fda53
Move some stuff around
natalieparellano Apr 22, 2024
d508728
Move stuff around
natalieparellano Apr 22, 2024
4aedd4c
Merge pull request #12 from buildpacks/image-index
jjbustamante Apr 22, 2024
c2871d0
Fixing - these tests should push and pull from a local registry to av…
jjbustamante Apr 23, 2024
8412584
removing focus
jjbustamante Apr 24, 2024
cbecaa8
adding one more test case for adding multiple manifests, updating Pus…
jjbustamante Apr 24, 2024
f00946b
removing blobs from test data, after testing on pack we don't want to…
jjbustamante Apr 25, 2024
f79d933
when using a fake.Image for unit testing purpose, the Platform is und…
jjbustamante Apr 26, 2024
7a7ff3e
moving layout index tests to index_test.go and adding test coverage t…
jjbustamante Apr 29, 2024
d4a3c74
adding more test coverage for error cases in image index
jjbustamante Apr 29, 2024
2e42a19
fixing an issue when a docker media-type is updated and the value is …
jjbustamante Apr 30, 2024
73a2d7c
change a FIXME into a Note
jjbustamante May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acceptance/reproducibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func testReproducibility(t *testing.T, _ spec.G, it spec.S) {
it.Before(func() {
dockerClient = h.DockerCli(t)

daemonInfo, err := dockerClient.Info(context.TODO())
daemonInfo, err := dockerClient.ServerVersion(context.TODO())
h.AssertNil(t, err)

daemonOS := daemonInfo.OSType
daemonOS := daemonInfo.Os

runnableBaseImageName = h.RunnableBaseImage(daemonOS)
h.PullIfMissing(t, dockerClient, runnableBaseImageName)
Expand Down
157 changes: 79 additions & 78 deletions cnb_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

var (
ErrManifestUndefined = errors.New("encountered unexpected error while parsing image: manifest or index manifest is nil")
ErrUnknownMediaType = func(format types.MediaType) error {
return fmt.Errorf("unsupported media type encountered in image: '%s'", format)

Check warning on line 24 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}
)

Expand All @@ -35,346 +35,347 @@
RepoName string
}

func (h *CNBIndex) getConfigFileFrom(digest name.Digest) (v1.ConfigFile, error) {
hash, err := v1.NewHash(digest.Identifier())
if err != nil {
return v1.ConfigFile{}, err
}
image, err := h.Image(hash)
if err != nil {
return v1.ConfigFile{}, err
}
configFile, err := GetConfigFile(image)
if err != nil {
return v1.ConfigFile{}, err
}
return *configFile, nil
}

func (h *CNBIndex) getManifestFileFrom(digest name.Digest) (v1.Manifest, error) {
hash, err := v1.NewHash(digest.Identifier())
if err != nil {
return v1.Manifest{}, err
}
image, err := h.Image(hash)
func (h *CNBIndex) getDescriptorFrom(digest name.Digest) (v1.Descriptor, error) {
indexManifest, err := getIndexManifest(h.ImageIndex)
if err != nil {
return v1.Manifest{}, err
return v1.Descriptor{}, err

Check warning on line 41 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L38-L41

Added lines #L38 - L41 were not covered by tests
}
manifestFile, err := GetManifest(image)
if err != nil {
return v1.Manifest{}, err
for _, current := range indexManifest.Manifests {
if current.Digest.String() == digest.Identifier() {
return current, nil

Check warning on line 45 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L43-L45

Added lines #L43 - L45 were not covered by tests
}
}
return *manifestFile, nil
return v1.Descriptor{}, fmt.Errorf("failed to find image with digest %s in index", digest.Identifier())

Check warning on line 48 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L48

Added line #L48 was not covered by tests
}

// OS returns `OS` of an existing Image.
func (h *CNBIndex) OS(digest name.Digest) (os string, err error) {
configFile, err := h.getConfigFileFrom(digest)
desc, err := h.getDescriptorFrom(digest)
if err != nil {
return "", err

Check warning on line 55 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L52-L55

Added lines #L52 - L55 were not covered by tests
}
return configFile.OS, nil
if desc.Platform != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: getDescriptorFrom never returns nil in its first argument, so I think you can remove this check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I added it because on unit testing when using random packages in ggcr some nil in these attributes but let me check if everything is file after removing it

return desc.Platform.OS, nil

Check warning on line 58 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L57-L58

Added lines #L57 - L58 were not covered by tests
}
return "", nil

Check warning on line 60 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L60

Added line #L60 was not covered by tests
}

// Architecture return the Architecture of an Image/Index based on given Digest.
// Returns an error if no Image/Index found with given Digest.
func (h *CNBIndex) Architecture(digest name.Digest) (arch string, err error) {
configFile, err := h.getConfigFileFrom(digest)
desc, err := h.getDescriptorFrom(digest)
if err != nil {
return "", err

Check warning on line 68 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L65-L68

Added lines #L65 - L68 were not covered by tests
}
return configFile.Architecture, nil
if desc.Platform != nil {
return desc.Platform.Architecture, nil

Check warning on line 71 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L70-L71

Added lines #L70 - L71 were not covered by tests
}
return "", nil

Check warning on line 73 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L73

Added line #L73 was not covered by tests
}

// Variant return the `Variant` of an Image.
// Returns an error if no Image/Index found with given Digest.
func (h *CNBIndex) Variant(digest name.Digest) (osVariant string, err error) {
configFile, err := h.getConfigFileFrom(digest)
desc, err := h.getDescriptorFrom(digest)
if err != nil {
return "", err

Check warning on line 81 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L78-L81

Added lines #L78 - L81 were not covered by tests
}
return configFile.Variant, nil
if desc.Platform != nil {
return desc.Platform.Variant, nil

Check warning on line 84 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L83-L84

Added lines #L83 - L84 were not covered by tests
}
return "", nil

Check warning on line 86 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L86

Added line #L86 was not covered by tests
}

// OSVersion returns the `OSVersion` of an Image with given Digest.
// Returns an error if no Image/Index found with given Digest.
func (h *CNBIndex) OSVersion(digest name.Digest) (osVersion string, err error) {
configFile, err := h.getConfigFileFrom(digest)
desc, err := h.getDescriptorFrom(digest)
if err != nil {
return "", err

Check warning on line 94 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L91-L94

Added lines #L91 - L94 were not covered by tests
}
return configFile.OSVersion, nil
if desc.Platform != nil {
return desc.Platform.OSVersion, nil

Check warning on line 97 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L96-L97

Added lines #L96 - L97 were not covered by tests
}
return "", nil

Check warning on line 99 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L99

Added line #L99 was not covered by tests
}

// OSFeatures returns the `OSFeatures` of an Image with given Digest.
// Returns an error if no Image/Index found with given Digest.
func (h *CNBIndex) OSFeatures(digest name.Digest) (osFeatures []string, err error) {
configFile, err := h.getConfigFileFrom(digest)
desc, err := h.getDescriptorFrom(digest)
if err != nil {
return nil, err

Check warning on line 107 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L104-L107

Added lines #L104 - L107 were not covered by tests
}
return configFile.OSFeatures, nil
if desc.Platform != nil {
return desc.Platform.OSFeatures, nil

Check warning on line 110 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L109-L110

Added lines #L109 - L110 were not covered by tests
}
return []string{}, nil

Check warning on line 112 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L112

Added line #L112 was not covered by tests
}

// Annotations return the `Annotations` of an Image with given Digest.
// Returns an error if no Image/Index found with given Digest.
// For Docker images and Indexes it returns an error.
func (h *CNBIndex) Annotations(digest name.Digest) (annotations map[string]string, err error) {
manifestFile, err := h.getManifestFileFrom(digest)
desc, err := h.getDescriptorFrom(digest)
if err != nil {
return nil, err

Check warning on line 121 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L118-L121

Added lines #L118 - L121 were not covered by tests
}
return manifestFile.Annotations, nil
return desc.Annotations, nil

Check warning on line 123 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L123

Added line #L123 was not covered by tests
}

// setters

func (h *CNBIndex) SetAnnotations(digest name.Digest, annotations map[string]string) (err error) {
return h.mutateExistingImage(digest, func(image v1.Image) (v1.Image, error) {
partial := mutate.Annotations(image, annotations)
annotatedImage, ok := partial.(v1.Image)
if !ok {
return nil, fmt.Errorf("failed to annotate image")
return h.replaceDescriptor(digest, func(descriptor v1.Descriptor) (v1.Descriptor, error) {
if len(descriptor.Annotations) == 0 {
descriptor.Annotations = make(map[string]string)

Check warning on line 131 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L128-L131

Added lines #L128 - L131 were not covered by tests
}
return annotatedImage, nil

for k, v := range annotations {
descriptor.Annotations[k] = v

Check warning on line 135 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L134-L135

Added lines #L134 - L135 were not covered by tests
}
return descriptor, nil

Check warning on line 137 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L137

Added line #L137 was not covered by tests
})
}

func (h *CNBIndex) SetArchitecture(digest name.Digest, arch string) (err error) {
return h.mutateExistingImage(digest, func(image v1.Image) (v1.Image, error) {
configFile, err := image.ConfigFile()
if err != nil {
return nil, err
}
configFile.Architecture = arch
return mutate.ConfigFile(image, configFile)
return h.replaceDescriptor(digest, func(descriptor v1.Descriptor) (v1.Descriptor, error) {
descriptor.Platform.Architecture = arch
return descriptor, nil
})

Check warning on line 145 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L141-L145

Added lines #L141 - L145 were not covered by tests
}

func (h *CNBIndex) SetOS(digest name.Digest, os string) (err error) {
return h.mutateExistingImage(digest, func(image v1.Image) (v1.Image, error) {
configFile, err := image.ConfigFile()
if err != nil {
return nil, err
}
configFile.OS = os
return mutate.ConfigFile(image, configFile)
return h.replaceDescriptor(digest, func(descriptor v1.Descriptor) (v1.Descriptor, error) {
descriptor.Platform.OS = os
return descriptor, nil
})

Check warning on line 152 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L148-L152

Added lines #L148 - L152 were not covered by tests
}

func (h *CNBIndex) SetVariant(digest name.Digest, osVariant string) (err error) {
return h.mutateExistingImage(digest, func(image v1.Image) (v1.Image, error) {
configFile, err := image.ConfigFile()
if err != nil {
return nil, err
}
configFile.Variant = osVariant
return mutate.ConfigFile(image, configFile)
return h.replaceDescriptor(digest, func(descriptor v1.Descriptor) (v1.Descriptor, error) {
descriptor.Platform.Variant = osVariant
return descriptor, nil
})

Check warning on line 159 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L155-L159

Added lines #L155 - L159 were not covered by tests
}

func (h *CNBIndex) mutateExistingImage(digest name.Digest, withFunc func(image v1.Image) (v1.Image, error)) (err error) {
hash, err := v1.NewHash(digest.Identifier())
func (h *CNBIndex) replaceDescriptor(digest name.Digest, withFun func(descriptor v1.Descriptor) (v1.Descriptor, error)) (err error) {
desc, err := h.getDescriptorFrom(digest)
if err != nil {
return err

Check warning on line 165 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L162-L165

Added lines #L162 - L165 were not covered by tests
}
image, err := h.Image(hash)
desc, err = withFun(desc)
if err != nil {
return err

Check warning on line 169 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L167-L169

Added lines #L167 - L169 were not covered by tests
}
if err = h.RemoveManifest(digest); err != nil {
return err
}
newImage, err := withFunc(image)
if err != nil {
return err
add := mutate.IndexAddendum{
Add: h.ImageIndex,
Descriptor: desc,

Check warning on line 173 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L171-L173

Added lines #L171 - L173 were not covered by tests
}
h.AddManifest(newImage)
h.ImageIndex = mutate.AppendManifests(mutate.RemoveManifests(h.ImageIndex, match.Digests(desc.Digest)), add)
return nil

Check warning on line 176 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L175-L176

Added lines #L175 - L176 were not covered by tests
}

func (h *CNBIndex) Image(hash v1.Hash) (v1.Image, error) {
index, err := h.IndexManifest()
if err != nil {
return nil, err

Check warning on line 182 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L179-L182

Added lines #L179 - L182 were not covered by tests
}
if !indexContains(index.Manifests, hash) {
return nil, fmt.Errorf("failed to find image with digest %s in index", hash.String())

Check warning on line 185 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L184-L185

Added lines #L184 - L185 were not covered by tests
}
return h.ImageIndex.Image(hash)

Check warning on line 187 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L187

Added line #L187 was not covered by tests
}

func indexContains(manifests []v1.Descriptor, hash v1.Hash) bool {
for _, m := range manifests {
if m.Digest.String() == hash.String() {
return true

Check warning on line 193 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L190-L193

Added lines #L190 - L193 were not covered by tests
}
}
return false

Check warning on line 196 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L196

Added line #L196 was not covered by tests
}

// AddManifest adds an image to the index.
func (h *CNBIndex) AddManifest(image v1.Image) {
desc, _ := descriptor(image)
h.ImageIndex = mutate.AppendManifests(h.ImageIndex, mutate.IndexAddendum{
Add: image,
Add: image,
Descriptor: desc,
})

Check warning on line 205 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L200-L205

Added lines #L200 - L205 were not covered by tests
}

// SaveDir will locally save the index.
func (h *CNBIndex) SaveDir() error {
layoutPath := filepath.Join(h.XdgPath, MakeFileSafeName(h.RepoName)) // FIXME: do we create an OCI-layout compatible directory structure?
natalieparellano marked this conversation as resolved.
Show resolved Hide resolved
var (
path layout.Path
err error
)

Check warning on line 214 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L209-L214

Added lines #L209 - L214 were not covered by tests

if _, err = os.Stat(layoutPath); !os.IsNotExist(err) {

Check warning on line 216 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L216

Added line #L216 was not covered by tests
// We need to always init an empty index when saving
if err = os.RemoveAll(layoutPath); err != nil {
return err

Check warning on line 219 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L218-L219

Added lines #L218 - L219 were not covered by tests
}
}

indexType, err := h.ImageIndex.MediaType()
if err != nil {
return err

Check warning on line 225 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L223-L225

Added lines #L223 - L225 were not covered by tests
}
if path, err = newEmptyLayoutPath(indexType, layoutPath); err != nil {
return err

Check warning on line 228 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L227-L228

Added lines #L227 - L228 were not covered by tests
}

var errs SaveError
index, err := h.ImageIndex.IndexManifest()
if err != nil {
return err

Check warning on line 234 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L231-L234

Added lines #L231 - L234 were not covered by tests
}
for _, desc := range index.Manifests {
appendManifest(desc, path, &errs)

Check warning on line 237 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L236-L237

Added lines #L236 - L237 were not covered by tests
}
if len(errs.Errors) != 0 {
return errs

Check warning on line 240 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L239-L240

Added lines #L239 - L240 were not covered by tests
}
return nil

Check warning on line 242 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L242

Added line #L242 was not covered by tests
}

func appendManifest(desc v1.Descriptor, path layout.Path, errs *SaveError) {
if err := path.RemoveDescriptors(match.Digests(desc.Digest)); err != nil {
errs.Errors = append(errs.Errors, SaveDiagnostic{
Cause: err,
})

Check warning on line 249 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L245-L249

Added lines #L245 - L249 were not covered by tests
}
if err := path.AppendDescriptor(desc); err != nil {
errs.Errors = append(errs.Errors, SaveDiagnostic{
Cause: err,
})

Check warning on line 254 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L251-L254

Added lines #L251 - L254 were not covered by tests
}
}

func newEmptyLayoutPath(indexType types.MediaType, path string) (layout.Path, error) {
if indexType == types.OCIImageIndex {
return layout.Write(path, empty.Index)

Check warning on line 260 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L258-L260

Added lines #L258 - L260 were not covered by tests
}
return layout.Write(path, NewEmptyDockerIndex())

Check warning on line 262 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L262

Added line #L262 was not covered by tests
}

// Push Publishes ImageIndex to the registry assuming every image it referes exists in registry.
//
// It will only push the IndexManifest to registry.
func (h *CNBIndex) Push(ops ...func(*IndexOptions) error) error {
func (h *CNBIndex) Push(ops ...IndexOption) error {
var pushOps = &IndexOptions{}
for _, op := range ops {
if err := op(pushOps); err != nil {
return err

Check warning on line 272 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L268-L272

Added lines #L268 - L272 were not covered by tests
}
}

if pushOps.MediaType != "" {
if !pushOps.MediaType.IsIndex() {
return ErrUnknownMediaType(pushOps.MediaType)

Check warning on line 278 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L276-L278

Added lines #L276 - L278 were not covered by tests
}
existingType, err := h.ImageIndex.MediaType()
if err != nil {
return err

Check warning on line 282 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L280-L282

Added lines #L280 - L282 were not covered by tests
}
if pushOps.MediaType != existingType {
h.ImageIndex = mutate.IndexMediaType(h.ImageIndex, pushOps.MediaType)

Check warning on line 285 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L284-L285

Added lines #L284 - L285 were not covered by tests
}
}

ref, err := name.ParseReference(
h.RepoName,
name.WeakValidation,
name.Insecure,
)
if err != nil {
return err

Check warning on line 295 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L289-L295

Added lines #L289 - L295 were not covered by tests
}

indexManifest, err := getIndexManifest(h.ImageIndex)
if err != nil {
return err

Check warning on line 300 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L298-L300

Added lines #L298 - L300 were not covered by tests
}

var taggableIndex = NewTaggableIndex(indexManifest)
multiWriteTagables := map[name.Reference]remote.Taggable{
ref: taggableIndex,

Check warning on line 305 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L303-L305

Added lines #L303 - L305 were not covered by tests
}
for _, tag := range pushOps.DestinationTags {
multiWriteTagables[ref.Context().Tag(tag)] = taggableIndex

Check warning on line 308 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L307-L308

Added lines #L307 - L308 were not covered by tests
}

// FIXME: this will only push the index manifest, assuming that all the images it refers to exist in the registry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a FIXME, I tried to remove it and use the remote.WriteIndex but in such a case we need to have everything on disk in OCI layout format.
I think we should document this behavior for library consumers. For example:

  • I want to create my own index at repo/foo and include some busybox manifests, first you need to copy the busybox manifests to repo/foo before pushing the index otherwise it fails

jjbustamante marked this conversation as resolved.
Show resolved Hide resolved
err = remote.MultiWrite(
multiWriteTagables,
remote.WithAuthFromKeychain(h.KeyChain),
remote.WithTransport(GetTransport(pushOps.Insecure)),
)
if err != nil {
return err

Check warning on line 318 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L312-L318

Added lines #L312 - L318 were not covered by tests
}

if pushOps.Purge {
return h.DeleteDir()

Check warning on line 322 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L321-L322

Added lines #L321 - L322 were not covered by tests
}
return h.SaveDir()

Check warning on line 324 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L324

Added line #L324 was not covered by tests
natalieparellano marked this conversation as resolved.
Show resolved Hide resolved
}

// Inspect Displays IndexManifest.
func (h *CNBIndex) Inspect() (string, error) {
rawManifest, err := h.RawManifest()
if err != nil {
return "", err

Check warning on line 331 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L328-L331

Added lines #L328 - L331 were not covered by tests
}
return string(rawManifest), nil

Check warning on line 333 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L333

Added line #L333 was not covered by tests
}

// RemoveManifest removes an image with a given digest from the index.
func (h *CNBIndex) RemoveManifest(digest name.Digest) (err error) {
hash, err := v1.NewHash(digest.Identifier())
if err != nil {
return err

Check warning on line 340 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L337-L340

Added lines #L337 - L340 were not covered by tests
}
h.ImageIndex = mutate.RemoveManifests(h.ImageIndex, match.Digests(hash))
_, err = h.ImageIndex.Digest() // force compute
return err

Check warning on line 344 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L342-L344

Added lines #L342 - L344 were not covered by tests
}

// DeleteDir removes the index from the local filesystem if it exists.
func (h *CNBIndex) DeleteDir() error {
layoutPath := filepath.Join(h.XdgPath, MakeFileSafeName(h.RepoName))
if _, err := os.Stat(layoutPath); err != nil {
if os.IsNotExist(err) {
return nil

Check warning on line 352 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L348-L352

Added lines #L348 - L352 were not covered by tests
}
return err

Check warning on line 354 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L354

Added line #L354 was not covered by tests
}
return os.RemoveAll(layoutPath)

Check warning on line 356 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L356

Added line #L356 was not covered by tests
}

func getIndexManifest(ii v1.ImageIndex) (mfest *v1.IndexManifest, err error) {
mfest, err = ii.IndexManifest()
if mfest == nil {
return mfest, ErrManifestUndefined

Check warning on line 362 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L359-L362

Added lines #L359 - L362 were not covered by tests
}
return mfest, err

Check warning on line 364 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L364

Added line #L364 was not covered by tests
}

// descriptor returns a v1.Descriptor filled with a v1.Platform created from reading
// the image config file.
func descriptor(image v1.Image) (v1.Descriptor, error) {

Check warning on line 369 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L369

Added line #L369 was not covered by tests
// Get the image configuration file
cfg, _ := GetConfigFile(image)
platform := v1.Platform{}
platform.Architecture = cfg.Architecture
platform.OS = cfg.OS
platform.OSVersion = cfg.OSVersion
platform.Variant = cfg.Variant
platform.OSFeatures = cfg.OSFeatures
return v1.Descriptor{
Platform: &platform,
}, nil

Check warning on line 380 in cnb_index.go

View check run for this annotation

Codecov / codecov/patch

cnb_index.go#L371-L380

Added lines #L371 - L380 were not covered by tests
}
2 changes: 1 addition & 1 deletion index.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ImageIndex interface {
AddManifest(image v1.Image)
RemoveManifest(digest name.Digest) error

Push(ops ...func(options *IndexOptions) error) error
Push(ops ...IndexOption) error
SaveDir() error
DeleteDir() error
}
Loading
Loading