-
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
Merged
priyawadhwa
merged 5 commits into
GoogleContainerTools:master
from
priyawadhwa:entrypoint
Sep 26, 2018
+107
−5
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5d2d282
Review config for cmd/entrypoint after building a stage
d923d5e
Fix integration test
da6f099
Merge branch 'master' of github.com:GoogleContainerTools/kaniko into …
cd1b957
Address code review comments; review unnecessary error check
1e1c982
Merged master, fixed merge conflict
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM gcr.io/distroless/base@sha256:628939ac8bf3f49571d05c6c76b8688cb4a851af6c7088e599388259875bde20 AS first | ||
CMD ["mycmd"] | ||
|
||
FROM first | ||
ENTRYPOINT ["myentrypoint"] # This should clear out CMD in the config metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package executor | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/GoogleContainerTools/kaniko/pkg/config" | ||
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||
"github.com/GoogleContainerTools/kaniko/testutil" | ||
"github.com/google/go-containerregistry/pkg/v1" | ||
) | ||
|
||
func Test_reviewConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
dockerfile string | ||
originalCmd []string | ||
originalEntrypoint []string | ||
expectedCmd []string | ||
}{ | ||
{ | ||
name: "entrypoint and cmd declared", | ||
dockerfile: ` | ||
FROM scratch | ||
CMD ["mycmd"] | ||
ENTRYPOINT ["myentrypoint"]`, | ||
originalEntrypoint: []string{"myentrypoint"}, | ||
originalCmd: []string{"mycmd"}, | ||
expectedCmd: []string{"mycmd"}, | ||
}, | ||
{ | ||
name: "only entrypoint declared", | ||
dockerfile: ` | ||
FROM scratch | ||
ENTRYPOINT ["myentrypoint"]`, | ||
originalEntrypoint: []string{"myentrypoint"}, | ||
originalCmd: []string{"mycmd"}, | ||
expectedCmd: nil, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
config := &v1.Config{ | ||
Cmd: test.originalCmd, | ||
Entrypoint: test.originalEntrypoint, | ||
} | ||
reviewConfig(stage(t, test.dockerfile), config) | ||
testutil.CheckErrorAndDeepEqual(t, false, nil, test.expectedCmd, config.Cmd) | ||
}) | ||
} | ||
} | ||
|
||
func stage(t *testing.T, d string) config.KanikoStage { | ||
stages, err := dockerfile.Parse([]byte(d)) | ||
if err != nil { | ||
t.Fatalf("error parsing dockerfile: %v", err) | ||
} | ||
return config.KanikoStage{ | ||
Stage: stages[0], | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.