Skip to content

Commit

Permalink
Changes for 0.2.0 release (oras-project#18)
Browse files Browse the repository at this point in the history
* prepare for 0.2.0 release

* fix example

* use custom mediatype in example
  • Loading branch information
jdolitsky authored Dec 28, 2018
1 parent cf59c2b commit 3e12356
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 25 deletions.
37 changes: 37 additions & 0 deletions .codefresh/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Note: must set env var GITHUB_TOKEN for goreleaser
version: '1.0'
stages:
- test
- build
- release
steps:
UnitTest:
title: Run unit tests
stage: test
image: golang:1.11
working_directory: &workdir /go/src/github.com/${{CF_REPO_OWNER}}
commands:
- &link ln -s /codefresh/volume/${{CF_REPO_NAME}} ${{CF_REPO_NAME}} && cd ${{CF_REPO_NAME}}
- echo make test
BuildDockerImage:
title: Build Docker image
stage: build
type: build
image_name: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
UploadReleaseArtifacts:
title: Upload release artifacts
stage: release
image: goreleaser/goreleaser:v0.95.0
working_directory: *workdir
commands:
- *link
- git checkout tags/${{CF_BRANCH_TAG_NORMALIZED}}
- goreleaser --rm-dist
PushDockerImageTagged:
title: Push Docker image (tag)
stage: release
type: push
candidate: ${{BuildDockerImage}}
image_name: ocistorage/${{CF_REPO_NAME}}
tag: ${{CF_BRANCH_TAG_NORMALIZED}}
registry: dockerhub
9 changes: 6 additions & 3 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

## Cutting a new release

Use [goreleaser](https://goreleaser.com/):

Example of releasing `v0.1.0`:
```
git tag -a v0.1.0 -m "Release v0.1.0"
git push origin v0.1.0
goreleaser
```

A Codefresh pipeline will pick up the GitHub tag event
and run [.codefresh/release.yml](.codefresh/release.yml).

This will result in running [goreleaser](https://goreleaser.com/)
to upload release artiacts, as well as push a tag to Docker Hub for
the image `ocistorage/oras`.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,39 @@ Public image is available on [Docker Hub](https://hub.docker.com/r/ocistorage/or
#### Run on Mac/Linux
```
docker run --rm -it -v $(pwd):/workplace ocistorage/oras:latest \
pull localhost:5000/hello:latest
pull localhost:5000/hello:v0.2.0
```

#### Run on Windows PowerShell
```
docker run --rm -it -v ${pwd}:/workplace ocistorage/oras:latest \
pull localhost:5000/hello:latest
pull localhost:5000/hello:v0.2.0
```

#### Run on Windows Commands
```
docker run --rm -it -v %cd%:/workplace ocistorage/oras:latest \
pull localhost:5000/hello:latest
pull localhost:5000/hello:v0.2.0
```

### Install the binary

Install from latest release (v0.1.0):
Install from latest release (v0.2.0):

```
# on Linux
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.1.0/oras_0.1.0_linux_amd64.tar.gz
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.2.0/oras_0.2.0_linux_amd64.tar.gz
# on macOS
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.1.0/oras_0.1.0_darwin_amd64.tar.gz
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.2.0/oras_0.2.0_darwin_amd64.tar.gz
# on Windows
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.1.0/oras_0.1.0_windows_amd64.tar.gz
curl -LO https://github.com/shizhMSFT/oras/releases/download/v0.2.0/oras_0.2.0_windows_amd64.tar.gz
mkdir -p oras/
tar -zxf oras_0.1.0_*.tar.gz -C oras/
tar -zxf oras_0.2.0_*.tar.gz -C oras/
mv oras/bin/oras /usr/local/bin/
rm -rf oras_0.1.0_*.tar.gz oras/
rm -rf oras_0.2.0_*.tar.gz oras/
```

Then, to run:
Expand All @@ -85,7 +85,7 @@ Then, to run:
oras help
```

The checksums for the `.tar.gz` files above can be found [here](https://github.com/shizhMSFT/oras/releases/tag/v0.1.0).
The checksums for the `.tar.gz` files above can be found [here](https://github.com/shizhMSFT/oras/releases/tag/v0.2.0).


## Go Module
Expand All @@ -103,9 +103,10 @@ package main
import (
"context"
"fmt"
"io/ioutil"

"github.com/containerd/containerd/remotes/docker"
"github.com/shizhMSFT/oras/pkg/oras"
"io/ioutil"
)

func check(e error) {
Expand All @@ -118,23 +119,28 @@ func main() {
ref := "localhost:5000/oras:test"
fileName := "hello.txt"
fileContent := []byte("Hello World!\n")
customMediaType := "my.custom.media.type"

ctx := context.Background()
resolver := docker.NewResolver(docker.ResolverOptions{})

// Push file(s) to registry
pushContents := make(map[string][]byte)
pushContents[fileName] = fileContent
// Push file(s) w custom mediatype to registry
pushContents := make(map[string]oras.Blob)
pushContents[fileName] = oras.Blob{
Content: fileContent,
MediaType: customMediaType,
}
fmt.Printf("Pushing %s to %s... ", fileName, ref)
err := oras.Push(ctx, resolver, ref, pushContents)
check(err)
fmt.Println("success!")

// Pull file(s) from registry and save to disk
fmt.Printf("Pulling from %s and saving to %s... ", ref, fileName)
pullContents, err := oras.Pull(ctx, resolver, ref)
allowedMediaTypes := []string{customMediaType}
pullContents, err := oras.Pull(ctx, resolver, ref, allowedMediaTypes...)
check(err)
err = ioutil.WriteFile(fileName, pullContents[fileName], 0644)
err = ioutil.WriteFile(fileName, pullContents[fileName].Content, 0644)
check(err)
fmt.Println("success!")
fmt.Printf("Try running 'cat %s'\n", fileName)
Expand Down
18 changes: 12 additions & 6 deletions examples/simple_push_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import (
"context"
"fmt"
"io/ioutil"

"github.com/containerd/containerd/remotes/docker"
"github.com/shizhMSFT/oras/pkg/oras"
"io/ioutil"
)

func check(e error) {
Expand All @@ -18,23 +19,28 @@ func main() {
ref := "localhost:5000/oras:test"
fileName := "hello.txt"
fileContent := []byte("Hello World!\n")
customMediaType := "my.custom.media.type"

ctx := context.Background()
resolver := docker.NewResolver(docker.ResolverOptions{})

// Push file(s) to registry
pushContents := make(map[string][]byte)
pushContents[fileName] = fileContent
// Push file(s) w custom mediatype to registry
pushContents := make(map[string]oras.Blob)
pushContents[fileName] = oras.Blob{
Content: fileContent,
MediaType: customMediaType,
}
fmt.Printf("Pushing %s to %s... ", fileName, ref)
err := oras.Push(ctx, resolver, ref, pushContents)
check(err)
fmt.Println("success!")

// Pull file(s) from registry and save to disk
fmt.Printf("Pulling from %s and saving to %s... ", ref, fileName)
pullContents, err := oras.Pull(ctx, resolver, ref)
allowedMediaTypes := []string{customMediaType}
pullContents, err := oras.Pull(ctx, resolver, ref, allowedMediaTypes...)
check(err)
err = ioutil.WriteFile(fileName, pullContents[fileName], 0644)
err = ioutil.WriteFile(fileName, pullContents[fileName].Content, 0644)
check(err)
fmt.Println("success!")
fmt.Printf("Try running 'cat %s'\n", fileName)
Expand Down

0 comments on commit 3e12356

Please sign in to comment.