-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Review config for cmd/entrypoint after building a stage #348
Review config for cmd/entrypoint after building a stage #348
Conversation
As mentioned in GoogleContainerTools#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.
4be4f72
to
d923d5e
Compare
pkg/executor/build.go
Outdated
cmd := false | ||
|
||
for _, c := range stage.Commands { | ||
if c.Name() == "cmd" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/executor/build.go
Outdated
// 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function does not encounter an error flow and always returns nil.
There is no need to return an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
FROM scratch | ||
CMD ["mycmd"] | ||
ENTRYPOINT ["myentrypoint"]`, | ||
originalEntrypoint: []string{"myentrypoint"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by originalCmd, do you mean command from previous stage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use different values for dockerfile.CMD and dockerfile.ENTRYPOINT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by originalCmd, I mean the original value of Cmd in the config file (it should match the value specified in the Dockerfile)
The function reviews the Dockerfile and then clears the Cmd field if it isn't declared in the Dockerfile.
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.