mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-22 09:14:00 +02:00
Rebased on master
This commit is contained in:
+29
-11
@@ -85,23 +85,41 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
|
||||
if err := dockerCommand.ExecuteCommand(&imageConfig.Config, buildArgs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Don't snapshot if it's not the final stage and not the final command
|
||||
// Also don't snapshot if it's the final stage, not the final command, and single snapshot is set
|
||||
if (!stage.FinalStage && !finalCmd) || (stage.FinalStage && !finalCmd && opts.SingleSnapshot) {
|
||||
continue
|
||||
}
|
||||
// Now, we get the files to snapshot from this command and take the snapshot
|
||||
snapshotFiles := dockerCommand.FilesToSnapshot()
|
||||
if finalCmd {
|
||||
snapshotFiles = nil
|
||||
var contents []byte
|
||||
|
||||
// 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 !stage.FinalStage {
|
||||
if finalCmd {
|
||||
contents, err = snapshotter.TakeSnapshotFS()
|
||||
}
|
||||
} else {
|
||||
// If we are in single snapshot mode, we only take a snapshot once, after all
|
||||
// commands have completed.
|
||||
if opts.SingleSnapshot {
|
||||
if finalCmd {
|
||||
contents, err = snapshotter.TakeSnapshotFS()
|
||||
}
|
||||
} else {
|
||||
// Otherwise, in the final stage we take a snapshot at each command. If we know
|
||||
// the files that were changed, we'll snapshot those explicitly, otherwise we'll
|
||||
// check if anything in the filesystem changed.
|
||||
if snapshotFiles != nil {
|
||||
contents, err = snapshotter.TakeSnapshot(snapshotFiles)
|
||||
} else {
|
||||
contents, err = snapshotter.TakeSnapshotFS()
|
||||
}
|
||||
}
|
||||
}
|
||||
contents, err := snapshotter.TakeSnapshot(snapshotFiles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("Error taking snapshot of files for command %s: %s", dockerCommand, err)
|
||||
}
|
||||
|
||||
util.MoveVolumeWhitelistToWhitelist()
|
||||
if contents == nil {
|
||||
logrus.Info("No files were changed, appending empty layer to config.")
|
||||
logrus.Info("No files were changed, appending empty layer to config. No layer added to image.")
|
||||
continue
|
||||
}
|
||||
// Append the layer to the image
|
||||
|
||||
Reference in New Issue
Block a user