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