Skip to content

Commit

Permalink
adding option of using buffered image reader for faster dmverity hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
SethHollandsworth committed Jan 30, 2024
1 parent d4494c7 commit 62250ee
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions cmd/dmverity-vhd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import (
const usage = `dmverity-vhd is a command line tool for creating LCOW layer VHDs with dm-verity hashes.`

const (
usernameFlag = "username"
passwordFlag = "password"
imageFlag = "image"
verboseFlag = "verbose"
outputDirFlag = "out-dir"
dockerFlag = "docker"
tarballFlag = "tarball"
hashDeviceVhdFlag = "hash-dev-vhd"
maxVHDSize = dmverity.RecommendedVHDSizeGB
usernameFlag = "username"
passwordFlag = "password"
imageFlag = "image"
verboseFlag = "verbose"
outputDirFlag = "out-dir"
dockerFlag = "docker"
bufferedOpenerFlag = "buffered-opener"
tarballFlag = "tarball"
hashDeviceVhdFlag = "hash-dev-vhd"
maxVHDSize = dmverity.RecommendedVHDSizeGB
)

func init() {
Expand Down Expand Up @@ -68,6 +69,10 @@ func main() {
Name: tarballFlag + ",t",
Usage: "Optional: path to tarball containing image info",
},
cli.BoolFlag{
Name: bufferedOpenerFlag + ",b",
Usage: "Optional: use buffered opener for image",
},
}

if err := app.Run(os.Args); err != nil {
Expand Down Expand Up @@ -103,11 +108,13 @@ func fetchImageLayers(ctx *cli.Context) (layers []v1.Layer, err error) {
// if only an image name is provided and not a tag, the default is "latest"
img, err = tarball.ImageFromPath(tarballPath, &imageNameAndTag)
} else if dockerDaemon {
// use the unbuffered opener, the tradeoff being the image will stream as needed
// use the unbuffered opener by default, the tradeoff being the image will stream as needed
// so it is slower but much more memory efficient
var opts []daemon.Option
opt := daemon.WithUnbufferedOpener()
opts = append(opts, opt)
if !ctx.GlobalBool(bufferedOpenerFlag) {
opt := daemon.WithUnbufferedOpener()
opts = append(opts, opt)
}

img, err = daemon.Image(ref, opts...)
} else {
Expand Down

0 comments on commit 62250ee

Please sign in to comment.