Skip to content

Commit

Permalink
Merge branch 'main' into progress-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
TerryHowe authored Dec 22, 2024
2 parents 959d140 + e89bc7b commit 8bd855f
Show file tree
Hide file tree
Showing 96 changed files with 3,158 additions and 521 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: setup go environment
uses: actions/setup-go@v5
with:
go-version: '1.23.0'
go-version: '1.23.4'
- name: run goreleaser
uses: goreleaser/goreleaser-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.23.0-alpine as builder
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.23.4-alpine as builder
ARG TARGETPLATFORM
RUN apk add git make
ENV ORASPKG /oras
Expand Down
34 changes: 34 additions & 0 deletions KEYS
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,37 @@ H9l5uBixf+MDUpSPe/YNMz9iZSeWwkW8fmA1EOOFapryw+DEA6glT7AjERGz/pFx
blbo6H6w/7d+
=sd98
-----END PGP PUBLIC KEY BLOCK-----
pub rsa4096 2024-12-04 [SC] [expires: 2025-12-04]
73C7F42E8F0B4493115ABED64F723223E9DF0185
uid [ultimate] Shiwei Zhang <[email protected]>
sig 3 4F723223E9DF0185 2024-12-04 Shiwei Zhang <[email protected]>

-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBGdP0LsBEACrX5ECJSS1wZpFH0EkA8WK7S0Z8R0PlT2bFRGu0Ozd78cuxxi7
rHt0UGrGkTdr6YLQ45sZvdh+Y/ukq6IgBsHlrL5FYWQ4ZgPFMfZeRZlRJvRlmnXj
Pj9JNpqXJNN0fpa3xa6oA31HxNTVMQFL/10UE3BVKJCmmQL3bMu8Q6Kggf6eqJjN
HOyF9o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KQsSXjyP5+pVQ0MudVlOG/K5MLM/eQ8CoSi/5
IR1nU9bP55OLUSGFxgg7tQT9o4NydlgkzM6oiI84GDWbkWnR/slt/J77EKqULACv
CHRPOwmT8gi1uIlbtAPrJ0/Xq2ERpZBZ4EtUZTD2hP3GR3gKShvocDAnRd0mTwNd
mhIkUA7BNzIVRzbzwLuxnFawyhu+e2enQRf/ltDRwstnpZ6at/t15DxCRv7GRdG2
R2N/iKu82t4prtB3o4sDU0aYU+NAjGemhkKbLC90yGa8QCXTVWk3t8rOwWEZoTs6
0TaHyX7iwh/uXs8=
=2B8p
-----END PGP PUBLIC KEY BLOCK-----
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ check-encoding: ## check file CR/LF encoding
fix-encoding: ## fix file CR/LF encoding
find cmd internal -type f -name "*.go" -exec sed -i -e "s/\r//g" {} +

.PHONY: lint
lint: ## run CI version of lint
golangci-lint run ./...

.PHONY: tidy
tidy: ## go mod tidy
GO111MODULE=on $(GO_EXE) mod tidy
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/internal/command/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// GetLogger returns a new FieldLogger and an associated Context derived from command context.
func GetLogger(cmd *cobra.Command, opts *option.Common) (context.Context, logrus.FieldLogger) {
ctx, logger := trace.NewLogger(cmd.Context(), opts.Debug, opts.Verbose)
ctx, logger := trace.NewLogger(cmd.Context(), opts.Debug)
cmd.SetContext(ctx)
return ctx, logger
}
13 changes: 9 additions & 4 deletions cmd/oras/internal/display/content/discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ package content

import ocispec "github.com/opencontainers/image-spec/specs-go/v1"

type discardHandler struct{}
type DiscardHandler struct{}

// OnContentFetched implements ManifestFetchHandler.
func (discardHandler) OnContentFetched(ocispec.Descriptor, []byte) error {
func (DiscardHandler) OnContentFetched(ocispec.Descriptor, []byte) error {
return nil
}

// OnContentCreated implements ManifestIndexCreateHandler.
func (DiscardHandler) OnContentCreated([]byte) error {
return nil
}

// NewDiscardHandler returns a new discard handler.
func NewDiscardHandler() ManifestFetchHandler {
return discardHandler{}
func NewDiscardHandler() DiscardHandler {
return DiscardHandler{}
}
9 changes: 9 additions & 0 deletions cmd/oras/internal/display/content/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ type ManifestFetchHandler interface {
// OnContentFetched is called after the manifest content is fetched.
OnContentFetched(desc ocispec.Descriptor, content []byte) error
}

// ManifestIndexCreateHandler handles raw output for manifest index create events.
type ManifestIndexCreateHandler interface {
// OnContentCreated is called after the index content is created.
OnContentCreated(content []byte) error
}

// ManifestIndexUpdateHandler handles raw output for manifest index update events.
type ManifestIndexUpdateHandler ManifestIndexCreateHandler
12 changes: 10 additions & 2 deletions cmd/oras/internal/display/content/manifest_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,29 @@ type manifestFetch struct {
outputPath string
}

func (h *manifestFetch) OnContentFetched(desc ocispec.Descriptor, manifest []byte) error {
func (h *manifestFetch) OnContentFetched(desc ocispec.Descriptor, manifest []byte) (eventErr error) {
out := h.stdout
if h.outputPath != "-" && h.outputPath != "" {
f, err := os.Create(h.outputPath)
if err != nil {
return fmt.Errorf("failed to open %q: %w", h.outputPath, err)
}
defer f.Close()
defer func() {
if err := f.Close(); eventErr == nil {
eventErr = err
}
}()
out = f
}
return output.PrintJSON(out, manifest, h.pretty)
}

// NewManifestFetchHandler creates a new handler.
func NewManifestFetchHandler(out io.Writer, pretty bool, outputPath string) ManifestFetchHandler {
// ignore --pretty when output to a file
if outputPath != "" && outputPath != "-" {
pretty = false
}
return &manifestFetch{
pretty: pretty,
stdout: out,
Expand Down
62 changes: 62 additions & 0 deletions cmd/oras/internal/display/content/manifest_index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package content

import (
"fmt"
"io"
"os"

"oras.land/oras/cmd/oras/internal/output"
)

// manifestIndexCreate handles raw content output.
type manifestIndexCreate struct {
pretty bool
stdout io.Writer
outputPath string
}

// NewManifestIndexCreateHandler creates a new handler.
func NewManifestIndexCreateHandler(out io.Writer, pretty bool, outputPath string) ManifestIndexCreateHandler {
// ignore --pretty when output to a file
if outputPath != "" && outputPath != "-" {
pretty = false
}
return &manifestIndexCreate{
pretty: pretty,
stdout: out,
outputPath: outputPath,
}
}

// OnContentCreated is called after index content is created.
func (h *manifestIndexCreate) OnContentCreated(manifest []byte) (eventErr error) {
out := h.stdout
if h.outputPath != "" && h.outputPath != "-" {
f, err := os.Create(h.outputPath)
if err != nil {
return fmt.Errorf("failed to open %q: %w", h.outputPath, err)
}
defer func() {
if err := f.Close(); eventErr == nil {
eventErr = err
}
}()
out = f
}
return output.PrintJSON(out, manifest, h.pretty)
}
28 changes: 28 additions & 0 deletions cmd/oras/internal/display/content/manifest_index_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package content

import (
"os"
"testing"
)

func Test_manifestIndexCreate_OnContentCreated(t *testing.T) {
testHandler := NewManifestIndexCreateHandler(os.Stdout, false, "invalid/path")
if err := testHandler.OnContentCreated([]byte("test content")); err == nil {
t.Errorf("manifestIndexCreate.OnContentCreated() error = %v, wantErr non-nil error", err)
}
}
53 changes: 47 additions & 6 deletions cmd/oras/internal/display/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,57 @@ func NewTagHandler(printer *output.Printer, target option.Target) metadata.TagHa
}

// NewManifestPushHandler returns a manifest push handler.
func NewManifestPushHandler(printer *output.Printer) metadata.ManifestPushHandler {
return text.NewManifestPushHandler(printer)
func NewManifestPushHandler(printer *output.Printer, outputDescriptor bool, pretty bool, desc ocispec.Descriptor, target *option.Target) (status.ManifestPushHandler, metadata.ManifestPushHandler) {
if outputDescriptor {
return status.NewDiscardHandler(), metadata.NewDiscardHandler()
}
return status.NewTextManifestPushHandler(printer, desc), text.NewManifestPushHandler(printer, target)
}

// NewManifestIndexCreateHandler returns status, metadata and content handlers for index create command.
func NewManifestIndexCreateHandler(outputPath string, printer *output.Printer, pretty bool) (status.ManifestIndexCreateHandler, metadata.ManifestIndexCreateHandler, content.ManifestIndexCreateHandler) {
var statusHandler status.ManifestIndexCreateHandler
var metadataHandler metadata.ManifestIndexCreateHandler
var contentHandler content.ManifestIndexCreateHandler
switch outputPath {
case "":
statusHandler = status.NewTextManifestIndexCreateHandler(printer)
metadataHandler = text.NewManifestIndexCreateHandler(printer)
contentHandler = content.NewDiscardHandler()
case "-":
statusHandler = status.NewDiscardHandler()
metadataHandler = metadata.NewDiscardHandler()
contentHandler = content.NewManifestIndexCreateHandler(printer, pretty, outputPath)
default:
statusHandler = status.NewTextManifestIndexCreateHandler(printer)
metadataHandler = text.NewManifestIndexCreateHandler(printer)
contentHandler = content.NewManifestIndexCreateHandler(printer, pretty, outputPath)
}
return statusHandler, metadataHandler, contentHandler
}

// NewManifestIndexCreateHandler returns an index create handler.
func NewManifestIndexCreateHandler(printer *output.Printer) metadata.ManifestIndexCreateHandler {
return text.NewManifestIndexCreateHandler(printer)
// NewManifestIndexUpdateHandler returns status, metadata and content handlers for index update command.
func NewManifestIndexUpdateHandler(outputPath string, printer *output.Printer, pretty bool) (
status.ManifestIndexUpdateHandler,
metadata.ManifestIndexUpdateHandler,
content.ManifestIndexUpdateHandler) {
statusHandler := status.NewTextManifestIndexUpdateHandler(printer)
metadataHandler := text.NewManifestIndexCreateHandler(printer)
contentHandler := content.NewManifestIndexCreateHandler(printer, pretty, outputPath)
switch outputPath {
case "":
contentHandler = content.NewDiscardHandler()
case "-":
statusHandler = status.NewDiscardHandler()
metadataHandler = metadata.NewDiscardHandler()
}
return statusHandler, metadataHandler, contentHandler
}

// NewCopyHandler returns copy handlers.
func NewCopyHandler(printer *output.Printer, fetcher fetcher.Fetcher) (status.CopyHandler, metadata.CopyHandler) {
func NewCopyHandler(printer *output.Printer, tty *os.File, fetcher fetcher.Fetcher) (status.CopyHandler, metadata.CopyHandler) {
if tty != nil {
return status.NewTTYCopyHandler(tty), text.NewCopyHandler(printer)
}
return status.NewTextCopyHandler(printer, fetcher), text.NewCopyHandler(printer)
}
30 changes: 26 additions & 4 deletions cmd/oras/internal/display/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ limitations under the License.
package display

import (
"oras.land/oras/internal/testutils"
"os"
"reflect"
"testing"

"oras.land/oras/internal/testutils"

"oras.land/oras/cmd/oras/internal/display/metadata/text"
"oras.land/oras/cmd/oras/internal/display/status"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/cmd/oras/internal/output"
)

func TestNewPushHandler(t *testing.T) {
mockFetcher := testutils.NewMockFetcher()
printer := output.NewPrinter(os.Stdout, os.Stderr, false)
printer := output.NewPrinter(os.Stdout, os.Stderr)
_, _, err := NewPushHandler(printer, option.Format{Type: option.FormatTypeText.Name}, os.Stdout, mockFetcher.Fetcher)
if err != nil {
t.Errorf("NewPushHandler() error = %v, want nil", err)
Expand All @@ -35,17 +39,35 @@ func TestNewPushHandler(t *testing.T) {

func TestNewAttachHandler(t *testing.T) {
mockFetcher := testutils.NewMockFetcher()
printer := output.NewPrinter(os.Stdout, os.Stderr, false)
printer := output.NewPrinter(os.Stdout, os.Stderr)
_, _, err := NewAttachHandler(printer, option.Format{Type: option.FormatTypeText.Name}, os.Stdout, mockFetcher.Fetcher)
if err != nil {
t.Errorf("NewAttachHandler() error = %v, want nil", err)
}
}

func TestNewPullHandler(t *testing.T) {
printer := output.NewPrinter(os.Stdout, os.Stderr, false)
printer := output.NewPrinter(os.Stdout, os.Stderr)
_, _, err := NewPullHandler(printer, option.Format{Type: option.FormatTypeText.Name}, "", os.Stdout)
if err != nil {
t.Errorf("NewPullHandler() error = %v, want nil", err)
}
}

func TestNewCopyHandler(t *testing.T) {
printer := output.NewPrinter(os.Stdout, os.Stderr)
copyHandler, copyMetadataHandler := NewCopyHandler(printer, os.Stdout, nil)
if _, ok := copyHandler.(*status.TTYCopyHandler); !ok {
t.Errorf("expected *status.TTYCopyHandler actual %v", reflect.TypeOf(copyHandler))
}
if _, ok := copyMetadataHandler.(*text.CopyHandler); !ok {
t.Errorf("expected metadata.CopyHandler actual %v", reflect.TypeOf(copyMetadataHandler))
}
copyHandler, copyMetadataHandler = NewCopyHandler(printer, nil, nil)
if _, ok := copyHandler.(*status.TextCopyHandler); !ok {
t.Errorf("expected *status.TextCopyHandler actual %v", reflect.TypeOf(copyHandler))
}
if _, ok := copyMetadataHandler.(*text.CopyHandler); !ok {
t.Errorf("expected metadata.CopyHandler actual %v", reflect.TypeOf(copyMetadataHandler))
}
}
Loading

0 comments on commit 8bd855f

Please sign in to comment.