-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
- Loading branch information
zhouhao
committed
Feb 17, 2017
1 parent
7575a09
commit 59ec62f
Showing
7 changed files
with
579 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/oci-create-runtime-bundle | ||
/oci-unpack | ||
/oci-generate | ||
/oci-image-validate | ||
/oci-unpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// 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" | ||
|
||
specs "github.com/opencontainers/image-spec/specs-go" | ||
"github.com/opencontainers/image-tools/image" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// gitCommit will be the hash that the binary was built from | ||
// and will be populated by the Makefile | ||
var gitCommit = "" | ||
|
||
var generateTypes = []string{ | ||
"imageLayout", | ||
"image", | ||
} | ||
|
||
type generateCmd struct { | ||
stdout *log.Logger | ||
stderr *log.Logger | ||
typ string //the type to generate, can be empty string | ||
version bool | ||
} | ||
|
||
func main() { | ||
stdout := log.New(os.Stdout, "", 0) | ||
stderr := log.New(os.Stderr, "", 0) | ||
|
||
cmd := newGenerateCmd(stdout, stderr) | ||
if err := cmd.Execute(); err != nil { | ||
stderr.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func newGenerateCmd(stdout, stderr *log.Logger) *cobra.Command { | ||
v := &generateCmd{ | ||
stdout: stdout, | ||
stderr: stderr, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "generate [dest]", | ||
Short: "Generate an image or an imageLayout", | ||
Long: `Generate the OCI iamge or imageLayout to the destination directory [dest].`, | ||
Run: v.Run, | ||
} | ||
|
||
cmd.Flags().StringVar( | ||
&v.typ, "type", "imageLayout", | ||
fmt.Sprintf( | ||
`Type of the file to generate, one of "%s".`, | ||
strings.Join(generateTypes, ","), | ||
), | ||
) | ||
|
||
cmd.Flags().BoolVarP( | ||
&v.version, "version", "v", false, | ||
`Print version information and exit`, | ||
) | ||
|
||
origHelp := cmd.HelpFunc() | ||
|
||
cmd.SetHelpFunc(func(c *cobra.Command, args []string) { | ||
origHelp(c, args) | ||
stdout.Println("\nMore information:") | ||
stdout.Printf("\treferences\t%s\n", image.SpecURL) | ||
stdout.Printf("\tbug report\t%s\n", image.IssuesURL) | ||
}) | ||
|
||
return cmd | ||
} | ||
|
||
func (v *generateCmd) Run(cmd *cobra.Command, args []string) { | ||
if v.version { | ||
v.stdout.Printf("commit: %s", gitCommit) | ||
v.stdout.Printf("spec: %s", specs.Version) | ||
os.Exit(0) | ||
} | ||
|
||
if len(args) != 1 { | ||
v.stderr.Print("dest must be provided") | ||
if err := cmd.Usage(); err != nil { | ||
v.stderr.Println(err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
var err error | ||
switch v.typ { | ||
case "imageLayout": | ||
err = image.GenerateLayout(args[0]) | ||
case "image": | ||
err = image.Generate(args[0]) | ||
default: | ||
err = fmt.Errorf("unsupport type %q", v.typ) | ||
} | ||
|
||
if err != nil { | ||
v.stderr.Printf("generating failed: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
% OCI(1) OCI-UNPACK User Manuals | ||
% OCI Community | ||
% JULY 2016 | ||
# NAME | ||
oci-generate \- Generate an OCI image or an OCI imageLayout | ||
|
||
# SYNOPSIS | ||
**oci-unpack** [dest] [flags] | ||
**oci-unpack** [--help|--version] | ||
|
||
# DESCRIPTION | ||
`oci-generate` generate an application/vnd.oci.image.manifest.v1+json or application/vnd.oci.image.manifest.list+json to `dest`. | ||
|
||
# OPTIONS | ||
**--help** | ||
Print usage statement | ||
|
||
**--type** | ||
Type of the file to generate.One of "imageLayout,image".(detault "imageLayout") | ||
|
||
**--version** | ||
Print version information and exit. | ||
|
||
# EXAMPLES | ||
``` | ||
$ oci-generate example | ||
$ tree example | ||
example | ||
├── blobs | ||
│ └── sha256 | ||
│ ├── 5d82e6cbf19cd18f40301df14ffbd62ba1acae8a097e75011ec603ff38a7450a | ||
│ ├── 89b46f9224fbcedd165dd6b317329b69182471c6706993bedc2c2d2fd2d76fba | ||
│ └── a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4 | ||
├── oci-layout | ||
└── refs | ||
└── latest | ||
[...] | ||
``` | ||
# HISTORY | ||
Sept 2016, Originally compiled by Antonio Murdaca (runcom at redhat dot com) |
Oops, something went wrong.