Skip to content

Commit b686775

Browse files
committed
merge branch 'pr-51'
LGTMs: @cyphar @xiekeyang Closes #51
2 parents 4edc8af + 3c7c0e7 commit b686775

File tree

9 files changed

+351
-84
lines changed

9 files changed

+351
-84
lines changed

cmd/oci-image-tool/create.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ var bundleTypes = []string{
2929
}
3030

3131
type bundleCmd struct {
32-
typ string // the type to bundle, can be empty string
33-
ref string
34-
root string
32+
typ string // the type to bundle, can be empty string
33+
ref string
34+
root string
35+
platform string
3536
}
3637

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

4243
v := bundleCmd{
43-
typ: context.String("type"),
44-
ref: context.String("ref"),
45-
root: context.String("rootfs"),
44+
typ: context.String("type"),
45+
ref: context.String("ref"),
46+
root: context.String("rootfs"),
47+
platform: context.String("platform"),
4648
}
4749

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

6163
case image.TypeImage:
62-
err = image.CreateRuntimeBundleFile(context.Args()[0], context.Args()[1], v.ref, v.root)
64+
err = image.CreateRuntimeBundleFile(context.Args()[0], context.Args()[1], v.ref, v.root, v.platform)
6365

6466
default:
6567
err = fmt.Errorf("cannot create %q", v.typ)
@@ -95,5 +97,9 @@ var createCommand = cli.Command{
9597
Value: "rootfs",
9698
Usage: "A directory representing the root filesystem of the container in the OCI runtime bundle. It is strongly recommended to keep the default value.",
9799
},
100+
cli.StringFlag{
101+
Name: "platform",
102+
Usage: "Specify the os and architecture of the manifest, format is OS:Architecture. Only applicable if reftype is index.",
103+
},
98104
},
99105
}

cmd/oci-image-tool/unpack.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ var unpackTypes = []string{
2929
}
3030

3131
type unpackCmd struct {
32-
typ string // the type to unpack, can be empty string
33-
ref string
32+
typ string // the type to unpack, can be empty string
33+
ref string
34+
platform string
3435
}
3536

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

4142
v := unpackCmd{
42-
typ: context.String("type"),
43-
ref: context.String("ref"),
43+
typ: context.String("type"),
44+
ref: context.String("ref"),
45+
platform: context.String("platform"),
4446
}
4547

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

5961
case image.TypeImage:
60-
err = image.UnpackFile(context.Args()[0], context.Args()[1], v.ref)
62+
err = image.UnpackFile(context.Args()[0], context.Args()[1], v.ref, v.platform)
6163

6264
default:
6365
err = fmt.Errorf("cannot unpack %q", v.typ)
@@ -86,5 +88,9 @@ var unpackCommand = cli.Command{
8688
Value: "v1.0",
8789
Usage: "The ref pointing to the manifest of the OCI image. This must be present in the 'refs' subdirectory of the image.",
8890
},
91+
cli.StringFlag{
92+
Name: "platform",
93+
Usage: "Specify the os and architecture of the manifest, format is OS:Architecture. Only applicable if reftype is index.",
94+
},
8995
},
9096
}

completions/bash/oci-image-tool

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ _oci-image-tool_create() {
150150

151151
case "$cur" in
152152
-*)
153-
COMPREPLY=( $( compgen -W "--type --ref --rootfs --help -h" -- "$cur" ) )
153+
COMPREPLY=( $( compgen -W "--type --ref --rootfs --platform --help -h" -- "$cur" ) )
154154
;;
155155
esac
156156

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

167167
case "$cur" in
168168
-*)
169-
COMPREPLY=( $( compgen -W "--type --ref --help -h" -- "$cur" ) )
169+
COMPREPLY=( $( compgen -W "--type --ref --platform --help -h" -- "$cur" ) )
170170
;;
171171
esac
172172

image/descriptor.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import (
2525
"github.com/pkg/errors"
2626
)
2727

28+
const indexPath = "index.json"
29+
2830
func listReferences(w walker) (map[string]*v1.Descriptor, error) {
2931
refs := make(map[string]*v1.Descriptor)
3032
var index v1.Index
3133

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

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

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

0 commit comments

Comments
 (0)