Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/executor"
"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
"github.com/GoogleContainerTools/kaniko/pkg/logging"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/util"
Expand Down Expand Up @@ -210,7 +211,7 @@ var RootCmd = &cobra.Command{
}
logrus.Infof("Benchmark file written at %s", benchmarkFile)
} else {
f, err := os.Create(benchmarkFile)
f, err := filesystem.FS.Create(benchmarkFile)
if err != nil {
logrus.Warnf("Unable to create benchmarking file %s: %s", benchmarkFile, err)
return
Expand Down Expand Up @@ -305,7 +306,7 @@ func checkKanikoDir(dir string) error {
return err
}

if err := os.RemoveAll(constants.DefaultKanikoPath); err != nil {
if err := filesystem.FS.RemoveAll(constants.DefaultKanikoPath); err != nil {
return err
}
// After remove DefaultKankoPath, the DOKCER_CONFIG env will point to a non-exist dir, so we should update DOCKER_CONFIG env to new dir
Expand Down Expand Up @@ -437,7 +438,7 @@ func resolveSourceContext() error {
}
if ctxSubPath != "" {
opts.SrcContext = filepath.Join(opts.SrcContext, ctxSubPath)
if _, err := os.Stat(opts.SrcContext); os.IsNotExist(err) {
if _, err := filesystem.FS.Stat(opts.SrcContext); os.IsNotExist(err) {
return err
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/warmer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/GoogleContainerTools/kaniko/pkg/cache"
"github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
"github.com/GoogleContainerTools/kaniko/pkg/logging"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/containerd/containerd/platforms"
Expand Down Expand Up @@ -70,16 +71,15 @@ var RootCmd = &cobra.Command{
return nil
},
Run: func(cmd *cobra.Command, args []string) {
if _, err := os.Stat(opts.CacheDir); os.IsNotExist(err) {
err = os.MkdirAll(opts.CacheDir, 0755)
if _, err := filesystem.FS.Stat(opts.CacheDir); os.IsNotExist(err) {
err = filesystem.MkdirAll(opts.CacheDir, 0o755)
if err != nil {
exit(errors.Wrap(err, "Failed to create cache directory"))
}
}
if err := cache.WarmCache(opts); err != nil {
exit(errors.Wrap(err, "Failed warming cache"))
}

},
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
require (
github.com/GoogleCloudPlatform/docker-credential-gcr/v2 v2.1.22
github.com/containerd/containerd v1.7.19
github.com/twpayne/go-vfs/v5 v5.0.4
)

require github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/toqueteos/webbrowser v1.2.0 h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
github.com/twpayne/go-vfs/v5 v5.0.4 h1:/ne3h+rW7f5YOyOFguz+3ztfUwzOLR0Vts3y0mMAitg=
github.com/twpayne/go-vfs/v5 v5.0.4/go.mod h1:zTPFJUbgsEMFNSWnWQlLq9wh4AN83edZzx3VXbxrS1w=
github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=
github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
Expand Down
11 changes: 6 additions & 5 deletions integration/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"sync"
"testing"
"time"

"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
)

type result struct {
Expand Down Expand Up @@ -68,7 +70,7 @@ func TestSnapshotBenchmark(t *testing.T) {
r := newResult(t, filepath.Join(benchmarkDir, dockerfile))
timeMap.Store(num, r)
wg.Done()
defer os.Remove(benchmarkDir)
defer filesystem.FS.Remove(benchmarkDir)
}(num, &err)
if err != nil {
t.Errorf("could not run benchmark results for num %d due to %s", num, err)
Expand All @@ -84,12 +86,11 @@ func TestSnapshotBenchmark(t *testing.T) {
t.Logf("%d,%f,%f,%f", d, v.totalBuildTime, v.walkingFiles, v.resolvingFiles)
return true
})

}

func newResult(t *testing.T, f string) result {
var current map[string]time.Duration
jsonFile, err := os.Open(f)
jsonFile, err := filesystem.FS.Open(f)
defer jsonFile.Close()
if err != nil {
t.Errorf("could not read benchmark file %s", f)
Expand Down Expand Up @@ -141,7 +142,7 @@ func TestSnapshotBenchmarkGcloud(t *testing.T) {
r := newResult(t, filepath.Join(dir, "results"))
t.Log(fmt.Sprintf("%d,%f,%f,%f, %f", num, r.totalBuildTime, r.walkingFiles, r.resolvingFiles, r.hashingFiles))
wg.Done()
defer os.Remove(dir)
defer filesystem.FS.Remove(dir)
defer os.Chdir(cwd)
}(num)
})
Expand All @@ -160,7 +161,7 @@ func runInGcloud(dir string, num int) (string, error) {
}

// grab gcs and to temp dir and return
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%d", num))
tmpDir, err := filesystem.MkdirTemp("", fmt.Sprintf("%d", num))
if err != nil {
return "", err
}
Expand Down
7 changes: 4 additions & 3 deletions integration/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"time"

"cloud.google.com/go/storage"
"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/GoogleContainerTools/kaniko/pkg/util/bucket"
Expand Down Expand Up @@ -379,7 +380,7 @@ func (d *DockerFileBuilder) buildCachedImage(config *integrationTestConfig, cach

benchmarkEnv := "BENCHMARK_FILE=false"
if b, err := strconv.ParseBool(os.Getenv("BENCHMARK")); err == nil && b {
os.Mkdir("benchmarks", 0o755)
filesystem.FS.Mkdir("benchmarks", 0o755)
benchmarkEnv = "BENCHMARK_FILE=/workspace/benchmarks/" + dockerfile
}
kanikoImage := GetVersionedKanikoImage(imageRepo, dockerfile, version)
Expand Down Expand Up @@ -470,7 +471,7 @@ func buildKanikoImage(
shdUpload bool,
) (string, error) {
benchmarkEnv := "BENCHMARK_FILE=false"
benchmarkDir, err := os.MkdirTemp("", "")
benchmarkDir, err := filesystem.MkdirTemp("", "")
if err != nil {
return "", err
}
Expand All @@ -480,7 +481,7 @@ func buildKanikoImage(
benchmarkFile := path.Join(benchmarkDir, dockerfile)
fileName := fmt.Sprintf("run_%s_%s", time.Now().Format("2006-01-02-15:04"), dockerfile)
dst := path.Join("benchmarks", fileName)
file, err := os.Open(benchmarkFile)
file, err := filesystem.FS.Open(benchmarkFile)
if err != nil {
return "", err
}
Expand Down
9 changes: 5 additions & 4 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/pkg/errors"
"google.golang.org/api/option"

"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/GoogleContainerTools/kaniko/pkg/util/bucket"
Expand Down Expand Up @@ -104,7 +105,7 @@ func launchTests(m *testing.M) (int, error) {
if err != nil {
return 1, errors.Wrap(err, "failed to get bucket name from uri")
}
contextFile, err := os.Open(contextFilePath)
contextFile, err := filesystem.FS.Open(contextFilePath)
if err != nil {
return 1, fmt.Errorf("failed to read file at path %v: %w", contextFilePath, err)
}
Expand All @@ -113,7 +114,7 @@ func launchTests(m *testing.M) (int, error) {
return 1, errors.Wrap(err, "Failed to upload build context")
}

if err = os.Remove(contextFilePath); err != nil {
if err = filesystem.FS.Remove(contextFilePath); err != nil {
return 1, errors.Wrap(err, fmt.Sprintf("Failed to remove tarball at %s", contextFilePath))
}

Expand Down Expand Up @@ -1035,7 +1036,7 @@ func getLastLayerFiles(image string) ([]string, error) {

func logBenchmarks(benchmark string) error {
if b, err := strconv.ParseBool(os.Getenv("BENCHMARK")); err == nil && b {
f, err := os.Create(benchmark)
f, err := filesystem.FS.Create(benchmark)
if err != nil {
return err
}
Expand Down Expand Up @@ -1074,7 +1075,7 @@ func initIntegrationTestConfig() *integrationTestConfig {
if err != nil {
log.Fatalf("Error getting absolute path for service account: %s\n", c.serviceAccount)
}
if _, err := os.Stat(absPath); os.IsNotExist(err) {
if _, err := filesystem.FS.Stat(absPath); os.IsNotExist(err) {
log.Fatalf("Service account does not exist: %s\n", absPath)
}
c.serviceAccount = absPath
Expand Down
5 changes: 3 additions & 2 deletions integration/integration_with_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"os"
"path/filepath"
"testing"

"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
)

func TestWithContext(t *testing.T) {
Expand All @@ -31,7 +33,7 @@ func TestWithContext(t *testing.T) {
}

dir := filepath.Join(cwd, "dockerfiles-with-context")
entries, err := os.ReadDir(dir)
entries, err := filesystem.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -68,7 +70,6 @@ func TestWithContext(t *testing.T) {

expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)

})
}

Expand Down
13 changes: 8 additions & 5 deletions integration/integration_with_stdin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sync"
"testing"

"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/GoogleContainerTools/kaniko/testutil"
)
Expand All @@ -37,7 +38,7 @@ func TestBuildWithStdin(t *testing.T) {
testDir := "test_dir"
testDirLongPath := filepath.Join(cwd, testDir)

if err := os.MkdirAll(testDirLongPath, 0750); err != nil {
if err := filesystem.MkdirAll(testDirLongPath, 0o750); err != nil {
t.Errorf("Failed to create dir_where_to_extract: %v", err)
}

Expand All @@ -62,7 +63,7 @@ func TestBuildWithStdin(t *testing.T) {
// Create Tar Gz File with dockerfile inside
go func(wg *sync.WaitGroup) {
defer wg.Done()
tarFile, err := os.Create(tarPath)
tarFile, err := filesystem.FS.Create(tarPath)
if err != nil {
t.Errorf("Failed to create %s: %v", tarPath, err)
}
Expand All @@ -86,10 +87,12 @@ func TestBuildWithStdin(t *testing.T) {

dockerImage := GetDockerImage(config.imageRepo, dockerfile)
dockerCmd := exec.Command("docker",
append([]string{"build",
append([]string{
"build",
"-t", dockerImage,
"-f", dockerfile,
"."})...)
".",
})...)

_, err := RunCommandWithoutTest(dockerCmd)
if err != nil {
Expand Down Expand Up @@ -145,7 +148,7 @@ func TestBuildWithStdin(t *testing.T) {
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImageStdin, dockerImage, kanikoImageStdin)
checkContainerDiffOutput(t, diff, expected)

if err := os.RemoveAll(testDirLongPath); err != nil {
if err := filesystem.FS.RemoveAll(testDirLongPath); err != nil {
t.Errorf("Failed to remove %s: %v", testDirLongPath, err)
}
}
10 changes: 6 additions & 4 deletions integration/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"path/filepath"
"testing"
"text/template"

"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
)

type K8sConfig struct {
Expand All @@ -41,7 +43,7 @@ func TestK8s(t *testing.T) {

dir := filepath.Join(cwd, "dockerfiles-with-context")

entries, err := os.ReadDir(dir)
entries, err := filesystem.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -73,11 +75,11 @@ func TestK8s(t *testing.T) {
dockerImage := GetDockerImage(config.imageRepo, name)
kanikoImage := GetKanikoImage(config.imageRepo, name)

tmpfile, err := os.CreateTemp("", "k8s-job-*.yaml")
tmpfile, err := filesystem.CreateTemp("", "k8s-job-*.yaml")
if err != nil {
log.Fatal(err)
}
defer os.Remove(tmpfile.Name()) // clean up
defer filesystem.FS.Remove(tmpfile.Name()) // clean up
tmpl := template.Must(template.ParseFiles("k8s-job.yaml"))
job := K8sConfig{KanikoImage: kanikoImage, Context: testDir, Name: name}
if err := tmpl.Execute(tmpfile, job); err != nil {
Expand All @@ -86,7 +88,7 @@ func TestK8s(t *testing.T) {

t.Logf("Testing K8s based Kaniko building of dockerfile %s and push to %s \n",
testDir, kanikoImage)
content, err := os.ReadFile(tmpfile.Name())
content, err := filesystem.ReadFile(tmpfile.Name())
if err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions integration/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"time"

"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
"github.com/GoogleContainerTools/kaniko/pkg/util"
)

Expand All @@ -34,13 +35,13 @@ func CreateIntegrationTarball() (string, error) {
if err != nil {
return "nil", fmt.Errorf("Failed find path to integration dir: %w", err)
}
tempDir, err := os.MkdirTemp("", "")
tempDir, err := filesystem.MkdirTemp("", "")
if err != nil {
return "", fmt.Errorf("Failed to create temporary directory to hold tarball: %w", err)
}
contextFilePath := fmt.Sprintf("%s/context_%d.tar.gz", tempDir, time.Now().UnixNano())

file, err := os.OpenFile(contextFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
file, err := filesystem.FS.OpenFile(contextFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/buildcontext/azureblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
kConfig "github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
"github.com/GoogleContainerTools/kaniko/pkg/util"
)

Expand All @@ -36,7 +37,6 @@ type AzureBlob struct {

// Download context file from given azure blob storage url and unpack it to BuildContextDir
func (b *AzureBlob) UnpackTarFromBuildContext() (string, error) {

// Get Azure_STORAGE_ACCESS_KEY from environment variables
accountKey := os.Getenv("AZURE_STORAGE_ACCESS_KEY")
if len(accountKey) == 0 {
Expand Down Expand Up @@ -79,5 +79,5 @@ func (b *AzureBlob) UnpackTarFromBuildContext() (string, error) {
return tarPath, err
}
// Remove the tar so it doesn't interfere with subsequent commands
return directory, os.Remove(tarPath)
return directory, filesystem.FS.Remove(tarPath)
}
Loading