Skip to content

Commit

Permalink
Merge branch 'master' into pass-through-writer
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Deitcher <avi@deitcher.net>
  • Loading branch information
jdolitsky authored and deitch committed Oct 5, 2020
2 parents bfb413b + 6414398 commit 11fb40a
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 2 deletions.
23 changes: 23 additions & 0 deletions implementors.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ See [OCI Artifacts][artifacts] for how to add OCI Artifacts support to your regi
- [docker/distribution](#docker-distribution) - local/offline verification
- [Azure Container Registry](#azure-container-registry-acr)
- [Amazon Elastic Container Registry](#amazon-elastic-container-registry-ecr)
- [Google Artifact Registry](#google-artifact-registry-gar)

## Artifact Types Using ORAS

Expand Down Expand Up @@ -234,6 +235,28 @@ ACR Artifact Documentation: [aka.ms/acr/artifacts](https://aka.ms/acr/artifacts)
--media-type application/vnd.unknown.layer.v1+txt
```

### [Google Artifact Registry (GAR)](https://cloud.google.com/artifact-registry)

- Authenticating with GAR using the gcloud command-line tool

```sh
gcloud auth configure-docker ${REGION}-docker.pkg.dev
```

- Pushing Artifacts to GAR

```sh
oras push ${REGION}-docker.pkg.dev/${GCP_PROJECT}/samples/artifact:1.0 \
./artifact.txt:application/vnd.unknown.layer.v1+txt
```

- Pulling Artifacts from GAR

```sh
oras pull ${REGION}-docker.pkg.dev/${GCP_PROJECT}/samples/artifact:1.0 \
--media-type application/vnd.unknown.layer.v1+txt
```

## Adding Your Registry or Artifact Type

Do you support [OCI Artifacts][artifacts] and would like your registry and/or project listed here? Please [submit a PR](https://github.com/deislabs/oras/pulls), using similar formatting above. We're happy to promote all usage, as well as feedback.
Expand Down
2 changes: 1 addition & 1 deletion pkg/content/iowriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewIoContentWriter(writer io.Writer, blocksize int) content.Writer {
blocksize: blocksize,
}
return NewPassthroughWriter(ioc, func(pw *PassthroughWriter) {
// write out the uncompressed data
// write out the data to the io writer
var (
err error
n int
Expand Down
2 changes: 1 addition & 1 deletion pkg/content/passthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (pw *PassthroughWriter) Commit(ctx context.Context, size int64, expected di
pw.pipew.Close()
err := <-pw.Done
pw.Reader.Close()
if err != nil {
if err != nil && err != io.EOF {
return err
}
return pw.writer.Commit(ctx, pw.underlyingSize, pw.underlyingDigester.Digest(), opts...)
Expand Down
104 changes: 104 additions & 0 deletions pkg/content/passthrough_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package content_test

import (
"context"
"fmt"
"io"
"testing"

ctrcontent "github.com/containerd/containerd/content"
"github.com/deislabs/oras/pkg/content"
digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

var (
testRef = "abc123"
testContent = []byte("Hello World!")
appendText = "1"
modifiedContent = fmt.Sprintf("%s%s", testContent, appendText)
testDescriptor = ocispec.Descriptor{
MediaType: ocispec.MediaTypeImageConfig,
Digest: digest.FromBytes(testContent),
Size: int64(len(testContent)),
Annotations: map[string]string{
ocispec.AnnotationTitle: testRef,
},
}
modifiedDescriptor = ocispec.Descriptor{
MediaType: ocispec.MediaTypeImageConfig,
Digest: digest.FromBytes([]byte(modifiedContent)),
Size: int64(len(modifiedContent)),
Annotations: map[string]string{
ocispec.AnnotationTitle: testRef,
},
}
)

func TestPassthroughWriter(t *testing.T) {
// simple pass through function that modifies the data just slightly
f := func(pw *content.PassthroughWriter) {
var (
err error
n int
)
for {
b := make([]byte, 1024)
n, err = pw.Reader.Read(b)
if err != nil && err != io.EOF {
t.Fatalf("data read error: %v", err)
break
}
l := n
if n > len(b) {
l = len(b)
}

// we change it just slightly
b = b[:l]
if l > 0 {
b = append(b, 0x31)
}
if err := pw.UnderlyingWrite(b); err != nil {
t.Fatalf("error writing to underlying writer: %v", err)
break
}
if err == io.EOF {
break
}
}
pw.Done <- err
}
ctx := context.Background()
mem := content.NewMemoryStore()
memw, err := mem.Writer(ctx, ctrcontent.WithDescriptor(modifiedDescriptor))
if err != nil {
t.Fatalf("unexpected error getting the memory store writer: %v", err)
}
writer := content.NewPassthroughWriter(memw, f)
n, err := writer.Write(testContent)
if err != nil {
t.Fatalf("unexpected error on Write: %v", err)
}
if n != len(testContent) {
t.Fatalf("wrote %d bytes instead of %d", n, len(testContent))
}
if err := writer.Commit(ctx, testDescriptor.Size, testDescriptor.Digest); err != nil {
t.Errorf("unexpected error on Commit: %v", err)
}
if digest := writer.Digest(); digest != testDescriptor.Digest {
t.Errorf("mismatched digest: actual %v, expected %v", digest, testDescriptor.Digest)
}

// make sure the data is what we expected
_, b, found := mem.Get(modifiedDescriptor)
if !found {
t.Fatalf("target descriptor not found in underlying memory store")
}
if len(b) != len(modifiedContent) {
t.Errorf("unexpectedly got %d bytes instead of expected %d", len(b), len(modifiedContent))
}
if string(b) != modifiedContent {
t.Errorf("mismatched content, expected '%s', got '%s'", modifiedContent, string(b))
}
}

0 comments on commit 11fb40a

Please sign in to comment.