From f6a11223079e9b39c98af5183bd969b705c41ab7 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Wed, 4 Oct 2023 23:33:50 +0000 Subject: [PATCH] fix: handle ancient empty docker layers Earlier versions of docker images had empty layers of 1024 zero-valued octets. https://github.com/moby/moby/issues/20917#issuecomment-191901912 Signed-off-by: Ramkumar Chinchani --- pkg/log/log.go | 4 ++++ pkg/overlay/metadata.go | 11 ++++++++++- test/docker-base.bats | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/log/log.go b/pkg/log/log.go index 553383f0..c8a8c280 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -46,6 +46,10 @@ func Infof(msg string, v ...interface{}) { addStackerLogSentinel(log.NewEntry(log.Log.(*log.Logger))).Infof(msg, v...) } +func Warnf(msg string, v ...interface{}) { + addStackerLogSentinel(log.NewEntry(log.Log.(*log.Logger))).Warnf(msg, v...) +} + func Errorf(msg string, v ...interface{}) { addStackerLogSentinel(log.NewEntry(log.Log.(*log.Logger))).Errorf(msg, v...) } diff --git a/pkg/overlay/metadata.go b/pkg/overlay/metadata.go index 3114dcf3..43906a2a 100644 --- a/pkg/overlay/metadata.go +++ b/pkg/overlay/metadata.go @@ -3,6 +3,7 @@ package overlay import ( "bytes" "encoding/json" + "io/fs" "os" "path" @@ -117,7 +118,15 @@ func (ovl overlayMetadata) lxcRootfsString(config types.StackerConfig, tag strin for _, layer := range manifest.Layers { contents := overlayPath(config.RootFSDir, layer.Digest, "overlay") if _, err := os.Stat(contents); err != nil { - return "", errors.Wrapf(err, "%s does not exist", contents) + if errors.Is(err, fs.ErrNotExist) { + // some docker layers may be empty tars, so ignore these + // https://github.com/moby/moby/issues/20917#issuecomment-191901912 + log.Warnf("%s skipping empty tar layer", layer.Digest) + + continue + } + + return "", errors.Wrapf(err, "%s unable to stat", contents) } lowerdirs = append(lowerdirs, contents) } diff --git a/test/docker-base.bats b/test/docker-base.bats index b21d1cdc..5df40d6b 100644 --- a/test/docker-base.bats +++ b/test/docker-base.bats @@ -31,3 +31,13 @@ EOF umoci unpack --image oci:layer1 dest [ ! -f dest/rootfs/favicon.ico ] } + +@test "image with empty layer" { + cat > stacker.yaml <