Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/oci-create-runtime-bundle
/oci-unpack
/oci-image-validate
/oci-image-tool

*.1
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ script:
- make lint
- make check-license
- make test
- make tools
- make tool
58 changes: 30 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
GO15VENDOREXPERIMENT=1
export GO15VENDOREXPERIMENT
PREFIX ?= $(DESTDIR)/usr
BINDIR ?= $(DESTDIR)/usr/bin

COMMIT=$(shell git rev-parse HEAD 2> /dev/null || true)

EPOCH_TEST_COMMIT ?= v0.2.0
TOOLS := \
oci-create-runtime-bundle \
oci-image-validate \
oci-unpack
MAN := $(TOOLS:%=%.1)

default: all

help:
@echo "Usage: make <target>"
@echo
@echo " * 'all' - Build the oci tools and manual pages"
@echo " * 'all' - Build the oci tool and manual pages"
@echo " * 'tool' - Build the oci tool"
@echo " * 'install' - Install binaries and manual pages"
@echo " * 'install.tools' - Install tools needed for building this project"
@echo " * 'uninstall' - Remove the oci tools and manual pages"
@echo " * 'tools' - Build the oci image tools binaries"
@echo " * 'install.tools' - Install tool needed for building this project"
@echo " * 'uninstall' - Remove the oci tool and manual pages"
@echo " * 'man' - Build the oci image manual pages"
@echo " * 'check-license' - Check license headers in source files"
@echo " * 'lint' - Execute the source code linter"
Expand All @@ -31,25 +25,33 @@ check-license:
@echo "checking license headers"
@./.tool/check-license

tools: $(TOOLS)
.PHONY: tool
tool:
go build -o oci-image-tool ./cmd/oci-image-tool

man: $(MAN)

all: $(TOOLS) $(MAN)
all: tool man

$(TOOLS): oci-%:
go build -ldflags "-X main.gitCommit=${COMMIT}" ./cmd/$@
.PHONY: man
man:
go-md2man -in "man/oci-image-tool.1.md" -out "oci-image-tool.1"
go-md2man -in "man/oci-image-tool-create.1.md" -out "oci-image-tool-create.1"
go-md2man -in "man/oci-image-tool-unpack.1.md" -out "oci-image-tool-unpack.1"
go-md2man -in "man/oci-image-tool-validate.1.md" -out "oci-image-tool-validate.1"

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

install: $(TOOLS) $(MAN)
install -m 755 $(TOOLS) /usr/local/bin/
install -m 644 $(MAN) /usr/local/share/man/man1
install: man
install -d -m 755 $(BINDIR)
install -m 755 oci-image-tool $(BINDIR)
install -d -m 755 $(PREFIX)/share/man/man1
install -m 644 *.1 $(PREFIX)/share/man/man1
install -d -m 755 $(PREFIX)/share/bash-completion/completions
install -m 644 completions/bash/oci-image-tool $(PREFIX)/share/bash-completion/completionsn

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

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


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

clean:
rm -rf *~ $(OUTPUT_DIRNAME) $(TOOLS) $(MAN)
rm -rf oci-image-tool *.1

.PHONY: \
all \
tools \
$(TOOLS) \
tool \
man \
install \
uninstall \
Expand Down
152 changes: 0 additions & 152 deletions cmd/oci-create-runtime-bundle/main.go

This file was deleted.

104 changes: 104 additions & 0 deletions cmd/oci-image-tool/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2016 The Linux Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"strings"

"github.com/opencontainers/image-tools/image"
"github.com/urfave/cli"
)

// supported bundle types
var bundleTypes = []string{
image.TypeImageLayout,
image.TypeImage,
}

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

func createHandle(context *cli.Context) error {
if len(context.Args()) != 2 {
return fmt.Errorf("both src and dest must be provided")
}

var v bundleCmd
if context.IsSet("type") {
v.typ = context.String("type")
}
if context.IsSet("ref") {
v.ref = context.String("ref")
}
if context.IsSet("rootfs") {
v.root = context.String("roofs")
}

if v.typ == "" {
typ, err := image.Autodetect(context.Args()[0])
if err != nil {
return fmt.Errorf("%q: autodetection failed: %v", context.Args()[0], err)
}
v.typ = typ
}

var err error
switch v.typ {
case image.TypeImageLayout:
err = image.CreateRuntimeBundleLayout(context.Args()[0], context.Args()[1], v.ref, v.root)

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

default:
err = fmt.Errorf("cannot create %q", v.typ)

}

if err != nil {
fmt.Printf("creating failed: %v\n", err)
}

return err
}

var createCommand = cli.Command{
Name: "create",
Usage: "Create an OCI image runtime bundle",
Action: createHandle,
Flags: []cli.Flag{
cli.StringFlag{
Name: "type",
Usage: fmt.Sprintf(
`Type of the file to unpack. If unset, oci-image-tool-validate will try to auto-detect the type. One of "%s".`,
strings.Join(bundleTypes, ","),
),
},
cli.StringFlag{
Name: "ref",
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: "rootfs",
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.",
},
},
}
Loading