Skip to content

Commit

Permalink
revert: "feat: add flag to skip deleting obsolete referrers index (#957
Browse files Browse the repository at this point in the history
…)" (#1046)

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah authored Aug 3, 2023
1 parent 8ccbad6 commit 43e4832
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 228 deletions.
8 changes: 0 additions & 8 deletions cmd/oras/internal/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ limitations under the License.
package errors

import (
"errors"
"fmt"

"oras.land/oras-go/v2/registry"
"oras.land/oras-go/v2/registry/remote"
)

// NewErrInvalidReference creates a new error based on the reference string.
Expand All @@ -32,9 +30,3 @@ func NewErrInvalidReference(ref registry.Reference) error {
func NewErrInvalidReferenceStr(ref string) error {
return fmt.Errorf("%s: invalid image reference, expecting <name:tag|name@digest>", ref)
}

// IsReferrersIndexDelete checks if err is a referrers index delete error.
func IsReferrersIndexDelete(err error) bool {
var re *remote.ReferrersError
return errors.As(err, &re) && re.IsReferrersIndexDelete()
}
42 changes: 0 additions & 42 deletions cmd/oras/internal/option/referrers.go

This file was deleted.

10 changes: 1 addition & 9 deletions cmd/oras/root/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ import (
"context"
"errors"
"fmt"
"os"
"strings"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content"
"oras.land/oras-go/v2/content/file"
oerr "oras.land/oras/cmd/oras/internal/errors"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/internal/graph"
)
Expand All @@ -37,7 +35,6 @@ type attachOptions struct {
option.Packer
option.ImageSpec
option.Target
option.Referrers

artifactType string
concurrency int
Expand Down Expand Up @@ -101,7 +98,7 @@ Example - Attach file to the manifest tagged 'v1' in an OCI image layout folder
}

func runAttach(ctx context.Context, opts attachOptions) error {
ctx, logger := opts.WithContext(ctx)
ctx, _ = opts.WithContext(ctx)
annotations, err := opts.LoadManifestAnnotations()
if err != nil {
return err
Expand All @@ -124,8 +121,6 @@ func runAttach(ctx context.Context, opts attachOptions) error {
if err := opts.EnsureReferenceNotEmpty(); err != nil {
return err
}
opts.SetReferrersGC(dst, logger)

subject, err := dst.Resolve(ctx, opts.Reference)
if err != nil {
return err
Expand Down Expand Up @@ -168,9 +163,6 @@ func runAttach(ctx context.Context, opts attachOptions) error {

root, err := pushArtifact(dst, pack, copy)
if err != nil {
if oerr.IsReferrersIndexDelete(err) {
fmt.Fprintln(os.Stderr, "attached successfully but failed to remove the outdated referrers index, please use `--skip-delete-referrers` if you want to skip the deletion")
}
return err
}

Expand Down
9 changes: 1 addition & 8 deletions cmd/oras/root/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package root
import (
"context"
"fmt"
"os"
"strings"
"sync"

Expand All @@ -27,7 +26,6 @@ import (
"github.com/spf13/cobra"
"oras.land/oras-go/v2"
"oras.land/oras/cmd/oras/internal/display"
oerr "oras.land/oras/cmd/oras/internal/errors"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/internal/graph"
)
Expand All @@ -36,7 +34,6 @@ type copyOptions struct {
option.Common
option.Platform
option.BinaryTarget
option.Referrers

recursive bool
concurrency int
Expand Down Expand Up @@ -99,7 +96,7 @@ Example - Copy an artifact with multiple tags with concurrency tuned:
}

func runCopy(ctx context.Context, opts copyOptions) error {
ctx, logger := opts.WithContext(ctx)
ctx, _ = opts.WithContext(ctx)

// Prepare source
src, err := opts.From.NewReadonlyTarget(ctx, opts.Common)
Expand All @@ -115,7 +112,6 @@ func runCopy(ctx context.Context, opts copyOptions) error {
if err != nil {
return err
}
opts.SetReferrersGC(dst, logger)

// Prepare copy options
committed := &sync.Map{}
Expand Down Expand Up @@ -171,9 +167,6 @@ func runCopy(ctx context.Context, opts copyOptions) error {
}
}
if err != nil {
if oerr.IsReferrersIndexDelete(err) {
fmt.Fprintln(os.Stderr, "failed to remove the outdated referrers index, please use `--skip-delete-referrers` if you want to skip the deletion")
}
return err
}

Expand Down
8 changes: 1 addition & 7 deletions cmd/oras/root/manifest/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"oras.land/oras-go/v2/errdef"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras/cmd/oras/internal/display"
oerr "oras.land/oras/cmd/oras/internal/errors"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/internal/file"
)
Expand All @@ -39,7 +38,6 @@ type pushOptions struct {
option.Descriptor
option.Pretty
option.Target
option.Referrers

concurrency int
extraRefs []string
Expand Down Expand Up @@ -106,14 +104,13 @@ Example - Push a manifest to an OCI image layout folder 'layout-dir' and tag wit
}

func pushManifest(ctx context.Context, opts pushOptions) error {
ctx, logger := opts.WithContext(ctx)
ctx, _ = opts.WithContext(ctx)
var target oras.Target
var err error
target, err = opts.NewTarget(opts.Common)
if err != nil {
return err
}
opts.SetReferrersGC(target, logger)
if repo, ok := target.(*remote.Repository); ok {
target = repo.Manifests()
}
Expand Down Expand Up @@ -154,9 +151,6 @@ func pushManifest(ctx context.Context, opts pushOptions) error {
return err
}
if _, err := oras.TagBytes(ctx, target, mediaType, contentBytes, ref); err != nil {
if oerr.IsReferrersIndexDelete(err) {
fmt.Fprintln(os.Stderr, "pushed successfully but failed to remove the outdated referrers index, please use `--skip-delete-referrers` if you want to skip the deletion")
}
return err
}
if err = display.PrintStatus(desc, "Uploaded ", verbose); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ go test oras.land/oras/test/e2e/suite/${suite_name}
This is super handy when you want to do step-by-step debugging from command-line or via an IDE. If you need to debug certain specs, use [focused specs](https://onsi.github.io/ginkgo/#focused-specs) but don't check it in.

### 4. Testing Registry Services
The backend of E2E tests are two registry services: [oras-distribution](https://github.com/oras-project/distribution) and [upstream distribution](https://github.com/distribution/distribution). The former is expected to support image and artifact media types and referrer API; The latter is expected to only support image media type with subject and provide referrers via [tag schema](https://github.com/opencontainers/distribution-spec/blob/v1.1.0-rc1/spec.md#referrers-tag-schema), with deletion disabled.
The backend of E2E tests are two registry services: [oras-distribution](https://github.com/oras-project/distribution) and [upstream distribution](https://github.com/distribution/distribution). The former is expected to support image and artifact media types and referrer API; The latter is expected to only support image media type with subject and provide referrers via [tag schema](https://github.com/opencontainers/distribution-spec/blob/v1.1.0-rc1/spec.md#referrers-tag-schema).

You can run scenario test suite against your own registry services via setting `ORAS_REGISTRY_HOST` or `ORAS_REGISTRY_FALLBACK_HOST` environmental variables.

Expand Down
4 changes: 0 additions & 4 deletions test/e2e/internal/testdata/foobar/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ limitations under the License.
package foobar

import (
"fmt"

"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/test/e2e/internal/utils/match"
Expand All @@ -26,8 +24,6 @@ import (
var (
Tag = "foobar"
Digest = "sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb"
Size = 851
DescriptorStr = fmt.Sprintf(`{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"%s","size":%d}`, Digest, Size)
ManifestStateKey = match.StateKey{Digest: "fd6ed2f36b54", Name: "application/vnd.oci.image.manifest.v1+json"}

FileLayerNames = []string{
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@

help () {
echo "Usage"
echo " run-registry <mount-root> <image-name> <container-name> <container-port> <deletion-enabled>"
echo " run-registry <mount-root> <image-name> <container-name> <container-port>"
echo ""
echo "Arguments"
echo " mount-root root mounting directory for pre-baked registry storage files."
echo " image-name image name of the registry."
echo " container-name container name of the registry service."
echo " container-port port to export the registry service."
echo " delete-enabled if set to true, the registry service will be configured to allow deletion."
}

# run registry service for testing
Expand Down Expand Up @@ -62,7 +61,7 @@ run_registry () {
try_clean_up $ctr_name
docker run --pull always -d -p $ctr_port:5000 --rm --name $ctr_name \
-u $(id -u $(whoami)) \
--env REGISTRY_STORAGE_DELETE_ENABLED=$5 \
--env REGISTRY_STORAGE_DELETE_ENABLED=true \
--env REGISTRY_AUTH_HTPASSWD_REALM=test-basic \
--env REGISTRY_AUTH_HTPASSWD_PATH=/etc/docker/registry/passwd \
--mount type=bind,source=$mnt_root/docker,target=/var/lib/registry/docker \
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ run_registry \
${e2e_root}/testdata/distribution/mount \
ghcr.io/oras-project/registry:v1.0.0-rc.4 \
$oras_container_name \
$ORAS_REGISTRY_PORT \
true
$ORAS_REGISTRY_PORT

echo " === preparing upstream distribution === "
run_registry \
${e2e_root}/testdata/distribution/mount_fallback \
registry:2.8.1 \
$upstream_container_name \
$ORAS_REGISTRY_FALLBACK_PORT \
false
$ORAS_REGISTRY_FALLBACK_PORT

echo " === run tests === "
if ! ginkgo -r -p --succinct suite; then
Expand Down
60 changes: 1 addition & 59 deletions test/e2e/suite/command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var _ = Describe("Fallback registry users:", func() {
subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag)
prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef)
// test
ORAS("attach", "--artifact-type", "test.attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
ORAS("attach", "--artifact-type", "test.attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--image-spec", "v1.1-image").
WithWorkDir(tempDir).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()

Expand All @@ -207,53 +207,6 @@ var _ = Describe("Fallback registry users:", func() {
Expect(index.Manifests[0].MediaType).To(Equal("application/vnd.oci.image.manifest.v1+json"))
})

It("should fail to attach again when cleaning referrers index", func() {
testRepo := attachTestRepo("fallback/fail-gc")
tempDir := PrepareTempFiles()
subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag)
prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef)
// test
ORAS("attach", "--artifact-type", "test.attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
WithWorkDir(tempDir).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()

// validate
var index ocispec.Index
bytes := ORAS("discover", subjectRef, "-o", "json").Exec().Out.Contents()
Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred())
Expect(len(index.Manifests)).To(Equal(1))
Expect(index.Manifests[0].MediaType).To(Equal(ocispec.MediaTypeImageManifest))
// test
ORAS("attach", "--artifact-type", "test.attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "-a", "test.type=another.image").
WithWorkDir(tempDir).
MatchErrKeyWords("Error: failed to delete dangling referrers index").
ExpectFailure().Exec()
})

It("should attach again and skip cleanning index", func() {
testRepo := attachTestRepo("fallback/skip-gc")
tempDir := PrepareTempFiles()
subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag)
prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef)
// test
ORAS("attach", "--artifact-type", "test.attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
WithWorkDir(tempDir).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()
// validate
var index ocispec.Index
bytes := ORAS("discover", subjectRef, "-o", "json").Exec().Out.Contents()
Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred())
Expect(len(index.Manifests)).To(Equal(1))
// test
ORAS("attach", "--artifact-type", "test.attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "-a", "test.type=another.image", "--skip-delete-referrers").
WithWorkDir(tempDir).
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()
// validate
bytes = ORAS("discover", subjectRef, "-o", "json").Exec().Out.Contents()
Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred())
Expect(len(index.Manifests)).To(Equal(2))
})

It("should attach a file via a OCI Image and generate referrer via tag schema", func() {
testRepo := attachTestRepo("fallback/tag_schema")
tempDir := PrepareTempFiles()
Expand All @@ -279,7 +232,6 @@ var _ = Describe("OCI image layout users:", func() {
prepare := func(root string) {
ORAS("cp", RegistryRef(Host, ImageRepo, foobar.Tag), Flags.ToLayout, LayoutRef(root, foobar.Tag)).Exec()
}

It("should attach a file to a subject", func() {
root := PrepareTempFiles()
subjectRef := LayoutRef(root, foobar.Tag)
Expand All @@ -289,16 +241,6 @@ var _ = Describe("OCI image layout users:", func() {
MatchStatus([]match.StateKey{foobar.AttachFileStateKey}, false, 1).Exec()
})

It("should attach and output warning for referrers deletion by default", func() {
root := PrepareTempFiles()
subjectRef := LayoutRef(root, foobar.Tag)
prepare(root)
ORAS("attach", "--artifact-type", "test.attach", "-v", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--skip-delete-referrers").
MatchErrKeyWords("referrers deletion can only be enforced upon registry\n").
WithWorkDir(root).
Exec()
})

It("should attach a file to a subject and export the built manifest", func() {
// prepare
root := PrepareTempFiles()
Expand Down
Loading

0 comments on commit 43e4832

Please sign in to comment.