Skip to content

Commit 6ba7af1

Browse files
fix(build): ensure imageSpec preserves CMD and ENTRYPOINT behavior for compatibility
If CMD is defined from the base image, setting ENTRYPOINT will reset CMD to an empty value. In this scenario, CMD must be defined in the current image to have a value. https: //docs.docker.com/reference/dockerfile/#understand-how-cmd-and-entrypoint-interact Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
1 parent b4ffc4a commit 6ba7af1

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

pkg/build/stage/image_spec.go

+23-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ func (s *ImageSpecStage) PrepareImage(ctx context.Context, _ Conveyor, _ contain
5454
StopSignal: s.imageSpec.StopSignal,
5555
}
5656

57+
// Entrypoint and Cmd handling.
58+
{
59+
// If CMD is defined from the base image, setting ENTRYPOINT will reset CMD to an empty value.
60+
// In this scenario, CMD must be defined in the current image to have a value.
61+
// rel https://docs.docker.com/reference/dockerfile/#understand-how-cmd-and-entrypoint-interact
62+
if s.imageSpec.Entrypoint != nil {
63+
newConfig.Entrypoint = s.imageSpec.Entrypoint
64+
if s.imageSpec.Cmd == nil {
65+
newConfig.ClearCmd = true
66+
}
67+
}
68+
69+
if s.imageSpec.Cmd != nil {
70+
newConfig.Cmd = s.imageSpec.Cmd
71+
}
72+
73+
newConfig.ClearCmd = newConfig.ClearCmd || s.imageSpec.ClearCmd
74+
newConfig.ClearEntrypoint = newConfig.ClearEntrypoint || s.imageSpec.ClearEntrypoint
75+
}
76+
5777
serviceLabels := s.stageImage.Image.GetBuildServiceLabels()
5878
mergedLabels := util.MergeMaps(s.imageSpec.Labels, serviceLabels)
5979
resultLabels, err := modifyLabels(ctx, mergedLabels, s.imageSpec.Labels, s.imageSpec.RemoveLabels, s.imageSpec.ClearWerfLabels)
@@ -86,19 +106,19 @@ func (s *ImageSpecStage) PrepareImage(ctx context.Context, _ Conveyor, _ contain
86106
}
87107

88108
newConfig.ClearHistory = s.imageSpec.ClearHistory
89-
newConfig.ClearCmd = s.imageSpec.ClearCmd
90-
newConfig.ClearEntrypoint = s.imageSpec.ClearEntrypoint
91109

92110
stageImage.Image.SetImageSpecConfig(&newConfig)
93111
}
94112

95113
return nil
96114
}
97115

116+
const imageSpecStageCacheVersion = "2"
117+
98118
func (s *ImageSpecStage) GetDependencies(_ context.Context, _ Conveyor, _ container_backend.ContainerBackend, _, _ *StageImage, _ container_backend.BuildContextArchiver) (string, error) {
99119
var args []string
100120

101-
args = append(args, "1")
121+
args = append(args, imageSpecStageCacheVersion)
102122
args = append(args, s.imageSpec.Author)
103123
args = append(args, fmt.Sprint(s.imageSpec.ClearHistory))
104124

0 commit comments

Comments
 (0)