Skip to content

Commit

Permalink
Revert "feat: add flag to skip deleting obsolete referrers index (ora…
Browse files Browse the repository at this point in the history
…s-project#957)"

This reverts commit ba60b99.

Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Aug 3, 2023
1 parent e6b9a44 commit 078dd8e
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 234 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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/spf13/pflag v1.0.5
golang.org/x/term v0.10.0
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.2.1-0.20230627113607-6b5bd4b4372b
oras.land/oras-go/v2 v2.2.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
oras.land/oras-go/v2 v2.2.1-0.20230627113607-6b5bd4b4372b h1:NYynybpqtG3lLTZMWNlrvUlcyGakCke57tg4TX6w2kA=
oras.land/oras-go/v2 v2.2.1-0.20230627113607-6b5bd4b4372b/go.mod h1:goptA58HogB/6sLN7KV6FgoiurcVxd5QBqv8wMVB0as=
oras.land/oras-go/v2 v2.2.0 h1:E1fqITD56Eg5neZbxBtAdZVgDHD6wBabJo6xESTcQyo=
oras.land/oras-go/v2 v2.2.0/go.mod h1:pXjn0+KfarspMHHNR3A56j3tgvr+mxArHuI8qVn59v8=
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
2 changes: 1 addition & 1 deletion test/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc2
gopkg.in/yaml.v2 v2.4.0
oras.land/oras-go/v2 v2.2.1-0.20230627113607-6b5bd4b4372b
oras.land/oras-go/v2 v2.2.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
oras.land/oras-go/v2 v2.2.1-0.20230627113607-6b5bd4b4372b h1:NYynybpqtG3lLTZMWNlrvUlcyGakCke57tg4TX6w2kA=
oras.land/oras-go/v2 v2.2.1-0.20230627113607-6b5bd4b4372b/go.mod h1:goptA58HogB/6sLN7KV6FgoiurcVxd5QBqv8wMVB0as=
oras.land/oras-go/v2 v2.2.0 h1:E1fqITD56Eg5neZbxBtAdZVgDHD6wBabJo6xESTcQyo=
oras.land/oras-go/v2 v2.2.0/go.mod h1:pXjn0+KfarspMHHNR3A56j3tgvr+mxArHuI8qVn59v8=
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
Loading

0 comments on commit 078dd8e

Please sign in to comment.