Defer initial snapshot. Remove ReadSuccess()
This commit is contained in:
parent
691acd094a
commit
8fb17f60d9
|
|
@ -20,18 +20,12 @@ import v1 "github.com/google/go-containerregistry/pkg/v1"
|
|||
|
||||
type Cached interface {
|
||||
Layer() v1.Layer
|
||||
ReadSuccess() bool
|
||||
}
|
||||
|
||||
type caching struct {
|
||||
layer v1.Layer
|
||||
readSuccess bool
|
||||
}
|
||||
|
||||
func (c caching) Layer() v1.Layer {
|
||||
return c.layer
|
||||
}
|
||||
|
||||
func (c caching) ReadSuccess() bool {
|
||||
return c.readSuccess
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,8 +189,6 @@ func (cr *CachingCopyCommand) ExecuteCommand(config *v1.Config, buildArgs *docke
|
|||
}
|
||||
|
||||
cr.layer = layers[0]
|
||||
cr.readSuccess = true
|
||||
|
||||
cr.extractedFiles, err = util.GetFSFromLayers(kConfig.RootDir, layers, util.ExtractFunc(cr.extractFn), util.IncludeWhiteout())
|
||||
|
||||
logrus.Debugf("extractedFiles: %s", cr.extractedFiles)
|
||||
|
|
|
|||
|
|
@ -200,7 +200,6 @@ func (cr *CachingRunCommand) ExecuteCommand(config *v1.Config, buildArgs *docker
|
|||
}
|
||||
|
||||
cr.layer = layers[0]
|
||||
cr.readSuccess = true
|
||||
|
||||
cr.extractedFiles, err = util.GetFSFromLayers(
|
||||
kConfig.RootDir,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ package constants
|
|||
|
||||
const (
|
||||
// RootDir is the path to the root directory
|
||||
RootDir = "/root"
|
||||
RootDir = "/"
|
||||
|
||||
// WorkspaceDir is the path to the workspace directory
|
||||
WorkspaceDir = "/workspace"
|
||||
|
|
|
|||
|
|
@ -317,13 +317,7 @@ func (s *stageBuilder) build() error {
|
|||
return errors.Wrap(err, "failed to check filesystem whitelist")
|
||||
}
|
||||
|
||||
// Take initial snapshot
|
||||
t := timing.Start("Initial FS snapshot")
|
||||
if err := s.snapshotter.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
timing.DefaultRun.Stop(t)
|
||||
initSnapshotTaken := false
|
||||
|
||||
cacheGroup := errgroup.Group{}
|
||||
for index, command := range s.cmds {
|
||||
|
|
@ -346,6 +340,24 @@ func (s *stageBuilder) build() error {
|
|||
|
||||
logrus.Info(command.String())
|
||||
|
||||
isCacheCommand := func() bool {
|
||||
switch command.(type) {
|
||||
case commands.Cached:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
if !isCacheCommand() && !initSnapshotTaken {
|
||||
// Take initial snapshot
|
||||
t := timing.Start("Initial FS snapshot")
|
||||
if err := s.snapshotter.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
timing.DefaultRun.Stop(t)
|
||||
initSnapshotTaken = true
|
||||
}
|
||||
|
||||
if err := command.ExecuteCommand(&s.cf.Config, s.args); err != nil {
|
||||
return errors.Wrap(err, "failed to execute command")
|
||||
}
|
||||
|
|
@ -356,16 +368,7 @@ func (s *stageBuilder) build() error {
|
|||
continue
|
||||
}
|
||||
|
||||
fn := func() bool {
|
||||
switch v := command.(type) {
|
||||
case commands.Cached:
|
||||
return v.ReadSuccess()
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if fn() {
|
||||
if isCacheCommand() {
|
||||
v := command.(commands.Cached)
|
||||
layer := v.Layer()
|
||||
if err := s.saveLayerToImage(layer, command.String()); err != nil {
|
||||
|
|
@ -388,6 +391,7 @@ func (s *stageBuilder) build() error {
|
|||
// Push layer to cache (in parallel) now along with new config file
|
||||
if s.opts.Cache && command.ShouldCacheOutput() {
|
||||
cacheGroup.Go(func() error {
|
||||
logrus.Infof("%s is saved at %s", ck, tarPath)
|
||||
return s.pushLayerToCache(s.opts, ck, tarPath, command.String())
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ func NewSnapshotter(l *LayeredMap, d string) *Snapshotter {
|
|||
|
||||
// Init initializes a new snapshotter
|
||||
func (s *Snapshotter) Init() error {
|
||||
logrus.Info("Taking initial snapshot")
|
||||
_, _, err := s.scanFullFilesystem()
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue