Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding tarball support for generating root layer hashes #1600

Merged
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
8 changes: 8 additions & 0 deletions cmd/dmverity-vhd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ generator.
## Example usage

Create VHDs:

```bash
dmverity-vhd create -i alpine:3.12 -o alpine_3_12_layers
```

Compute root hashes:

```bash
dmverity-vhd --docker roothash -i alpine:3.12
```

Compute root hashes with tarball:

```bash
dmverity-vhd --tarball /path/to/tarball.tar roothash -i alpine:3.12
```
29 changes: 25 additions & 4 deletions cmd/dmverity-vhd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand All @@ -26,7 +27,8 @@ const (
imageFlag = "image"
verboseFlag = "verbose"
outputDirFlag = "out-dir"
sourceFlag = "docker"
dockerFlag = "docker"
tarballFlag = "tarball"
hashDeviceVhdFlag = "hash-dev-vhd"
maxVHDSize = dmverity.RecommendedVHDSizeGB
)
Expand Down Expand Up @@ -59,9 +61,13 @@ func main() {
Usage: "Optional: verbose output",
},
cli.BoolFlag{
Name: sourceFlag + ",d",
Name: dockerFlag + ",d",
Usage: "Optional: use local docker daemon",
},
cli.StringFlag{
Name: tarballFlag + ",t",
Usage: "Optional: path to tarball containing image info",
},
}

if err := app.Run(os.Args); err != nil {
Expand All @@ -72,16 +78,31 @@ func main() {

func fetchImageLayers(ctx *cli.Context) (layers []v1.Layer, err error) {
image := ctx.String(imageFlag)
tarballPath := ctx.GlobalString(tarballFlag)
ref, err := name.ParseReference(image)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse image reference: %s", image)
}

local := ctx.GlobalBool(sourceFlag)
dockerDaemon := ctx.GlobalBool(dockerFlag)
SethHollandsworth marked this conversation as resolved.
Show resolved Hide resolved

// error check to make sure docker and tarball are not both defined
if dockerDaemon && tarballPath != "" {
return nil, errors.Errorf("cannot use both docker and tarball for image source")
}

// by default, using remote as source
var img v1.Image
if local {
if tarballPath != "" {
// create a tag and search the tarball for the image specified
var imageNameAndTag name.Tag
imageNameAndTag, err = name.NewTag(image)
if err != nil {
return nil, errors.Wrapf(err, "failed to failed to create a tag to search tarball for: %s", image)
}
// if only an image name is provided and not a tag, the default is "latest"
img, err = tarball.ImageFromPath(tarballPath, &imageNameAndTag)
} else if dockerDaemon {
img, err = daemon.Image(ref)
} else {
var remoteOpts []remote.Option
Expand Down