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

Remove tarball.WithCompressedCaching flag to resolve OOM Killed error #1722

Merged
merged 3 commits into from
Oct 19, 2021
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ _If you are interested in contributing to kaniko, see [DEVELOPMENT.md](DEVELOPME
- [--cache-ttl duration](#--cache-ttl-duration)
- [--cleanup](#--cleanup)
- [--context-sub-path](#--context-sub-path)
- [--compressed-caching](#--compressed-caching)
- [--customPlatform](#--customPlatform)
- [--digest-file](#--digest-file)
- [--dockerfile](#--dockerfile)
Expand Down Expand Up @@ -613,6 +614,11 @@ Cache timeout in hours. Defaults to two weeks.

Set this flag to clean the filesystem at the end of the build.

#### --compressed-caching

Set this to false in order to prevent tar compression for cached layers. This will increase the runtime of the build, but decrease the memory usage especially for large builds.
Try to use `--compressed-caching=false` if your build fails with an out of memory error. Defaults to true.

#### --context-sub-path

Set a sub path within the given `--context`.
Expand Down
1 change: 1 addition & 0 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func addKanikoOptionsFlags() {
RootCmd.PersistentFlags().StringVarP(&opts.ImageNameTagDigestFile, "image-name-tag-with-digest-file", "", "", "Specify a file to save the image name w/ image tag w/ digest of the built image to.")
RootCmd.PersistentFlags().StringVarP(&opts.OCILayoutPath, "oci-layout-path", "", "", "Path to save the OCI image layout of the built image.")
RootCmd.PersistentFlags().BoolVarP(&opts.Cache, "cache", "", false, "Use cache when building image")
RootCmd.PersistentFlags().BoolVarP(&opts.CompressedCaching, "compressed-caching", "", true, "Compress the cached layers. Decreases build time, but increases memory usage.")
RootCmd.PersistentFlags().BoolVarP(&opts.Cleanup, "cleanup", "", false, "Clean the filesystem at the end")
RootCmd.PersistentFlags().DurationVarP(&opts.CacheTTL, "cache-ttl", "", time.Hour*336, "Cache timeout in hours. Defaults to two weeks.")
RootCmd.PersistentFlags().VarP(&opts.InsecureRegistries, "insecure-registry", "", "Insecure registry using plain HTTP to push and pull. Set it repeatedly for multiple registries.")
Expand Down
1 change: 1 addition & 0 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type KanikoOptions struct {
NoPush bool
Cache bool
Cleanup bool
CompressedCaching bool
IgnoreVarRun bool
SkipUnusedStages bool
RunV2 bool
Expand Down
7 changes: 6 additions & 1 deletion pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,12 @@ func (s *stageBuilder) saveSnapshotToLayer(tarPath string) (v1.Layer, error) {
return nil, nil
}

layer, err := tarball.LayerFromFile(tarPath, tarball.WithCompressedCaching)
var layer v1.Layer
if s.opts.CompressedCaching == true {
layer, err = tarball.LayerFromFile(tarPath, tarball.WithCompressedCaching)
} else {
layer, err = tarball.LayerFromFile(tarPath)
}
if err != nil {
return nil, err
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/executor/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,42 @@ func Test_stageBuilder_build(t *testing.T) {
rootDir: dir,
}
}(),
func() testcase {
dir, files := tempDirAndFile(t)
file := files[0]
filePath := filepath.Join(dir, file)
ch := NewCompositeCache("", "meow")

ch.AddPath(filePath, util.FileContext{})
hash, err := ch.Hash()
if err != nil {
t.Errorf("couldn't create hash %v", err)
}
command := MockDockerCommand{
command: "meow",
contextFiles: []string{filePath},
cacheCommand: MockCachedDockerCommand{
contextFiles: []string{filePath},
},
}

destDir, err := ioutil.TempDir("", "baz")
if err != nil {
t.Errorf("could not create temp dir %v", err)
}
return testcase{
description: "fake command cache enabled with tar compression disabled and key in cache",
opts: &config.KanikoOptions{Cache: true, CompressedCaching: false},
config: &v1.ConfigFile{Config: v1.Config{WorkingDir: destDir}},
layerCache: &fakeLayerCache{
retrieve: true,
},
expectedCacheKeys: []string{hash},
pushedCacheKeys: []string{},
commands: []commands.DockerCommand{command},
rootDir: dir,
}
}(),
{
description: "fake command cache disabled and key not in cache",
opts: &config.KanikoOptions{Cache: false},
Expand Down
8 changes: 7 additions & 1 deletion pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,13 @@ func writeImageOutputs(image v1.Image, destRefs []name.Tag) error {
// pushLayerToCache pushes layer (tagged with cacheKey) to opts.Cache
// if opts.Cache doesn't exist, infer the cache from the given destination
func pushLayerToCache(opts *config.KanikoOptions, cacheKey string, tarPath string, createdBy string) error {
layer, err := tarball.LayerFromFile(tarPath, tarball.WithCompressedCaching)
var layer v1.Layer
var err error
if opts.CompressedCaching == true {
layer, err = tarball.LayerFromFile(tarPath, tarball.WithCompressedCaching)
} else {
layer, err = tarball.LayerFromFile(tarPath)
}
if err != nil {
return err
}
Expand Down