Permalink
Browse files

Drop image tools (cmd/ and image/)

These have been spun off into [1].

# glide.yaml

* Drop runtime-spec (the last reference was removed with
  image/config.go).
* Drop cobra (the last references were removed with cmd/).

# HACKING

The http/FileSystem stuff still applies, since the JSON Schema
validation is staying in this repo.  I've made it's earlier
oci-image-tool references more generic, and adopted the README's
recommended one sentence per line where I touched a line.

[1]: https://github.com/opencontainers/image-tools

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information...
1 parent d4ca161 commit dae341ebc89aff4c75d016b04832c65ec19cef27 @wking wking committed Sep 21, 2016
View
@@ -1,4 +1,3 @@
code-of-conduct.md
-/oci-image-tool
/oci-validate-examples
output
View
@@ -24,5 +24,4 @@ script:
- make lint
- make check-license
- make test
- - make oci-image-tool
- make docs
View
@@ -33,20 +33,13 @@ $ make test
$ make validate-examples
```
-### OCI image tool
-
-This target builds the `oci-image-tool` binary.
-
-Invocation:
-```
-$ make oci-image-tool
-```
-
### Virtual schema http/FileSystem
-The `oci-image-tool` uses a virtual [http/FileSystem](https://golang.org/pkg/net/http/#FileSystem) to load the JSON schema files for validating OCI images and/or manifests. The virtual file system is generated using the `esc` tool and compiled into the `oci-image-tool` binary so the JSON schema files don't have to be distributed along with the binary.
+The `schema` validator uses a virtual [http/FileSystem](https://golang.org/pkg/net/http/#FileSystem) to load the JSON schema files for validating OCI images and/or manifests.
+The virtual file system is generated using the `esc` tool and compiled into consumers of the `schema` package so the JSON schema files don't have to be distributed along with and consumer binaries.
-Whenever changes are being done in any of the `schema/*.json` files, one must refresh the generated virtual file system. Otherwise schema changes will not be visible inside the `oci-image-tool`.
+Whenever changes are being done in any of the `schema/*.json` files, one must refresh the generated virtual file system.
+Otherwise schema changes will not be visible inside `schema` consumers.
Prerequisites:
* [esc](https://github.com/mjibson/esc)
View
@@ -49,7 +49,6 @@ help:
@echo " * 'docs' - produce document in the $(OUTPUT_DIRNAME) directory"
@echo " * 'fmt' - format the json with indentation"
@echo " * 'validate-examples' - validate the examples in the specification markdown files"
- @echo " * 'oci-image-tool' - build the oci-image-tool binary"
@echo " * 'schema-fs' - regenerate the virtual schema http/FileSystem"
@echo " * 'check-license' - check license headers in source files"
@echo " * 'lint' - Execute the source code linter"
@@ -84,9 +83,6 @@ code-of-conduct.md:
validate-examples:
go test -run TestValidate ./schema
-oci-image-tool:
- go build ./cmd/oci-image-tool
-
schema-fs:
@echo "generating schema fs"
@cd schema && printf "%s\n\n%s\n" "$$(cat ../.header)" "$$(go generate)" > fs.go
@@ -139,11 +135,9 @@ install.tools: .install.gitvalidation .install.glide .install.glide-vc
clean:
rm -rf *~ $(OUTPUT_DIRNAME)
- rm -f oci-image-tool
.PHONY: \
validate-examples \
- oci-image-tool \
check-license \
clean \
lint \
@@ -1,24 +0,0 @@
-# oci-image-tool
-
-A tool for working with OCI images
-
-## Building
-
-This project uses the Go programming language and is tested with the [Go
-compiler](https://golang.org/dl/). (Results with gccgo may vary)
-
-Install from a particular version of this repo (i.e. the v0.4.0 tag):
-
-```bash
-go get -u -d github.com/opencontainers/image-spec
-cd $GOPATH/src/github.com/opencontainers/image-spec
-git checkout -f v0.4.0
-go install github.com/opencontainers/image-spec/cmd/oci-image-tool
-```
-
-While the tool may be `go get`'able, it is encouraged that it is only used per
-tagged releases.
-
-## Usage
-
-See the tool's own `--help` output.
@@ -1,112 +0,0 @@
-// 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 (
- "encoding/json"
- "io"
- "io/ioutil"
- "net/http"
- "os"
-
- "github.com/opencontainers/image-spec/schema"
- "github.com/pkg/errors"
-)
-
-// supported autodetection types
-const (
- typeImageLayout = "imageLayout"
- typeImage = "image"
- typeManifest = "manifest"
- typeManifestList = "manifestList"
- typeConfig = "config"
-)
-
-// autodetect detects the validation type for the given path
-// or an error if the validation type could not be resolved.
-func autodetect(path string) (string, error) {
- fi, err := os.Stat(path)
- if err != nil {
- return "", errors.Wrapf(err, "unable to access path") // err from os.Stat includes path name
- }
-
- if fi.IsDir() {
- return typeImageLayout, nil
- }
-
- f, err := os.Open(path)
- if err != nil {
- return "", errors.Wrap(err, "unable to open file") // os.Open includes the filename
- }
- defer f.Close()
-
- buf, err := ioutil.ReadAll(io.LimitReader(f, 512)) // read some initial bytes to detect content
- if err != nil {
- return "", errors.Wrap(err, "unable to read")
- }
-
- mimeType := http.DetectContentType(buf)
-
- switch mimeType {
- case "application/x-gzip":
- return typeImage, nil
-
- case "application/octet-stream":
- return typeImage, nil
-
- case "text/plain; charset=utf-8":
- // might be a JSON file, will be handled below
-
- default:
- return "", errors.New("unknown file type")
- }
-
- if _, err := f.Seek(0, os.SEEK_SET); err != nil {
- return "", errors.Wrap(err, "unable to seek")
- }
-
- header := struct {
- SchemaVersion int `json:"schemaVersion"`
- MediaType string `json:"mediaType"`
- Config interface{} `json:"config"`
- }{}
-
- if err := json.NewDecoder(f).Decode(&header); err != nil {
- if _, errSeek := f.Seek(0, os.SEEK_SET); errSeek != nil {
- return "", errors.Wrap(err, "unable to seek")
- }
-
- e := errors.Wrap(
- schema.WrapSyntaxError(f, err),
- "unable to parse JSON",
- )
-
- return "", e
- }
-
- switch {
- case header.MediaType == string(schema.MediaTypeManifest):
- return typeManifest, nil
-
- case header.MediaType == string(schema.MediaTypeManifestList):
- return typeManifestList, nil
-
- case header.MediaType == "" && header.SchemaVersion == 0 && header.Config != nil:
- // config files don't have mediaType/schemaVersion header
- return typeConfig, nil
- }
-
- return "", errors.New("unknown media type")
-}
@@ -1,114 +0,0 @@
-// 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"
- "log"
- "os"
- "strings"
-
- "github.com/opencontainers/image-spec/image"
- "github.com/spf13/cobra"
-)
-
-// supported bundle types
-var bundleTypes = []string{
- typeImageLayout,
- typeImage,
-}
-
-type bundleCmd struct {
- stdout *log.Logger
- stderr *log.Logger
- typ string // the type to bundle, can be empty string
- ref string
- root string
-}
-
-func newBundleCmd(stdout, stderr *log.Logger) *cobra.Command {
- v := &bundleCmd{
- stdout: stdout,
- stderr: stderr,
- }
-
- cmd := &cobra.Command{
- Use: "create-runtime-bundle [src] [dest]",
- Short: "Create an OCI image runtime bundle",
- Long: `Creates an OCI image runtime bundle at the destination directory [dest] from an OCI image present at [src].`,
- Run: v.Run,
- }
-
- cmd.Flags().StringVar(
- &v.typ, "type", "",
- fmt.Sprintf(
- `Type of the file to unpack. If unset, oci-image-tool will try to auto-detect the type. One of "%s"`,
- strings.Join(bundleTypes, ","),
- ),
- )
-
- cmd.Flags().StringVar(
- &v.ref, "ref", "v1.0",
- `The ref pointing to the manifest of the OCI image. This must be present in the "refs" subdirectory of the image.`,
- )
-
- cmd.Flags().StringVar(
- &v.root, "rootfs", "rootfs",
- `A directory representing the root filesystem of the container in the OCI runtime bundle.
-It is strongly recommended to keep the default value.`,
- )
-
- return cmd
-}
-
-func (v *bundleCmd) Run(cmd *cobra.Command, args []string) {
- if len(args) != 2 {
- v.stderr.Print("both src and dest must be provided")
- if err := cmd.Usage(); err != nil {
- v.stderr.Println(err)
- }
- os.Exit(1)
- }
-
- if _, err := os.Stat(args[1]); os.IsNotExist(err) {
- v.stderr.Printf("destination path %s does not exist", args[1])
- os.Exit(1)
- }
-
- if v.typ == "" {
- typ, err := autodetect(args[0])
- if err != nil {
- v.stderr.Printf("%q: autodetection failed: %v", args[0], err)
- os.Exit(1)
- }
- v.typ = typ
- }
-
- var err error
- switch v.typ {
- case typeImageLayout:
- err = image.CreateRuntimeBundleLayout(args[0], args[1], v.ref, v.root)
-
- case typeImage:
- err = image.CreateRuntimeBundle(args[0], args[1], v.ref, v.root)
- }
-
- if err != nil {
- v.stderr.Printf("unpacking failed: %v", err)
- os.Exit(1)
- }
-
- os.Exit(0)
-}
@@ -1,41 +0,0 @@
-// 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 (
- "log"
- "os"
-
- "github.com/spf13/cobra"
-)
-
-func main() {
- cmd := &cobra.Command{
- Use: "oci-image-tool",
- Short: "A tool for working with OCI images",
- }
-
- stdout := log.New(os.Stdout, "", 0)
- stderr := log.New(os.Stderr, "", 0)
-
- cmd.AddCommand(newValidateCmd(stdout, stderr))
- cmd.AddCommand(newUnpackCmd(stdout, stderr))
- cmd.AddCommand(newBundleCmd(stdout, stderr))
-
- if err := cmd.Execute(); err != nil {
- stderr.Println(err)
- os.Exit(1)
- }
-}
Oops, something went wrong.

0 comments on commit dae341e

Please sign in to comment.