mirror of
https://github.com/containers/skopeo.git
synced 2025-04-28 11:14:08 +00:00
refactor structure and print git commit in version
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
8cf22b9ca2
commit
a73078ea75
5
Makefile
5
Makefile
@ -21,10 +21,13 @@ ifeq ($(INTERACTIVE), 1)
|
||||
endif
|
||||
DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
|
||||
|
||||
GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true)
|
||||
LDFLAGS := "-X github.com/projectatomic/skopeo.GitCommit=${GIT_COMMIT} ${LDFLAGS}"
|
||||
|
||||
all: man binary
|
||||
|
||||
binary:
|
||||
go build -o ${DEST}skopeo .
|
||||
go build -ldflags ${LDFLAGS} -o ${DEST}skopeo ./cmd/skopeo
|
||||
|
||||
build-container:
|
||||
docker build ${DOCKER_BUILD_ARGS} -t "$(DOCKER_IMAGE)" .
|
||||
|
69
inspect.go
69
inspect.go
@ -1,69 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
pkgInspect "github.com/projectatomic/skopeo/docker/inspect"
|
||||
"github.com/projectatomic/skopeo/types"
|
||||
)
|
||||
|
||||
var inspectCmd = cli.Command{
|
||||
Name: "inspect",
|
||||
Usage: "inspect images on a registry",
|
||||
ArgsUsage: ``,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "raw",
|
||||
Usage: "output raw manifest",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
if c.Bool("raw") {
|
||||
img, err := parseImage(c.Args().First())
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
// TODO(runcom): this is not falling back to v1
|
||||
// TODO(runcom): hardcoded schema 2 version 1
|
||||
b, err := img.RawManifest("2-1")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
return
|
||||
}
|
||||
// get the Image interface before inspecting...utils.go parseImage
|
||||
imgInspect, err := inspect(c)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
out, err := json.Marshal(imgInspect)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
},
|
||||
}
|
||||
|
||||
func inspect(c *cli.Context) (types.ImageManifest, error) {
|
||||
var (
|
||||
imgInspect types.ImageManifest
|
||||
err error
|
||||
name = c.Args().First()
|
||||
)
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(name, types.DockerPrefix):
|
||||
imgInspect, err = pkgInspect.GetData(c, strings.Replace(name, "docker://", "", -1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("%s image is invalid, please use 'docker://'", name)
|
||||
}
|
||||
return imgInspect, nil
|
||||
}
|
22
layers.go
22
layers.go
@ -1,22 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
// TODO(runcom): document args and usage
|
||||
var layersCmd = cli.Command{
|
||||
Name: "layers",
|
||||
Usage: "get images layers",
|
||||
ArgsUsage: ``,
|
||||
Action: func(context *cli.Context) {
|
||||
img, err := parseImage(context.Args().First())
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if err := img.Layers(context.Args().Tail()...); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
57
main.go
57
main.go
@ -1,57 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/docker/cliconfig"
|
||||
)
|
||||
|
||||
const (
|
||||
version = "0.1.12-dev"
|
||||
usage = "interact with registries"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "skopeo"
|
||||
app.Version = version
|
||||
app.Usage = usage
|
||||
// TODO(runcom)
|
||||
//app.EnableBashCompletion = true
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "enable debug output",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
Value: "",
|
||||
Usage: "registry username",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "password",
|
||||
Value: "",
|
||||
Usage: "registry password",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker-cfg",
|
||||
Value: cliconfig.ConfigDir(),
|
||||
Usage: "Docker's cli config for auth",
|
||||
},
|
||||
}
|
||||
app.Before = func(c *cli.Context) error {
|
||||
if c.GlobalBool("debug") {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
app.Commands = []cli.Command{
|
||||
inspectCmd,
|
||||
layersCmd,
|
||||
}
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
4
utils.go
4
utils.go
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package skopeo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"github.com/projectatomic/skopeo/types"
|
||||
)
|
||||
|
||||
func parseImage(img string) (types.Image, error) {
|
||||
func ParseImage(img string) (types.Image, error) {
|
||||
switch {
|
||||
case strings.HasPrefix(img, types.DockerPrefix):
|
||||
return parseDockerImage(strings.TrimPrefix(img, dockerPrefix))
|
||||
|
5
version.go
Normal file
5
version.go
Normal file
@ -0,0 +1,5 @@
|
||||
package skopeo
|
||||
|
||||
const Version = "0.1.12-dev"
|
||||
|
||||
var GitCommit = ""
|
Loading…
Reference in New Issue
Block a user