Skip to content

Commit

Permalink
fix: handle ancient empty docker layers
Browse files Browse the repository at this point in the history
Earlier versions of docker images had empty layers of 1024 zero-valued
octets.

moby/moby#20917 (comment)

Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Oct 16, 2023
1 parent d9f849b commit f6a1122
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Check warning on line 50 in pkg/log/log.go

View check run for this annotation

Codecov / codecov/patch

pkg/log/log.go#L49-L50

Added lines #L49 - L50 were not covered by tests
}

func Errorf(msg string, v ...interface{}) {
addStackerLogSentinel(log.NewEntry(log.Log.(*log.Logger))).Errorf(msg, v...)
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/overlay/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package overlay
import (
"bytes"
"encoding/json"
"io/fs"
"os"
"path"

Expand Down Expand Up @@ -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

Check warning on line 126 in pkg/overlay/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/overlay/metadata.go#L121-L126

Added lines #L121 - L126 were not covered by tests
}

return "", errors.Wrapf(err, "%s unable to stat", contents)

Check warning on line 129 in pkg/overlay/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/overlay/metadata.go#L129

Added line #L129 was not covered by tests
}
lowerdirs = append(lowerdirs, contents)
}
Expand Down
10 changes: 10 additions & 0 deletions test/docker-base.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ EOF
umoci unpack --image oci:layer1 dest
[ ! -f dest/rootfs/favicon.ico ]
}

@test "image with empty layer" {
cat > stacker.yaml <<EOF
image:
from:
type: docker
url: docker://ghcr.io/project-stacker/grafana-oss:10.1.2-ubuntu
EOF
stacker build
}

0 comments on commit f6a1122

Please sign in to comment.