mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-18 14:36:03 +02:00
Review config for cmd/entrypoint after building a stage
As mentioned in #346, if only ENTRYPOINT is set in a stage then any CMD inherited from a parent should be cleared. If both entrypoint and cmd are set then nothing should change. I added a function and unit test to review the config file after building a stage which clears out config.Cmd if ENTRYPOINT was declared but CMD wasn't. I also added an integration test to make sure this works, which should be tested by the preexisting container-diff --metadata test.
This commit is contained in:
@@ -145,6 +145,9 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := reviewConfig(stage, &imageConfig.Config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sourceImage, err = mutate.Config(sourceImage, imageConfig.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -228,3 +231,24 @@ func resolveOnBuild(stage *config.KanikoStage, config *v1.Config) error {
|
||||
config.OnBuild = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// reviewConfig makes sure the value of CMD is correct after building the stage
|
||||
// If ENTRYPOINT was set in this stage but CMD wasn't, then CMD should be cleared out
|
||||
// See Issue #346 for more info
|
||||
func reviewConfig(stage config.KanikoStage, config *v1.Config) error {
|
||||
entrypoint := false
|
||||
cmd := false
|
||||
|
||||
for _, c := range stage.Commands {
|
||||
if c.Name() == "cmd" {
|
||||
cmd = true
|
||||
}
|
||||
if c.Name() == "entrypoint" {
|
||||
entrypoint = true
|
||||
}
|
||||
}
|
||||
if entrypoint && !cmd {
|
||||
config.Cmd = []string{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user