-
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
Refactor build into stageBuilder type #343
Refactor build into stageBuilder type #343
Conversation
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)
f317562
to
d9022dd
Compare
pkg/executor/build.go
Outdated
} | ||
snapshotFiles := dockerCommand.FilesToSnapshot() | ||
var contents []byte | ||
snapshotFiles := dockerCommand.FilesToSnapshot() |
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.
nit: use shorter variables names wherever possible.
Just files will suffice.
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.
Following up with nits that were missed due to git issues last time.
pkg/executor/build.go
Outdated
return nil | ||
} | ||
|
||
func (s *stageBuilder) buildStage(opts *config.KanikoOptions) 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.
Avoid Stuttering stageBuilder.buildStage().
Just stageBuilder.build()
suffix
pkg/executor/build.go
Outdated
if err := s.Snapshotter.Init(); err != nil { | ||
return err | ||
} | ||
buildArgs := dockerfile.NewBuildArgs(opts.BuildArgs) |
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 shorter names when possible https://github.com/golang/go/wiki/CodeReviewComments#variable-names
args
?
pkg/executor/build.go
Outdated
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) |
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.
cmd
instead of dockerCommand
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.
cmd is being used as the iterator here, maybe command if we really want to shorten it?
pkg/executor/build.go
Outdated
// 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 { |
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.
stage.Final
avoid stuttering stage.FinalStage
pkg/executor/build.go
Outdated
return nil, err | ||
} | ||
for index, stage := range stages { | ||
stageBuilder, err := newStageBuilder(opts, 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.
pkg/executor/build.go
Outdated
} | ||
sourceImage, err = mutate.Config(sourceImage, imageConfig.Config) | ||
sourceImage, err := mutate.Config(stageBuilder.Image, stageBuilder.ConfigFile.Config) |
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.
if this is the only image. Use image
or i
7bdebbd
to
ee9aa95
Compare
…ixed linting errors
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: