Compare commits
4 Commits
b34fd2966c
...
5c8719e80e
| Author | SHA1 | Date |
|---|---|---|
|
|
5c8719e80e | |
|
|
236ba5690e | |
|
|
fa67e45814 | |
|
|
806a9ad19b |
|
|
@ -1,2 +0,0 @@
|
||||||
Jerome Ju <jeromeju@google.com>
|
|
||||||
Quan Zhang <zhangquan@google.com>
|
|
||||||
|
|
@ -1,3 +1,11 @@
|
||||||
|
# 🧊 This project is archived and no longer developed or maintained. 🧊
|
||||||
|
|
||||||
|
The code remains available for historic purposes.
|
||||||
|
|
||||||
|
The README as of the archival date remains unchanged below for historic purposes.
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
# kaniko - Build Images In Kubernetes
|
# kaniko - Build Images In Kubernetes
|
||||||
|
|
||||||
## 🚨NOTE: kaniko is not an officially supported Google product🚨
|
## 🚨NOTE: kaniko is not an officially supported Google product🚨
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ func (b *BaseCommand) IsArgsEnvsRequiredInCache() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BaseCommand) IsConsiderExcludedFilesInCache() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BaseCommand) CacheCommand(v1.Image) DockerCommand {
|
func (b *BaseCommand) CacheCommand(v1.Image) DockerCommand {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,10 @@ type DockerCommand interface {
|
||||||
// True if need add ARGs and EVNs to composite cache string with resolved command
|
// True if need add ARGs and EVNs to composite cache string with resolved command
|
||||||
// need only for RUN instruction
|
// need only for RUN instruction
|
||||||
IsArgsEnvsRequiredInCache() bool
|
IsArgsEnvsRequiredInCache() bool
|
||||||
|
|
||||||
|
// True if need add consider excluded files to composite cache string with resolved command
|
||||||
|
// need only for COPY --from instruction
|
||||||
|
IsConsiderExcludedFilesInCache() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCommand(cmd instructions.Command, fileContext util.FileContext, useNewRun bool, cacheCopy bool, cacheRun bool) (DockerCommand, error) {
|
func GetCommand(cmd instructions.Command, fileContext util.FileContext, useNewRun bool, cacheCopy bool, cacheRun bool) (DockerCommand, error) {
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,10 @@ func (c *CopyCommand) ShouldCacheOutput() bool {
|
||||||
return c.shdCache
|
return c.shdCache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CopyCommand) IsConsiderExcludedFilesInCache() bool {
|
||||||
|
return c.cmd.From != ""
|
||||||
|
}
|
||||||
|
|
||||||
// CacheCommand returns true since this command should be cached
|
// CacheCommand returns true since this command should be cached
|
||||||
func (c *CopyCommand) CacheCommand(img v1.Image) DockerCommand {
|
func (c *CopyCommand) CacheCommand(img v1.Image) DockerCommand {
|
||||||
return &CachingCopyCommand{
|
return &CachingCopyCommand{
|
||||||
|
|
|
||||||
|
|
@ -219,8 +219,9 @@ func (s *stageBuilder) populateCompositeKey(command commands.DockerCommand, file
|
||||||
// Add the next command to the cache key.
|
// Add the next command to the cache key.
|
||||||
compositeKey.AddKey(command.String())
|
compositeKey.AddKey(command.String())
|
||||||
|
|
||||||
|
considerExcludedFiles := command.IsConsiderExcludedFilesInCache()
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if err := compositeKey.AddPath(f, s.fileContext); err != nil {
|
if err := compositeKey.AddPath(f, s.fileContext, considerExcludedFiles); err != nil {
|
||||||
return compositeKey, err
|
return compositeKey, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -934,7 +934,7 @@ func Test_stageBuilder_build(t *testing.T) {
|
||||||
filePath := filepath.Join(dir, file)
|
filePath := filepath.Join(dir, file)
|
||||||
ch := NewCompositeCache("", "meow")
|
ch := NewCompositeCache("", "meow")
|
||||||
|
|
||||||
ch.AddPath(filePath, util.FileContext{})
|
ch.AddPath(filePath, util.FileContext{}, false)
|
||||||
hash, err := ch.Hash()
|
hash, err := ch.Hash()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("couldn't create hash %v", err)
|
t.Errorf("couldn't create hash %v", err)
|
||||||
|
|
@ -964,7 +964,7 @@ func Test_stageBuilder_build(t *testing.T) {
|
||||||
filePath := filepath.Join(dir, file)
|
filePath := filepath.Join(dir, file)
|
||||||
ch := NewCompositeCache("", "meow")
|
ch := NewCompositeCache("", "meow")
|
||||||
|
|
||||||
ch.AddPath(filePath, util.FileContext{})
|
ch.AddPath(filePath, util.FileContext{}, false)
|
||||||
hash, err := ch.Hash()
|
hash, err := ch.Hash()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("couldn't create hash %v", err)
|
t.Errorf("couldn't create hash %v", err)
|
||||||
|
|
@ -997,7 +997,7 @@ func Test_stageBuilder_build(t *testing.T) {
|
||||||
filePath := filepath.Join(dir, file)
|
filePath := filepath.Join(dir, file)
|
||||||
ch := NewCompositeCache("", "meow")
|
ch := NewCompositeCache("", "meow")
|
||||||
|
|
||||||
ch.AddPath(filePath, util.FileContext{})
|
ch.AddPath(filePath, util.FileContext{}, false)
|
||||||
hash, err := ch.Hash()
|
hash, err := ch.Hash()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("couldn't create hash %v", err)
|
t.Errorf("couldn't create hash %v", err)
|
||||||
|
|
@ -1052,7 +1052,7 @@ func Test_stageBuilder_build(t *testing.T) {
|
||||||
tarContent := generateTar(t, dir, filename)
|
tarContent := generateTar(t, dir, filename)
|
||||||
|
|
||||||
ch := NewCompositeCache("", fmt.Sprintf("COPY %s foo.txt", filename))
|
ch := NewCompositeCache("", fmt.Sprintf("COPY %s foo.txt", filename))
|
||||||
ch.AddPath(filepath, util.FileContext{})
|
ch.AddPath(filepath, util.FileContext{}, false)
|
||||||
|
|
||||||
hash, err := ch.Hash()
|
hash, err := ch.Hash()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -1119,7 +1119,7 @@ func Test_stageBuilder_build(t *testing.T) {
|
||||||
destDir := t.TempDir()
|
destDir := t.TempDir()
|
||||||
filePath := filepath.Join(dir, filename)
|
filePath := filepath.Join(dir, filename)
|
||||||
ch := NewCompositeCache("", fmt.Sprintf("COPY %s foo.txt", filename))
|
ch := NewCompositeCache("", fmt.Sprintf("COPY %s foo.txt", filename))
|
||||||
ch.AddPath(filePath, util.FileContext{})
|
ch.AddPath(filePath, util.FileContext{}, false)
|
||||||
|
|
||||||
hash, err := ch.Hash()
|
hash, err := ch.Hash()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -1185,7 +1185,7 @@ COPY %s foo.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
ch.AddKey(fmt.Sprintf("COPY %s bar.txt", filename))
|
ch.AddKey(fmt.Sprintf("COPY %s bar.txt", filename))
|
||||||
ch.AddPath(filePath, util.FileContext{})
|
ch.AddPath(filePath, util.FileContext{}, false)
|
||||||
|
|
||||||
hash2, err := ch.Hash()
|
hash2, err := ch.Hash()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -1193,7 +1193,7 @@ COPY %s foo.txt
|
||||||
}
|
}
|
||||||
ch = NewCompositeCache("", fmt.Sprintf("COPY %s foo.txt", filename))
|
ch = NewCompositeCache("", fmt.Sprintf("COPY %s foo.txt", filename))
|
||||||
ch.AddKey(fmt.Sprintf("COPY %s bar.txt", filename))
|
ch.AddKey(fmt.Sprintf("COPY %s bar.txt", filename))
|
||||||
ch.AddPath(filePath, util.FileContext{})
|
ch.AddPath(filePath, util.FileContext{}, false)
|
||||||
|
|
||||||
image := fakeImage{
|
image := fakeImage{
|
||||||
ImageLayers: []v1.Layer{
|
ImageLayers: []v1.Layer{
|
||||||
|
|
@ -1253,7 +1253,7 @@ COPY %s bar.txt
|
||||||
filePath := filepath.Join(dir, filename)
|
filePath := filepath.Join(dir, filename)
|
||||||
|
|
||||||
ch := NewCompositeCache("", fmt.Sprintf("COPY %s bar.txt", filename))
|
ch := NewCompositeCache("", fmt.Sprintf("COPY %s bar.txt", filename))
|
||||||
ch.AddPath(filePath, util.FileContext{})
|
ch.AddPath(filePath, util.FileContext{}, false)
|
||||||
|
|
||||||
// copy hash
|
// copy hash
|
||||||
_, err := ch.Hash()
|
_, err := ch.Hash()
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ func (s *CompositeCache) Hash() (string, error) {
|
||||||
return util.SHA256(strings.NewReader(s.Key()))
|
return util.SHA256(strings.NewReader(s.Key()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *CompositeCache) AddPath(p string, context util.FileContext) error {
|
func (s *CompositeCache) AddPath(p string, context util.FileContext, considerExcludedFiles bool) error {
|
||||||
sha := sha256.New()
|
sha := sha256.New()
|
||||||
fi, err := os.Lstat(p)
|
fi, err := os.Lstat(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -70,7 +70,7 @@ func (s *CompositeCache) AddPath(p string, context util.FileContext) error {
|
||||||
|
|
||||||
// Only add the hash of this directory to the key
|
// Only add the hash of this directory to the key
|
||||||
// if there is any ignored content.
|
// if there is any ignored content.
|
||||||
if !empty || !context.ExcludesFile(p) {
|
if !empty || considerExcludedFiles || !context.ExcludesFile(p) {
|
||||||
s.keys = append(s.keys, k)
|
s.keys = append(s.keys, k)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func Test_CompositeCache_AddPath_dir(t *testing.T) {
|
||||||
|
|
||||||
fn := func() string {
|
fn := func() string {
|
||||||
r := NewCompositeCache()
|
r := NewCompositeCache()
|
||||||
if err := r.AddPath(tmpDir, util.FileContext{}); err != nil {
|
if err := r.AddPath(tmpDir, util.FileContext{}, false); err != nil {
|
||||||
t.Errorf("expected error to be nil but was %v", err)
|
t.Errorf("expected error to be nil but was %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ func Test_CompositeCache_AddPath_file(t *testing.T) {
|
||||||
p := tmpfile.Name()
|
p := tmpfile.Name()
|
||||||
fn := func() string {
|
fn := func() string {
|
||||||
r := NewCompositeCache()
|
r := NewCompositeCache()
|
||||||
if err := r.AddPath(p, util.FileContext{}); err != nil {
|
if err := r.AddPath(p, util.FileContext{}, false); err != nil {
|
||||||
t.Errorf("expected error to be nil but was %v", err)
|
t.Errorf("expected error to be nil but was %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,7 +166,7 @@ func setIgnoreContext(t *testing.T, content string) (util.FileContext, error) {
|
||||||
|
|
||||||
func hashDirectory(dirpath string, fileContext util.FileContext) (string, error) {
|
func hashDirectory(dirpath string, fileContext util.FileContext) (string, error) {
|
||||||
cache1 := NewCompositeCache()
|
cache1 := NewCompositeCache()
|
||||||
err := cache1.AddPath(dirpath, fileContext)
|
err := cache1.AddPath(dirpath, fileContext, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ type MockDockerCommand struct {
|
||||||
contextFiles []string
|
contextFiles []string
|
||||||
cacheCommand commands.DockerCommand
|
cacheCommand commands.DockerCommand
|
||||||
argToCompositeCache bool
|
argToCompositeCache bool
|
||||||
|
considerExcludedFiles bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MockDockerCommand) ExecuteCommand(c *v1.Config, args *dockerfile.BuildArgs) error { return nil }
|
func (m MockDockerCommand) ExecuteCommand(c *v1.Config, args *dockerfile.BuildArgs) error { return nil }
|
||||||
|
|
@ -83,10 +84,14 @@ func (m MockDockerCommand) ShouldDetectDeletedFiles() bool {
|
||||||
func (m MockDockerCommand) IsArgsEnvsRequiredInCache() bool {
|
func (m MockDockerCommand) IsArgsEnvsRequiredInCache() bool {
|
||||||
return m.argToCompositeCache
|
return m.argToCompositeCache
|
||||||
}
|
}
|
||||||
|
func (m MockDockerCommand) IsConsiderExcludedFilesInCache() bool {
|
||||||
|
return m.argToCompositeCache
|
||||||
|
}
|
||||||
|
|
||||||
type MockCachedDockerCommand struct {
|
type MockCachedDockerCommand struct {
|
||||||
contextFiles []string
|
contextFiles []string
|
||||||
argToCompositeCache bool
|
argToCompositeCache bool
|
||||||
|
considerExcludedFiles bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MockCachedDockerCommand) ExecuteCommand(c *v1.Config, args *dockerfile.BuildArgs) error {
|
func (m MockCachedDockerCommand) ExecuteCommand(c *v1.Config, args *dockerfile.BuildArgs) error {
|
||||||
|
|
@ -122,6 +127,9 @@ func (m MockCachedDockerCommand) ShouldCacheOutput() bool {
|
||||||
func (m MockCachedDockerCommand) IsArgsEnvsRequiredInCache() bool {
|
func (m MockCachedDockerCommand) IsArgsEnvsRequiredInCache() bool {
|
||||||
return m.argToCompositeCache
|
return m.argToCompositeCache
|
||||||
}
|
}
|
||||||
|
func (m MockCachedDockerCommand) IsConsiderExcludedFilesInCache() bool {
|
||||||
|
return m.considerExcludedFiles
|
||||||
|
}
|
||||||
|
|
||||||
type fakeLayerCache struct {
|
type fakeLayerCache struct {
|
||||||
retrieve bool
|
retrieve bool
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue