Skip to content

Commit ea79be6

Browse files
refactor(artifact): remove oci artifact support (#1359)
* refactor(artifact): remove oci artifact support - add header to referrers call to indicated applied artifact type filters Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com> * feat(gc): simplify gc logic to increase coverage Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com> --------- Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
1 parent 3be690c commit ea79be6

54 files changed

Lines changed: 604 additions & 1608 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ ignore:
66
- "./cmd/zb/*.go"
77
- "./pkg/test/mocks/*.go"
88
- "./swagger/*.go"
9+
- "./pkg/test/test_http_server.go"

errors/errors.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ var (
6363
ErrManifestConflict = errors.New("manifest: multiple manifests found")
6464
ErrManifestMetaNotFound = errors.New("repodb: image metadata not found for given manifest reference")
6565
ErrManifestDataNotFound = errors.New("repodb: image data not found for given manifest digest")
66-
ErrArtifactDataNotFound = errors.New("repodb: artifact data not found for given digest")
6766
ErrIndexDataNotFount = errors.New("repodb: index data not found for given digest")
6867
ErrRepoMetaNotFound = errors.New("repodb: repo metadata not found for given repo name")
6968
ErrTagMetaNotFound = errors.New("repodb: tag metadata not found for given repo and tag names")

examples/config-dynamodb.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"cacheTablename": "ZotBlobTable",
2121
"repoMetaTablename": "ZotRepoMetadataTable",
2222
"manifestDataTablename": "ZotManifestDataTable",
23-
"artifactDataTablename": "ZotArtifactDataTable",
2423
"userDataTablename": "ZotUserDataTable",
2524
"versionTablename": "ZotVersion"
2625
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ require (
462462
)
463463

464464
replace (
465-
github.com/opencontainers/umoci => github.com/project-stacker/umoci v0.0.0-20230228184813-24efbd35e8ef
465+
github.com/opencontainers/image-spec => github.com/project-zot/image-spec v0.0.0-20230428141304-a263befc67ea
466466
// v0.3.1-0.20230104082527-d6f58551be3f is taken from github.com/moby/buildkit v0.11.0
467467
// spdx logic write on v0.3.0 and incompatible with v0.3.1-0.20230104082527-d6f58551be3f
468468
// see https://github.com/aquasecurity/trivy/commit/2033e05b6b563aa4bc46d6234b3657a54e71ee46

go.sum

Lines changed: 22 additions & 11 deletions
Large diffs are not rendered by default.

golangcilint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ linters-settings:
5252
gomoddirectives:
5353
replace-allow-list:
5454
- helm.sh/helm/v3
55-
- github.com/opencontainers/umoci
5655
- github.com/spdx/tools-golang
56+
- github.com/opencontainers/image-spec
5757
issues:
5858
exclude-rules:
5959
- path: pkg/extensions/search/schema.resolvers.go

pkg/api/controller_test.go

Lines changed: 5 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
"zotregistry.io/zot/pkg/log"
5252
"zotregistry.io/zot/pkg/meta/repodb/repodbfactory"
5353
"zotregistry.io/zot/pkg/storage"
54-
storageConstants "zotregistry.io/zot/pkg/storage/constants"
5554
"zotregistry.io/zot/pkg/storage/local"
5655
"zotregistry.io/zot/pkg/test"
5756
)
@@ -157,7 +156,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
157156
"cacheTablename": "BlobTable",
158157
"repoMetaTablename": "RepoMetadataTable",
159158
"manifestDataTablename": "ManifestDataTable",
160-
"artifactDataTablename": "ArtifactDataTable",
161159
"userDataTablename": "ZotUserDataTable",
162160
"versionTablename": "Version",
163161
}
@@ -173,7 +171,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
173171
"cacheTablename": "BlobTable",
174172
"repoMetaTablename": "RepoMetadataTable",
175173
"manifestDataTablename": "ManifestDataTable",
176-
"artifactDataTablename": "ArtifactDataTable",
177174
"userDataTablename": "ZotUserDataTable",
178175
"versionTablename": "Version",
179176
}
@@ -188,7 +185,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
188185
"cacheTablename": "BlobTable",
189186
"repoMetaTablename": "RepoMetadataTable",
190187
"manifestDataTablename": "ManifestDataTable",
191-
"artifactDataTablename": "ArtifactDataTable",
192188
"userDataTablename": "ZotUserDataTable",
193189
"versionTablename": "Version",
194190
}
@@ -222,7 +218,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
222218
"cachetablename": "BlobTable",
223219
"repometatablename": "RepoMetadataTable",
224220
"manifestdatatablename": "ManifestDataTable",
225-
"artifactDataTablename": "ArtifactDataTable",
226221
"userdatatablename": "UserDatatable",
227222
}
228223

@@ -236,7 +231,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
236231
"cachetablename": "",
237232
"repometatablename": "RepoMetadataTable",
238233
"manifestdatatablename": "ManifestDataTable",
239-
"artifactDataTablename": "ArtifactDataTable",
240234
"userDataTablename": "ZotUserDataTable",
241235
"versiontablename": 1,
242236
}
@@ -252,7 +246,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
252246
"repometatablename": "RepoMetadataTable",
253247
"manifestdatatablename": "ManifestDataTable",
254248
"indexdatatablename": "IndexDataTable",
255-
"artifactdatatablename": "ArtifactDataTable",
256249
"userdatatablename": "ZotUserDataTable",
257250
"versiontablename": "1",
258251
}
@@ -4395,138 +4388,15 @@ func TestArtifactReferences(t *testing.T) {
43954388
So(err, ShouldBeNil)
43964389
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
43974390
So(resp.Header().Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex)
4398-
})
4399-
})
4400-
4401-
Convey("Validate Artifact Manifest Reference", func() {
4402-
resp, err := resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4403-
So(err, ShouldBeNil)
4404-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4405-
4406-
var referrers ispec.Index
4407-
err = json.Unmarshal(resp.Body(), &referrers)
4408-
So(err, ShouldBeNil)
4409-
So(referrers.Manifests, ShouldBeEmpty)
4410-
4411-
// now upload a reference
4412-
4413-
// upload image config blob
4414-
resp, err = resty.R().Post(baseURL + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName))
4415-
So(err, ShouldBeNil)
4416-
So(resp.StatusCode(), ShouldEqual, http.StatusAccepted)
4417-
loc := test.Location(baseURL, resp)
4418-
cblob, cdigest := test.GetEmptyImageConfig()
4419-
4420-
resp, err = resty.R().
4421-
SetContentLength(true).
4422-
SetHeader("Content-Length", fmt.Sprintf("%d", len(cblob))).
4423-
SetHeader("Content-Type", "application/octet-stream").
4424-
SetQueryParam("digest", cdigest.String()).
4425-
SetBody(cblob).
4426-
Put(loc)
4427-
So(err, ShouldBeNil)
4428-
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
4429-
4430-
// create a artifact
4431-
manifest := ispec.Artifact{
4432-
MediaType: ispec.MediaTypeArtifactManifest,
4433-
ArtifactType: artifactType,
4434-
Blobs: []ispec.Descriptor{
4435-
{
4436-
MediaType: "application/vnd.oci.image.layer.v1.tar",
4437-
Digest: digest,
4438-
Size: int64(len(content)),
4439-
},
4440-
},
4441-
Subject: &ispec.Descriptor{
4442-
MediaType: ispec.MediaTypeImageManifest,
4443-
Digest: digest,
4444-
Size: int64(len(content)),
4445-
},
4446-
Annotations: map[string]string{
4447-
"key": "val",
4448-
},
4449-
}
4450-
Convey("Using invalid content", func() {
4451-
content := []byte("invalid data")
4452-
So(err, ShouldBeNil)
4453-
mdigest := godigest.FromBytes(content)
4454-
So(mdigest, ShouldNotBeNil)
4455-
resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeArtifactManifest).
4456-
SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, mdigest.String()))
4457-
So(err, ShouldBeNil)
4458-
So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest)
4459-
4460-
// unknown repo will return status not found
4461-
resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", "unknown", digest.String()))
4462-
So(err, ShouldBeNil)
4463-
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
4464-
4465-
resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4466-
So(err, ShouldBeNil)
4467-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4391+
So(resp.Header().Get("OCI-Filters-Applied"), ShouldEqual, artifactType)
44684392

