Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit 90d1ef6

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

File tree

14 files changed

+485
-520
lines changed

14 files changed

+485
-520
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+
20+
"github.com/opencontainers/image-tools/image"
21+
"github.com/urfave/cli"
22+
)
23+
24+
// supported bundle types
25+
var bundleTypes = []string{
26+
image.TypeImageLayout,
27+
image.TypeImage,
28+
}
29+
30+
type bundleCmd struct {
31+
typ string // the type to bundle, can be empty string
32+
ref string
33+
root string
34+
}
35+
36+
func createHandle(context *cli.Context) error {
37+
if len(context.Args()) != 2 {
38+
return fmt.Errorf("both src and dest must be provided")
39+
}
40+
41+
var v bundleCmd
42+
if context.IsSet("type") {
43+
v.typ = context.String("type")
44+
}
45+
if context.IsSet("ref") {
46+
v.ref = context.String("ref")
47+
}
48+
if context.IsSet("rootfs") {
49+
v.root = context.String("roofs")
50+
}
51+
52+
if v.typ == "" {
53+
typ, err := image.Autodetect(context.Args()[0])
54+
if err != nil {
55+
return fmt.Errorf("%q: autodetection failed: %v", context.Args()[0], err)
56+
}
57+
v.typ = typ
58+
}
59+
60+
var err error
61+
switch v.typ {
62+
case image.TypeImageLayout:
63+
err = image.CreateRuntimeBundleLayout(context.Args()[0], context.Args()[1], v.ref, v.root)
64+
65+
case image.TypeImage:
66+
err = image.CreateRuntimeBundle(context.Args()[0], context.Args()[1], v.ref, v.root)
67+
68+
default:
69+
err = fmt.Errorf("cannot create %q", v.typ)
70+
71+
}
72+
73+
if err != nil {
74+
fmt.Printf("creating failed: %v\n", err)
75+
}
76+
77+
return err
78+
}
79+
80+
var createCommand = cli.Command{
81+
Name: "create",
82+
Usage: "Create an OCI image runtime bundle",
83+
Before: before,
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)