Skip to content

Commit

Permalink
merge branch 'pr-51'
Browse files Browse the repository at this point in the history
LGTMs: @cyphar @xiekeyang
Closes #51
  • Loading branch information
cyphar committed Jul 21, 2017
2 parents 4edc8af + 3c7c0e7 commit b686775
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 84 deletions.
22 changes: 14 additions & 8 deletions cmd/oci-image-tool/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ var bundleTypes = []string{
}

type bundleCmd struct {
typ string // the type to bundle, can be empty string
ref string
root string
typ string // the type to bundle, can be empty string
ref string
root string
platform string
}

func createHandle(context *cli.Context) error {
Expand All @@ -40,9 +41,10 @@ func createHandle(context *cli.Context) error {
}

v := bundleCmd{
typ: context.String("type"),
ref: context.String("ref"),
root: context.String("rootfs"),
typ: context.String("type"),
ref: context.String("ref"),
root: context.String("rootfs"),
platform: context.String("platform"),
}

if v.typ == "" {
Expand All @@ -56,10 +58,10 @@ func createHandle(context *cli.Context) error {
var err error
switch v.typ {
case image.TypeImageLayout:
err = image.CreateRuntimeBundleLayout(context.Args()[0], context.Args()[1], v.ref, v.root)
err = image.CreateRuntimeBundleLayout(context.Args()[0], context.Args()[1], v.ref, v.root, v.platform)

case image.TypeImage:
err = image.CreateRuntimeBundleFile(context.Args()[0], context.Args()[1], v.ref, v.root)
err = image.CreateRuntimeBundleFile(context.Args()[0], context.Args()[1], v.ref, v.root, v.platform)

default:
err = fmt.Errorf("cannot create %q", v.typ)
Expand Down Expand Up @@ -95,5 +97,9 @@ var createCommand = cli.Command{
Value: "rootfs",
Usage: "A directory representing the root filesystem of the container in the OCI runtime bundle. It is strongly recommended to keep the default value.",
},
cli.StringFlag{
Name: "platform",
Usage: "Specify the os and architecture of the manifest, format is OS:Architecture. Only applicable if reftype is index.",
},
},
}
18 changes: 12 additions & 6 deletions cmd/oci-image-tool/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ var unpackTypes = []string{
}

type unpackCmd struct {
typ string // the type to unpack, can be empty string
ref string
typ string // the type to unpack, can be empty string
ref string
platform string
}

func unpackHandle(context *cli.Context) error {
Expand All @@ -39,8 +40,9 @@ func unpackHandle(context *cli.Context) error {
}

v := unpackCmd{
typ: context.String("type"),
ref: context.String("ref"),
typ: context.String("type"),
ref: context.String("ref"),
platform: context.String("platform"),
}

if v.typ == "" {
Expand All @@ -54,10 +56,10 @@ func unpackHandle(context *cli.Context) error {
var err error
switch v.typ {
case image.TypeImageLayout:
err = image.UnpackLayout(context.Args()[0], context.Args()[1], v.ref)
err = image.UnpackLayout(context.Args()[0], context.Args()[1], v.ref, v.platform)

case image.TypeImage:
err = image.UnpackFile(context.Args()[0], context.Args()[1], v.ref)
err = image.UnpackFile(context.Args()[0], context.Args()[1], v.ref, v.platform)

default:
err = fmt.Errorf("cannot unpack %q", v.typ)
Expand Down Expand Up @@ -86,5 +88,9 @@ var unpackCommand = cli.Command{
Value: "v1.0",
Usage: "The ref pointing to the manifest of the OCI image. This must be present in the 'refs' subdirectory of the image.",
},
cli.StringFlag{
Name: "platform",
Usage: "Specify the os and architecture of the manifest, format is OS:Architecture. Only applicable if reftype is index.",
},
},
}
4 changes: 2 additions & 2 deletions completions/bash/oci-image-tool
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ _oci-image-tool_create() {

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--type --ref --rootfs --help -h" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--type --ref --rootfs --platform --help -h" -- "$cur" ) )
;;
esac

Expand All @@ -166,7 +166,7 @@ _oci-image-tool_unpack() {

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--type --ref --help -h" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--type --ref --platform --help -h" -- "$cur" ) )
;;
esac

Expand Down
6 changes: 4 additions & 2 deletions image/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import (
"github.com/pkg/errors"
)

const indexPath = "index.json"

func listReferences(w walker) (map[string]*v1.Descriptor, error) {
refs := make(map[string]*v1.Descriptor)
var index v1.Index

if err := w.walk(func(path string, info os.FileInfo, r io.Reader) error {
if info.IsDir() || filepath.Clean(path) != "index.json" {
if info.IsDir() || filepath.Clean(path) != indexPath {
return nil
}

Expand All @@ -56,7 +58,7 @@ func findDescriptor(w walker, name string) (*v1.Descriptor, error) {
var index v1.Index

switch err := w.walk(func(path string, info os.FileInfo, r io.Reader) error {
if info.IsDir() || filepath.Clean(path) != "index.json" {
if info.IsDir() || filepath.Clean(path) != indexPath {
return nil
}

Expand Down
Loading

0 comments on commit b686775

Please sign in to comment.