Skip to content

Commit

Permalink
Merge branch 'main' into propose-pr-template
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry Howe authored Feb 11, 2023
2 parents 0b08086 + d6240d6 commit e09ca18
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CLI_PKG = $(PROJECT_PKG)/cmd/oras
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
GO_EXE = go

TARGET_OBJS ?= checksums.txt darwin_amd64.tar.gz darwin_arm64.tar.gz linux_amd64.tar.gz linux_arm64.tar.gz linux_armv7.tar.gz linux_s390x.tar.gz windows_amd64.zip

Expand All @@ -31,8 +32,8 @@ LDFLAGS += -X $(PROJECT_PKG)/internal/version.GitCommit=${GIT_COMMIT}
LDFLAGS += -X $(PROJECT_PKG)/internal/version.GitTreeState=${GIT_DIRTY}

.PHONY: test
test: vendor check-encoding
go test -race -v -coverprofile=coverage.txt -covermode=atomic ./...
test: tidy vendor check-encoding
$(GO_EXE) test -race -v -coverprofile=coverage.txt -covermode=atomic ./...

.PHONY: covhtml
covhtml:
Expand All @@ -50,48 +51,48 @@ build-linux: build-linux-amd64 build-linux-arm64 build-linux-arm-v7 build-linux-

.PHONY: build-linux-amd64
build-linux-amd64:
GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -v --ldflags="$(LDFLAGS)" \
GOARCH=amd64 CGO_ENABLED=0 GOOS=linux $(GO_EXE) build -v --ldflags="$(LDFLAGS)" \
-o bin/linux/amd64/$(CLI_EXE) $(CLI_PKG)

.PHONY: build-linux-arm64
build-linux-arm64:
GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -v --ldflags="$(LDFLAGS)" \
GOARCH=arm64 CGO_ENABLED=0 GOOS=linux $(GO_EXE) build -v --ldflags="$(LDFLAGS)" \
-o bin/linux/arm64/$(CLI_EXE) $(CLI_PKG)

.PHONY: build-linux-arm-v7
build-linux-arm-v7:
GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -v --ldflags="$(LDFLAGS)" \
GOARCH=arm CGO_ENABLED=0 GOOS=linux $(GO_EXE) build -v --ldflags="$(LDFLAGS)" \
-o bin/linux/arm/v7/$(CLI_EXE) $(CLI_PKG)

.PHONY: build-linux-s390x
build-linux-s390x:
GOARCH=s390x CGO_ENABLED=0 GOOS=linux go build -v --ldflags="$(LDFLAGS)" \
GOARCH=s390x CGO_ENABLED=0 GOOS=linux $(GO_EXE) build -v --ldflags="$(LDFLAGS)" \
-o bin/linux/s390x/$(CLI_EXE) $(CLI_PKG)

.PHONY: build-mac
build-mac: build-mac-arm64 build-mac-amd64

.PHONY: build-mac-amd64
build-mac-amd64:
GOARCH=amd64 CGO_ENABLED=0 GOOS=darwin go build -v --ldflags="$(LDFLAGS)" \
GOARCH=amd64 CGO_ENABLED=0 GOOS=darwin $(GO_EXE) build -v --ldflags="$(LDFLAGS)" \
-o bin/darwin/amd64/$(CLI_EXE) $(CLI_PKG)

.PHONY: build-mac-arm64
build-mac-arm64:
GOARCH=arm64 CGO_ENABLED=0 GOOS=darwin go build -v --ldflags="$(LDFLAGS)" \
GOARCH=arm64 CGO_ENABLED=0 GOOS=darwin $(GO_EXE) build -v --ldflags="$(LDFLAGS)" \
-o bin/darwin/arm64/$(CLI_EXE) $(CLI_PKG)

.PHONY: build-windows
build-windows: build-windows-amd64 build-windows-arm64

.PHONY: build-windows-amd64
build-windows-amd64:
GOARCH=amd64 CGO_ENABLED=0 GOOS=windows go build -v --ldflags="$(LDFLAGS)" \
GOARCH=amd64 CGO_ENABLED=0 GOOS=windows $(GO_EXE) build -v --ldflags="$(LDFLAGS)" \
-o bin/windows/amd64/$(CLI_EXE).exe $(CLI_PKG)

