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

Refactor build into stageBuilder type #343

Merged
merged 4 commits into from
Sep 13, 2018

Conversation

priyawadhwa
Copy link
Collaborator

Refactoring builds by stage will make it easier to generate cache keys
for layers, since the stageBuilder type will contain everything required
to generate the key:

  1. Base image with digest
  2. Config file
  3. Snapshotter (which will provide a key for the filesystem)
  4. The current command (which will be passed in)

Refactoring builds by stage will make it easier to generate cache keys
for layers, since the stageBuilder type will contain everything required
to generate the key:

1. Base image with digest
2. Config file
3. Snapshotter (which will provide a key for the filesystem)
4. The current command (which will be passed in)
}
snapshotFiles := dockerCommand.FilesToSnapshot()
var contents []byte
snapshotFiles := dockerCommand.FilesToSnapshot()
Copy link
Member

Choose a reason for hiding this comment

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

nit: use shorter variables names wherever possible.
Just files will suffice.

Copy link
Member

@tejal29 tejal29 left a comment

Choose a reason for hiding this comment

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

Following up with nits that were missed due to git issues last time.

return nil
}

func (s *stageBuilder) buildStage(opts *config.KanikoOptions) error {
Copy link
Member

Choose a reason for hiding this comment

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

Avoid Stuttering stageBuilder.buildStage().
Just stageBuilder.build() suffix

if err := s.Snapshotter.Init(); err != nil {
return err
}
buildArgs := dockerfile.NewBuildArgs(opts.BuildArgs)
Copy link
Member

Choose a reason for hiding this comment

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

buildArgs := dockerfile.NewBuildArgs(opts.BuildArgs)
for index, cmd := range s.stage.Commands {
finalCmd := index == len(s.stage.Commands)-1
dockerCommand, err := commands.GetCommand(cmd, opts.SrcContext)
Copy link
Member

Choose a reason for hiding this comment

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

cmd instead of dockerCommand

Copy link
Contributor

Choose a reason for hiding this comment

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

cmd is being used as the iterator here, maybe command if we really want to shorten it?

// If this is an intermediate stage, we only snapshot for the last command and we
// want to snapshot the entire filesystem since we aren't tracking what was changed
// by previous commands.
if !s.stage.FinalStage {
Copy link
Member

Choose a reason for hiding this comment

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

stage.Final avoid stuttering stage.FinalStage

return nil, err
}
for index, stage := range stages {
stageBuilder, err := newStageBuilder(opts, stage)
Copy link
Member

Choose a reason for hiding this comment

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

}
sourceImage, err = mutate.Config(sourceImage, imageConfig.Config)
sourceImage, err := mutate.Config(stageBuilder.Image, stageBuilder.ConfigFile.Config)
Copy link
Member

Choose a reason for hiding this comment

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

if this is the only image. Use image or i

@tejal29 tejal29 merged commit 14f3c81 into GoogleContainerTools:master Sep 13, 2018
@priyawadhwa priyawadhwa deleted the stagebuilder branch September 13, 2018 19:32
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