4469-
resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType}).
4470-
Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4471-
So(err, ShouldBeNil)
4472-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4473-
})
4474-
Convey("Using valid content", func() {
4475-
content, err = json.Marshal(manifest)
4476-
So(err, ShouldBeNil)
4477-
mdigest := godigest.FromBytes(content)
4478-
So(mdigest, ShouldNotBeNil)
4479-
resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeArtifactManifest).
4480-
SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, mdigest.String()))
4481-
So(err, ShouldBeNil)
4482-
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
4483-
4484-
resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4485-
So(err, ShouldBeNil)
4486-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4487-
4488-
resp, err = resty.R().SetQueryParams(map[string]string{"artifact": "invalid"}).
4489-
Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4490-
So(err, ShouldBeNil)
4491-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4492-
4493-
resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": "invalid"}).
4494-
Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4495-
So(err, ShouldBeNil)
4496-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4497-
4498-
resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType}).
4499-
Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4393+
resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType +
4394+
",otherArtType"}).Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName,
4395+
digest.String()))
45004396
So(err, ShouldBeNil)
45014397
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
45024398
So(resp.Header().Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex)
4503-
4504-
var index ispec.Index
4505-
err = json.Unmarshal(resp.Body(), &index)
4506-
So(err, ShouldBeNil)
4507-
So(index.Manifests, ShouldNotBeEmpty)
4508-
So(index.Annotations[storageConstants.ReferrerFilterAnnotation], ShouldNotBeEmpty)
4509-
4510-
// filter by multiple artifactTypes
4511-
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet,
4512-
baseURL+fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()), nil)
4513-
So(err, ShouldBeNil)
4514-
values := url.Values{}
4515-
values.Add("artifactType", artifactType)
4516-
values.Add("artifactType", "foobar")
4517-
req.URL.RawQuery = values.Encode()
4518-
rsp, err := http.DefaultClient.Do(req)
4519-
So(err, ShouldBeNil)
4520-
defer rsp.Body.Close()
4521-
So(rsp.StatusCode, ShouldEqual, http.StatusOK)
4522-
So(rsp.Header.Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex)
4523-
body, err := io.ReadAll(rsp.Body)
4524-
So(err, ShouldBeNil)
4525-
err = json.Unmarshal(body, &index)
4526-
So(err, ShouldBeNil)
4527-
So(index.Manifests, ShouldNotBeEmpty)
4528-
So(index.Annotations[storageConstants.ReferrerFilterAnnotation], ShouldNotBeEmpty)
4529-
So(len(strings.Split(index.Annotations[storageConstants.ReferrerFilterAnnotation], ",")), ShouldEqual, 2)
4399+
So(resp.Header().Get("OCI-Filters-Applied"), ShouldEqual, artifactType+",otherArtType")
45304400
})
45314401
})
45324402
})

pkg/api/routes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func (rh *RouteHandler) GetManifest(response http.ResponseWriter, request *http.
433433
}
434434

435435
if rh.c.RepoDB != nil {
436-
err := meta.OnGetManifest(name, reference, digest, content, rh.c.StoreController, rh.c.RepoDB, rh.c.Log)
436+
err := meta.OnGetManifest(name, reference, content, rh.c.StoreController, rh.c.RepoDB, rh.c.Log)
437437

438438
if errors.Is(err, zerr.ErrOrphanSignature) {
439439
rh.c.Log.Error().Err(err).Msg("image is an orphan signature")
@@ -546,6 +546,10 @@ func (rh *RouteHandler) GetReferrers(response http.ResponseWriter, request *http
546546
return
547547
}
548548

549+
if len(artifactTypes) > 0 {
550+
response.Header().Set("OCI-Filters-Applied", strings.Join(artifactTypes, ","))
551+
}
552+
549553
WriteData(response, http.StatusOK, ispec.MediaTypeImageIndex, out)
550554
}
551555

pkg/cli/client.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,8 @@ func isNotationSigned(ctx context.Context, repo, digestStr string, searchConf se
490490
return false
491491
}
492492

493-
for _, reference := range referrers.Manifests {
494-
if reference.ArtifactType == notreg.ArtifactTypeNotation {
495-
return true
496-
}
493+
if len(referrers.Manifests) > 0 {
494+
return true
497495
}
498496

499497
return false

0 commit comments

Comments
 (0)