add a new method to indicate if the command provides files to snapshot

This commit is contained in:
Tejal Desai
2020-05-01 15:50:46 -07:00
parent 2e1ca5f19d
commit 32e3336d4c
9 changed files with 61 additions and 10 deletions
+12 -9
View File
@@ -347,15 +347,18 @@ func (s *stageBuilder) build() error {
default:
return false
}
}
if !isCacheCommand() && !initSnapshotTaken {
// Take initial snapshot
t := timing.Start("Initial FS snapshot")
if err := s.snapshotter.Init(); err != nil {
return err
}()
if !initSnapshotTaken && !isCacheCommand && !command.MetadataOnly() {
if !command.ProvidesFilesToSnapshot() {
// Take initial snapshot if command is not metadata only
// and does not return a list of files changed
t := timing.Start("Initial FS snapshot")
if err := s.snapshotter.Init(); err != nil {
return err
}
timing.DefaultRun.Stop(t)
initSnapshotTaken = true
}
timing.DefaultRun.Stop(t)
initSnapshotTaken = true
}
if err := command.ExecuteCommand(&s.cf.Config, s.args); err != nil {
@@ -368,7 +371,7 @@ func (s *stageBuilder) build() error {
continue
}
if isCacheCommand() {
if isCacheCommand {
v := command.(commands.Cached)
layer := v.Layer()
if err := s.saveLayerToImage(layer, command.String()); err != nil {
+6
View File
@@ -55,6 +55,9 @@ func (m MockDockerCommand) String() string {
func (m MockDockerCommand) FilesToSnapshot() []string {
return []string{"meow-snapshot-no-cache"}
}
func (m MockDockerCommand) ProvidesFilesToSnapshot() bool {
return true
}
func (m MockDockerCommand) CacheCommand(image v1.Image) commands.DockerCommand {
return m.cacheCommand
}
@@ -84,6 +87,9 @@ func (m MockCachedDockerCommand) String() string {
func (m MockCachedDockerCommand) FilesToSnapshot() []string {
return []string{"meow-snapshot"}
}
func (m MockCachedDockerCommand) ProvidesFilesToSnapshot() bool {
return true
}
func (m MockCachedDockerCommand) CacheCommand(image v1.Image) commands.DockerCommand {
return nil
}