Merge pull request #23 from mzihlmann/workdir-cache-2

simplify logic for detecting empty layers
This commit is contained in:
Martin Zihlmann 2025-05-29 23:57:38 +01:00 committed by GitHub
commit 685c1a6c5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 {