Skip to content

Commit 1423c5e

Browse files
author
zhouhao
committed
merging of subcommands
Signed-off-by: zhouhao <[email protected]>
1 parent 4f63474 commit 1423c5e

File tree

14 files changed

+498
-541
lines changed

14 files changed

+498
-541
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/oci-create-runtime-bundle
2-
/oci-unpack
3-
/oci-image-validate
1+
/oci-image-tool
42

53
*.1

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ script:
2121
- make lint
2222
- make check-license
2323
- make test
24-
- make tools
24+
- make tool

Makefile

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
GO15VENDOREXPERIMENT=1
22
export GO15VENDOREXPERIMENT
3+
PREFIX ?= $(DESTDIR)/usr
4+
BINDIR ?= $(DESTDIR)/usr/bin
35

4-
COMMIT=$(shell git rev-parse HEAD 2> /dev/null || true)
5-
6-
EPOCH_TEST_COMMIT ?= v0.2.0
7-
TOOLS := \
8-
oci-create-runtime-bundle \
9-
oci-image-validate \
10-
oci-unpack
11-
MAN := $(TOOLS:%=%.1)
126

137
default: all
148

159
help:
1610
@echo "Usage: make <target>"
1711
@echo
18-
@echo " * 'all' - Build the oci tools and manual pages"
12+
@echo " * 'all' - Build the oci tool and manual pages"
13+
@echo " * 'tool' - Build the oci tool"
1914
@echo " * 'install' - Install binaries and manual pages"
20-
@echo " * 'install.tools' - Install tools needed for building this project"
21-
@echo " * 'uninstall' - Remove the oci tools and manual pages"
22-
@echo " * 'tools' - Build the oci image tools binaries"
15+
@echo " * 'install.tools' - Install tool needed for building this project"
16+
@echo " * 'uninstall' - Remove the oci tool and manual pages"
2317
@echo " * 'man' - Build the oci image manual pages"
2418
@echo " * 'check-license' - Check license headers in source files"
2519
@echo " * 'lint' - Execute the source code linter"
@@ -31,25 +25,33 @@ check-license:
3125
@echo "checking license headers"
3226
@./.tool/check-license
3327

34-
tools: $(TOOLS)
28+
.PHONY: tool
29+
tool:
30+
go build -o oci-image-tool ./cmd/oci-image-tool
3531

36-
man: $(MAN)
3732

38-
all: $(TOOLS) $(MAN)
33+
all: tool man
3934

40-
$(TOOLS): oci-%:
41-
go build -ldflags "-X main.gitCommit=${COMMIT}" ./cmd/$@
35+
.PHONY: man
36+
man:
37+
go-md2man -in "man/oci-image-tool.1.md" -out "oci-image-tool.1"
38+
go-md2man -in "man/oci-image-tool-create.1.md" -out "oci-image-tool-create.1"
39+
go-md2man -in "man/oci-image-tool-unpack.1.md" -out "oci-image-tool-unpack.1"
40+
go-md2man -in "man/oci-image-tool-validate.1.md" -out "oci-image-tool-validate.1"
4241

43-
.SECONDEXPANSION:
44-
$(MAN): %.1: cmd/$$*/$$*.1.md
45-
go-md2man -in "$<" -out "$@"
4642

47-
install: $(TOOLS) $(MAN)
48-
install -m 755 $(TOOLS) /usr/local/bin/
49-
install -m 644 $(MAN) /usr/local/share/man/man1
43+
install: man
44+
install -d -m 755 $(BINDIR)
45+
install -m 755 oci-image-tool $(BINDIR)
46+
install -d -m 755 $(PREFIX)/share/man/man1
47+
install -m 644 *.1 $(PREFIX)/share/man/man1
48+
install -d -m 755 $(PREFIX)/share/bash-completion/completions
49+
install -m 644 completions/bash/oci-image-tool $(PREFIX)/share/bash-completion/completionsn
5050

51-
uninstall: clean
52-
rm -f $(MAN:%=/usr/local/share/man/man1/%) $(TOOLS:%=/usr/local/bin/%)
51+
uninstall:
52+
rm -f $(BINDIR)/oci-image-tool
53+
rm -f $(PREFIX)/share/man/man1/oci-image-tool*.1
54+
rm -f $(PREFIX)/share/bash-completion/completions/oci-image-tool
5355

