simplify logic for detecting empty layers

This commit is contained in:
Martin Zihlmann 2025-05-29 23:43:04 +01:00
parent 49f24a7395
commit 6a7139eeec
No known key found for this signature in database
GPG Key ID: 0F7784F41354DE99
1 changed files with 3 additions and 3 deletions

View File

@ -416,9 +416,9 @@ func (s *stageBuilder) build() error {
if isCacheCommand {
v := command.(commands.Cached)
layer := v.Layer()
if (files != nil || layer == nil) && len(files) == 0 {
// a cache image with a layer with no files indicates that no files were changed, ie. by 'RUN echo hello'
// a cache image without a layer indicates that no files were changed too, ie. by 'WORKDIR /'
if layer == nil || (files != nil && len(files) == 0) {
// a cache image without a layer indicates that no files were changed, ie. by 'WORKDIR /'
// a cache image with a layer with no files indicates that no files were changed too, ie. by 'RUN echo hello'
logrus.Info("No files were changed, appending empty layer to config. No layer added to image.")
} else {
if err := s.saveLayerToImage(layer, command.String()); err != nil {