.PHONY: build-windows-arm64
build-windows-arm64:
GOARCH=arm64 CGO_ENABLED=0 GOOS=windows go build -v --ldflags="$(LDFLAGS)" \
GOARCH=arm64 CGO_ENABLED=0 GOOS=windows $(GO_EXE) build -v --ldflags="$(LDFLAGS)" \
-o bin/windows/arm64/$(CLI_EXE).exe $(CLI_PKG)

.PHONY: check-encoding
Expand All @@ -102,9 +103,13 @@ check-encoding:
fix-encoding:
find cmd internal -type f -name "*.go" -exec sed -i -e "s/\r//g" {} +

.PHONY: tidy
tidy:
GO111MODULE=on $(GO_EXE) mod tidy

.PHONY: vendor
vendor:
GO111MODULE=on go mod vendor
GO111MODULE=on $(GO_EXE) mod vendor

.PHONY: fetch-dist
fetch-dist:
Expand Down
10 changes: 1 addition & 9 deletions cmd/oras/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content"
"oras.land/oras-go/v2/content/file"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras/cmd/oras/internal/option"
)

Expand Down Expand Up @@ -164,14 +163,7 @@ func runAttach(opts attachOptions) error {

digest := subject.Digest.String()
if !strings.HasSuffix(opts.RawReference, digest) {
// Reassemble a reference with subject digest
if repo, ok := dst.(*remote.Repository); ok {
ref := repo.Reference
ref.Reference = subject.Digest.String()
opts.RawReference = ref.String()
} else if opts.Type == option.TargetTypeOCILayout {
opts.RawReference = fmt.Sprintf("%s@%s", opts.Path, subject.Digest)
}
opts.RawReference = fmt.Sprintf("%s@%s", opts.Path, subject.Digest)
}
fmt.Println("Attached to", opts.AnnotatedReference())
fmt.Println("Digest:", root.Digest)
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func runDiscover(opts discoverOptions) error {
}

if opts.outputType == "tree" {
root := tree.New(opts.Reference)
root := tree.New(fmt.Sprintf("%s@%s", opts.Path, desc.Digest))
err = fetchAllReferrers(ctx, repo, desc, opts.artifactType, root, &opts)
if err != nil {
return err
Expand Down
11 changes: 10 additions & 1 deletion cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ type Target struct {
RawReference string
Type string
Reference string //contains tag or digest
Path string
// Path contains
// - path to the OCI image layout target, or
// - registry and repository for the remote target
Path string

isOCILayout bool
}
Expand Down Expand Up @@ -118,6 +121,9 @@ func (opts *Target) NewTarget(common Common) (oras.GraphTarget, error) {
if err != nil {
return nil, err
}
tmp := repo.Reference
tmp.Reference = ""
opts.Path = tmp.String()
opts.Reference = repo.Reference.Reference
return repo, nil
}
Expand Down Expand Up @@ -153,6 +159,9 @@ func (opts *Target) NewReadonlyTarget(ctx context.Context, common Common) (ReadO
if err != nil {
return nil, err
}
tmp := repo.Reference
tmp.Reference = ""
opts.Path = tmp.String()
opts.Reference = repo.Reference.Reference
return repo, nil
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module oras.land/oras
go 1.20

require (
github.com/docker/cli v23.0.0+incompatible
github.com/docker/cli v23.0.1+incompatible
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/need-being/go-tree v0.1.0
github.com/opencontainers/go-digest v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/danieljoos/wincred v1.1.0/go.mod h1:XYlo+eRTsVA9aHGp7NGjFkPla4m+DCL7h
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/cli v23.0.0+incompatible h1:bcM4syaQ+EM/iczJTimMOGzvnzJBFPFEf4acS7sZ+RM=
github.com/docker/cli v23.0.0+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v23.0.1+incompatible h1:LRyWITpGzl2C9e9uGxzisptnxAn1zfZKXy13Ul2Q5oM=
github.com/docker/cli v23.0.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/docker v20.10.17+incompatible h1:JYCuMrWaVNophQTOrMMoSwudOVEfcegoZZrleKc1xwE=
github.com/docker/docker v20.10.17+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.6.4 h1:axCks+yV+2MR3/kZhAmy07yC56WZ2Pwu/fKWtKuZB0o=
Expand Down

0 comments on commit e09ca18

Please sign in to comment.