5456
lint:
5557
@echo "checking lint"
@@ -58,6 +60,7 @@ lint:
5860
test:
5961
go test -race -cover $(shell go list ./... | grep -v /vendor/)
6062

63+
6164
## this uses https://github.com/Masterminds/glide and https://github.com/sgotti/glide-vc
6265
update-deps:
6366
@which glide > /dev/null 2>/dev/null || (echo "ERROR: glide not found. Consider 'make install.tools' target" && false)
@@ -98,12 +101,11 @@ install.tools: .install.gitvalidation .install.glide .install.glide-vc .install.
98101
go get github.com/cpuguy83/go-md2man
99102

100103
clean:
101-
rm -rf *~ $(OUTPUT_DIRNAME) $(TOOLS) $(MAN)
104+
rm -rf oci-image-tool *.1
102105

103106
.PHONY: \
104107
all \
105-
tools \
106-
$(TOOLS) \
108+
tool \
107109
man \
108110
install \
109111
uninstall \

cmd/oci-create-runtime-bundle/main.go

Lines changed: 0 additions & 152 deletions
This file was deleted.

cmd/oci-image-tool/create.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2016 The Linux Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
21+
"github.com/opencontainers/image-tools/image"
22+
"github.com/urfave/cli"
23+
)
24+
25+
// supported bundle types
26+
var bundleTypes = []string{
27+
image.TypeImageLayout,
28+
image.TypeImage,
29+
}
30+
31+
type bundleCmd struct {
32+
typ string // the type to bundle, can be empty string
33+
ref string
34+
root string
35+
}
36+
37+
func createHandle(context *cli.Context) error {
38+
if len(context.Args()) != 2 {
39+
return fmt.Errorf("both src and dest must be provided")
40+
}
41+
42+
var v bundleCmd
43+
if context.IsSet("type") {
44+
v.typ = context.String("type")
45+
}
46+
if context.IsSet("ref") {
47+
v.ref = context.String("ref")
48+
}
49+
if context.IsSet("rootfs") {
50+
v.root = context.String("roofs")
51+
}
52+
53+
if v.typ == "" {
54+
typ, err := image.Autodetect(context.Args()[0])
55+
if err != nil {
56+
return fmt.Errorf("%q: autodetection failed: %v", context.Args()[0], err)
57+
}
58+
v.typ = typ
59+
}
60+
61+
var err error
62+
switch v.typ {
63+
case image.TypeImageLayout:
64+
err = image.CreateRuntimeBundleLayout(context.Args()[0], context.Args()[1], v.ref, v.root)
65+
66+
case image.TypeImage:
67+
err = image.CreateRuntimeBundle(context.Args()[0], context.Args()[1], v.ref, v.root)
68+
69+
default:
70+
err = fmt.Errorf("cannot create %q", v.typ)
71+
72+
}
73+
74+
if err != nil {
75+
fmt.Printf("creating failed: %v\n", err)
76+
}
77+
78+
return err
79+
}
80+
81+
var createCommand = cli.Command{
82+
Name: "create",
83+
Usage: "Create an OCI image runtime bundle",
84+
Action: createHandle,
85+
Flags: []cli.Flag{
86+
cli.StringFlag{
87+
Name: "type",
88+
Usage: fmt.Sprintf(
89+
`Type of the file to unpack. If unset, oci-image-tool-validate will try to auto-detect the type. One of "%s".`,
90+
strings.Join(bundleTypes, ","),
91+
),
92+
},
93+
cli.StringFlag{
94+
Name: "ref",
95+
Value: "v1.0",
96+
Usage: "The ref pointing to the manifest of the OCI image. This must be present in the 'refs' subdirectory of the image.",
97+
},
98+
cli.StringFlag{
99+
Name: "rootfs",
100+
Value: "rootfs",
101+
Usage: "A directory representing the root filesystem of the container in the OCI runtime bundle. It is strongly recommended to keep the default value.",
102+
},
103+
},
104+
}

0 commit comments

Comments
 (0)