Skip to content
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

parse arg commands at the top of dockerfiles #404

Merged
merged 12 commits into from
Nov 6, 2018

Conversation

sharifelgamal
Copy link
Contributor

Fixes #395

func (b *BuildArgs) AddMetaArgs(metaArgs map[string]string) *BuildArgs {
for key, value := range metaArgs {
logrus.Infof("META ARG: adding %s = %s", key, value)
b.AddMetaArg(key, &value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bug is here -- since there is a single value variable, the address it's pointing to is the same each time, so when that's passed in to AddMetaArg, all of the meta args end up pointing to the same value.

I think if you change it to

for key, value := range metaArgs {
  v := value
  b.AddMetaArg(key, &v)
}

this should work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was it. Thank you!

@sharifelgamal
Copy link
Contributor Author

This should be ready for review.

@@ -14,7 +14,7 @@

# Bump these on release
VERSION_MAJOR ?= 0
VERSION_MINOR ?= 3
VERSION_MINOR ?= 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!! Must have missed it...many times... 😅

@@ -250,12 +253,21 @@ func (s *stageBuilder) saveSnapshot(createdBy string, ck string, contents []byte
// DoBuild executes building the Dockerfile
func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
// Parse dockerfile and unpack base image to root
stages, err := dockerfile.Stages(opts)
stages, metaArgs, err := dockerfile.Stages(opts)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT of storing the metaArgs for each stage in the KanikoStage type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that simplified things considerably. done.

filesAdded = true
if err := t.AddFileToTar(path); err != nil {
return false, err
}
}
}

if filesAdded && len(addedPaths) == 1 && addedPaths[0] == "/" {
logrus.Infof("Only added /, not taking snapshot.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so for a command like RUN touch /${FOO}, where $FOO doesn't resolve to anything, there should just be an empty layer appended to the image, that's what docker does. For some reason, we see that / has changed and add that to the snapshot, resulting in an extra non-empty layer compared to docker.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrmm, what if it's like "/foo/${FOO}"? Maybe the check is if the only added path is a directory, rather than root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, done.

@sharifelgamal sharifelgamal merged commit 224b7e2 into GoogleContainerTools:master Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants