fix: Remove references to deprecated io/ioutil pkg (#2867)
* Update benchmark_test * Updae tar.go * Update further refs * Commit next set of replacements * Reverting changes in vendor folder * Update integreation_with_context_test.go * Update k8s_test.go * Update remaining usages * Replace conflicting usage of fs local variable
This commit is contained in:
parent
2b3d3c7eff
commit
7bfc73c3ad
|
|
@ -19,7 +19,7 @@ package integration
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -94,7 +94,7 @@ func newResult(t *testing.T, f string) result {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("could not read benchmark file %s", f)
|
t.Errorf("could not read benchmark file %s", f)
|
||||||
}
|
}
|
||||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
byteValue, _ := io.ReadAll(jsonFile)
|
||||||
if err := json.Unmarshal(byteValue, ¤t); err != nil {
|
if err := json.Unmarshal(byteValue, ¤t); err != nil {
|
||||||
t.Errorf("could not unmarshal benchmark file")
|
t.Errorf("could not unmarshal benchmark file")
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +160,7 @@ func runInGcloud(dir string, num int) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab gcs and to temp dir and return
|
// grab gcs and to temp dir and return
|
||||||
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("%d", num))
|
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%d", num))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -459,7 +458,7 @@ func buildKanikoImage(
|
||||||
shdUpload bool,
|
shdUpload bool,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
benchmarkEnv := "BENCHMARK_FILE=false"
|
benchmarkEnv := "BENCHMARK_FILE=false"
|
||||||
benchmarkDir, err := ioutil.TempDir("", "")
|
benchmarkDir, err := os.MkdirTemp("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -31,12 +31,21 @@ func TestWithContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := filepath.Join(cwd, "dockerfiles-with-context")
|
dir := filepath.Join(cwd, "dockerfiles-with-context")
|
||||||
|
entries, err := os.ReadDir(dir)
|
||||||
testDirs, err := ioutil.ReadDir(dir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testDirs := make([]fs.FileInfo, 0, len(entries))
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
info, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
testDirs = append(testDirs, info)
|
||||||
|
}
|
||||||
|
|
||||||
builder := NewDockerFileBuilder()
|
builder := NewDockerFileBuilder()
|
||||||
|
|
||||||
for _, tdInfo := range testDirs {
|
for _, tdInfo := range testDirs {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -41,10 +41,19 @@ func TestK8s(t *testing.T) {
|
||||||
|
|
||||||
dir := filepath.Join(cwd, "dockerfiles-with-context")
|
dir := filepath.Join(cwd, "dockerfiles-with-context")
|
||||||
|
|
||||||
testDirs, err := ioutil.ReadDir(dir)
|
entries, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
testDirs := make([]fs.FileInfo, 0, len(entries))
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
info, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
testDirs = append(testDirs, info)
|
||||||
|
}
|
||||||
|
|
||||||
builder := NewDockerFileBuilder()
|
builder := NewDockerFileBuilder()
|
||||||
|
|
||||||
|
|
@ -64,7 +73,7 @@ func TestK8s(t *testing.T) {
|
||||||
dockerImage := GetDockerImage(config.imageRepo, name)
|
dockerImage := GetDockerImage(config.imageRepo, name)
|
||||||
kanikoImage := GetKanikoImage(config.imageRepo, name)
|
kanikoImage := GetKanikoImage(config.imageRepo, name)
|
||||||
|
|
||||||
tmpfile, err := ioutil.TempFile("", "k8s-job-*.yaml")
|
tmpfile, err := os.CreateTemp("", "k8s-job-*.yaml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +86,7 @@ func TestK8s(t *testing.T) {
|
||||||
|
|
||||||
t.Logf("Testing K8s based Kaniko building of dockerfile %s and push to %s \n",
|
t.Logf("Testing K8s based Kaniko building of dockerfile %s and push to %s \n",
|
||||||
testDir, kanikoImage)
|
testDir, kanikoImage)
|
||||||
content, err := ioutil.ReadFile(tmpfile.Name())
|
content, err := os.ReadFile(tmpfile.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package integration
|
||||||
import (
|
import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -35,7 +34,7 @@ func CreateIntegrationTarball() (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "nil", fmt.Errorf("Failed find path to integration dir: %w", err)
|
return "nil", fmt.Errorf("Failed find path to integration dir: %w", err)
|
||||||
}
|
}
|
||||||
tempDir, err := ioutil.TempDir("", "")
|
tempDir, err := os.MkdirTemp("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Failed to create temporary directory to hold tarball: %w", err)
|
return "", fmt.Errorf("Failed to create temporary directory to hold tarball: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -145,7 +144,7 @@ func TestBuildWithLocalTar(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSHAFromFilePath(f string) (string, error) {
|
func getSHAFromFilePath(f string) (string, error) {
|
||||||
data, err := ioutil.ReadFile(f)
|
data, err := os.ReadFile(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -109,7 +108,7 @@ func writeBufsToFile(cachePath string, tarBuf, manifestBuf *bytes.Buffer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
mfstPath := cachePath + ".json"
|
mfstPath := cachePath + ".json"
|
||||||
if err := ioutil.WriteFile(mfstPath, manifestBuf.Bytes(), 0666); err != nil {
|
if err := os.WriteFile(mfstPath, manifestBuf.Bytes(), 0666); err != nil {
|
||||||
return errors.Wrap(err, "Failed to save manifest to file")
|
return errors.Wrap(err, "Failed to save manifest to file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,9 +185,9 @@ func ParseDockerfile(opts *config.WarmerOptions) ([]string, error) {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
d, err = ioutil.ReadAll(response.Body)
|
d, err = io.ReadAll(response.Body)
|
||||||
} else {
|
} else {
|
||||||
d, err = ioutil.ReadFile(opts.DockerfilePath)
|
d, err = os.ReadFile(opts.DockerfilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -119,7 +118,7 @@ func TestParseDockerfile_SingleStageDockerfile(t *testing.T) {
|
||||||
dockerfile := `FROM alpine:latest
|
dockerfile := `FROM alpine:latest
|
||||||
LABEL maintainer="alexezio"
|
LABEL maintainer="alexezio"
|
||||||
`
|
`
|
||||||
tmpfile, err := ioutil.TempFile("", "example")
|
tmpfile, err := os.CreateTemp("", "example")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +151,7 @@ LABEL maintainer="alexezio"
|
||||||
FROM alpine:latest as RUNNER
|
FROM alpine:latest as RUNNER
|
||||||
LABEL maintainer="alexezio"
|
LABEL maintainer="alexezio"
|
||||||
`
|
`
|
||||||
tmpfile, err := ioutil.TempFile("", "example")
|
tmpfile, err := os.CreateTemp("", "example")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +185,7 @@ func TestParseDockerfile_ArgsDockerfile(t *testing.T) {
|
||||||
dockerfile := `ARG version=latest
|
dockerfile := `ARG version=latest
|
||||||
FROM golang:${version}
|
FROM golang:${version}
|
||||||
`
|
`
|
||||||
tmpfile, err := ioutil.TempFile("", "example")
|
tmpfile, err := os.CreateTemp("", "example")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -225,7 +224,7 @@ func TestParseDockerfile_MissingsDockerfile(t *testing.T) {
|
||||||
|
|
||||||
func TestParseDockerfile_InvalidsDockerfile(t *testing.T) {
|
func TestParseDockerfile_InvalidsDockerfile(t *testing.T) {
|
||||||
dockerfile := "This is a invalid dockerfile"
|
dockerfile := "This is a invalid dockerfile"
|
||||||
tmpfile, err := ioutil.TempFile("", "example")
|
tmpfile, err := os.CreateTemp("", "example")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -126,6 +125,24 @@ func setupTestTemp(t *testing.T) string {
|
||||||
return tempDir
|
return tempDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readDirectory(dirName string) ([]fs.FileInfo, error) {
|
||||||
|
entries, err := os.ReadDir(dirName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
testDir := make([]fs.FileInfo, 0, len(entries))
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
info, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
testDir = append(testDir, info)
|
||||||
|
}
|
||||||
|
return testDir, err
|
||||||
|
}
|
||||||
|
|
||||||
func Test_CachingCopyCommand_ExecuteCommand(t *testing.T) {
|
func Test_CachingCopyCommand_ExecuteCommand(t *testing.T) {
|
||||||
tempDir := setupTestTemp(t)
|
tempDir := setupTestTemp(t)
|
||||||
|
|
||||||
|
|
@ -320,7 +337,7 @@ func TestCopyExecuteCmd(t *testing.T) {
|
||||||
return // Unrecoverable, will segfault in the next line
|
return // Unrecoverable, will segfault in the next line
|
||||||
}
|
}
|
||||||
if fstat.IsDir() {
|
if fstat.IsDir() {
|
||||||
files, err := ioutil.ReadDir(dest)
|
files, err := readDirectory(dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error()
|
t.Error()
|
||||||
}
|
}
|
||||||
|
|
@ -358,12 +375,12 @@ func Test_resolveIfSymlink(t *testing.T) {
|
||||||
|
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
baseDir, err := ioutil.TempDir(tmpDir, "not-linked")
|
baseDir, err := os.MkdirTemp(tmpDir, "not-linked")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
path, err := ioutil.TempFile(baseDir, "foo.txt")
|
path, err := os.CreateTemp(baseDir, "foo.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
@ -420,11 +437,11 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
}
|
}
|
||||||
file := filepath.Join(dir, "bam.txt")
|
file := filepath.Join(dir, "bam.txt")
|
||||||
|
|
||||||
if err := ioutil.WriteFile(file, []byte("meow"), 0777); err != nil {
|
if err := os.WriteFile(file, []byte("meow"), 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
targetPath := filepath.Join(dir, "dam.txt")
|
targetPath := filepath.Join(dir, "dam.txt")
|
||||||
if err := ioutil.WriteFile(targetPath, []byte("woof"), 0777); err != nil {
|
if err := os.WriteFile(targetPath, []byte("woof"), 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := os.Symlink("dam.txt", filepath.Join(dir, "sym.link")); err != nil {
|
if err := os.Symlink("dam.txt", filepath.Join(dir, "sym.link")); err != nil {
|
||||||
|
|
@ -437,7 +454,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
t.Run("copy dir to another dir", func(t *testing.T) {
|
t.Run("copy dir to another dir", func(t *testing.T) {
|
||||||
testDir, srcDir := setupDirs(t)
|
testDir, srcDir := setupDirs(t)
|
||||||
defer os.RemoveAll(testDir)
|
defer os.RemoveAll(testDir)
|
||||||
expected, err := ioutil.ReadDir(filepath.Join(testDir, srcDir))
|
expected, err := readDirectory(filepath.Join(testDir, srcDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -461,7 +478,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
}
|
}
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "dest" dir exists with contents of srcDir
|
// Check if "dest" dir exists with contents of srcDir
|
||||||
actual, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
|
actual, err := readDirectory(filepath.Join(testDir, "dest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -475,7 +492,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
testDir, srcDir := setupDirs(t)
|
testDir, srcDir := setupDirs(t)
|
||||||
defer os.RemoveAll(testDir)
|
defer os.RemoveAll(testDir)
|
||||||
ignoredFile := "bam.txt"
|
ignoredFile := "bam.txt"
|
||||||
srcFiles, err := ioutil.ReadDir(filepath.Join(testDir, srcDir))
|
srcFiles, err := readDirectory(filepath.Join(testDir, srcDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -508,7 +525,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
}
|
}
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "dest" dir exists with contents of srcDir
|
// Check if "dest" dir exists with contents of srcDir
|
||||||
actual, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
|
actual, err := readDirectory(filepath.Join(testDir, "dest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -544,7 +561,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "dest" dir exists with file bam.txt
|
// Check if "dest" dir exists with file bam.txt
|
||||||
files, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
|
files, err := readDirectory(filepath.Join(testDir, "dest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -600,7 +617,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "dest" dir exists with file bam.txt
|
// Check if "dest" dir exists with file bam.txt
|
||||||
files, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
|
files, err := readDirectory(filepath.Join(testDir, "dest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -629,7 +646,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "dest" dir exists with link sym.link
|
// Check if "dest" dir exists with link sym.link
|
||||||
files, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
|
files, err := readDirectory(filepath.Join(testDir, "dest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -648,7 +665,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
testDir, srcDir := setupDirs(t)
|
testDir, srcDir := setupDirs(t)
|
||||||
defer os.RemoveAll(testDir)
|
defer os.RemoveAll(testDir)
|
||||||
doesNotExists := filepath.Join(testDir, "dead.txt")
|
doesNotExists := filepath.Join(testDir, "dead.txt")
|
||||||
if err := ioutil.WriteFile(doesNotExists, []byte("remove me"), 0777); err != nil {
|
if err := os.WriteFile(doesNotExists, []byte("remove me"), 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := os.Symlink("../dead.txt", filepath.Join(testDir, srcDir, "dead.link")); err != nil {
|
if err := os.Symlink("../dead.txt", filepath.Join(testDir, srcDir, "dead.link")); err != nil {
|
||||||
|
|
@ -674,7 +691,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "dest" dir exists with link dead.link
|
// Check if "dest" dir exists with link dead.link
|
||||||
files, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
|
files, err := readDirectory(filepath.Join(testDir, "dest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -728,7 +745,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
t.Run("copy dir with a symlink to a file outside of current src dir", func(t *testing.T) {
|
t.Run("copy dir with a symlink to a file outside of current src dir", func(t *testing.T) {
|
||||||
testDir, srcDir := setupDirs(t)
|
testDir, srcDir := setupDirs(t)
|
||||||
defer os.RemoveAll(testDir)
|
defer os.RemoveAll(testDir)
|
||||||
expected, err := ioutil.ReadDir(filepath.Join(testDir, srcDir))
|
expected, err := readDirectory(filepath.Join(testDir, srcDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -738,7 +755,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
targetPath := filepath.Join(anotherSrc, "target.txt")
|
targetPath := filepath.Join(anotherSrc, "target.txt")
|
||||||
if err := ioutil.WriteFile(targetPath, []byte("woof"), 0777); err != nil {
|
if err := os.WriteFile(targetPath, []byte("woof"), 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := os.Symlink(targetPath, filepath.Join(testDir, srcDir, "zSym.link")); err != nil {
|
if err := os.Symlink(targetPath, filepath.Join(testDir, srcDir, "zSym.link")); err != nil {
|
||||||
|
|
@ -762,7 +779,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "dest" dir exists contents of srcDir and an extra zSym.link created
|
// Check if "dest" dir exists contents of srcDir and an extra zSym.link created
|
||||||
// in this test
|
// in this test
|
||||||
actual, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
|
actual, err := readDirectory(filepath.Join(testDir, "dest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -818,7 +835,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
t.Run("copy src dir to a dest dir which is a symlink", func(t *testing.T) {
|
t.Run("copy src dir to a dest dir which is a symlink", func(t *testing.T) {
|
||||||
testDir, srcDir := setupDirs(t)
|
testDir, srcDir := setupDirs(t)
|
||||||
defer os.RemoveAll(testDir)
|
defer os.RemoveAll(testDir)
|
||||||
expected, err := ioutil.ReadDir(filepath.Join(testDir, srcDir))
|
expected, err := readDirectory(filepath.Join(testDir, srcDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -848,7 +865,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
err = cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
err = cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "linkdest" dir exists with contents of srcDir
|
// Check if "linkdest" dir exists with contents of srcDir
|
||||||
actual, err := ioutil.ReadDir(filepath.Join(testDir, "linkDest"))
|
actual, err := readDirectory(filepath.Join(testDir, "linkDest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -893,12 +910,12 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check if "linkDest" link is same.
|
// Check if "linkDest" link is same.
|
||||||
actual, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
|
actual, err := readDirectory(filepath.Join(testDir, "dest"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
testutil.CheckDeepEqual(t, "bam.txt", actual[0].Name())
|
testutil.CheckDeepEqual(t, "bam.txt", actual[0].Name())
|
||||||
c, err := ioutil.ReadFile(filepath.Join(testDir, "dest", "bam.txt"))
|
c, err := os.ReadFile(filepath.Join(testDir, "dest", "bam.txt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -942,7 +959,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
|
||||||
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
|
|
||||||
actual, err := ioutil.ReadDir(filepath.Join(testDir))
|
actual, err := readDirectory(filepath.Join(testDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ package commands
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/types"
|
"github.com/google/go-containerregistry/pkg/v1/types"
|
||||||
|
|
@ -40,7 +39,7 @@ func (f fakeLayer) Compressed() (io.ReadCloser, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
func (f fakeLayer) Uncompressed() (io.ReadCloser, error) {
|
func (f fakeLayer) Uncompressed() (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(bytes.NewReader(f.TarContent)), nil
|
return io.NopCloser(bytes.NewReader(f.TarContent)), nil
|
||||||
}
|
}
|
||||||
func (f fakeLayer) Size() (int64, error) {
|
func (f fakeLayer) Size() (int64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
|
@ -130,7 +129,7 @@ Meow meow meow meow
|
||||||
meow meow meow meow
|
meow meow meow meow
|
||||||
`
|
`
|
||||||
for _, name := range fileNames {
|
for _, name := range fileNames {
|
||||||
if err := ioutil.WriteFile(filepath.Join(dir, name), []byte(content), 0777); err != nil {
|
if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0777); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +152,7 @@ meow meow meow meow
|
||||||
if err := tw.WriteHeader(hdr); err != nil {
|
if err := tw.WriteHeader(hdr); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
body, err := ioutil.ReadFile(path)
|
body, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
package creds
|
package creds
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
ecr "github.com/awslabs/amazon-ecr-credential-helper/ecr-login"
|
ecr "github.com/awslabs/amazon-ecr-credential-helper/ecr-login"
|
||||||
"github.com/chrismellard/docker-credential-acr-env/pkg/credhelper"
|
"github.com/chrismellard/docker-credential-acr-env/pkg/credhelper"
|
||||||
|
|
@ -31,7 +31,7 @@ func GetKeychain() authn.Keychain {
|
||||||
return authn.NewMultiKeychain(
|
return authn.NewMultiKeychain(
|
||||||
authn.DefaultKeychain,
|
authn.DefaultKeychain,
|
||||||
google.Keychain,
|
google.Keychain,
|
||||||
authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(ioutil.Discard))),
|
authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(io.Discard))),
|
||||||
authn.NewKeychainFromHelper(credhelper.NewACRCredentialsHelper()),
|
authn.NewKeychainFromHelper(credhelper.NewACRCredentialsHelper()),
|
||||||
authn.NewKeychainFromHelper(gitlab.NewGitLabCredentialsHelper()),
|
authn.NewKeychainFromHelper(gitlab.NewGitLabCredentialsHelper()),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ package dockerfile
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -44,9 +45,9 @@ func ParseStages(opts *config.KanikoOptions) ([]instructions.Stage, []instructio
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, nil, e
|
return nil, nil, e
|
||||||
}
|
}
|
||||||
d, err = ioutil.ReadAll(response.Body)
|
d, err = io.ReadAll(response.Body)
|
||||||
} else {
|
} else {
|
||||||
d, err = ioutil.ReadFile(opts.DockerfilePath)
|
d, err = os.ReadFile(opts.DockerfilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package dockerfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -45,7 +44,7 @@ func Test_ParseStages_ArgValueWithQuotes(t *testing.T) {
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=second /hi2 /hi3
|
COPY --from=second /hi2 /hi3
|
||||||
`
|
`
|
||||||
tmpfile, err := ioutil.TempFile("", "Dockerfile.test")
|
tmpfile, err := os.CreateTemp("", "Dockerfile.test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -622,7 +621,7 @@ func Test_stageBuilder_optimize(t *testing.T) {
|
||||||
sb := &stageBuilder{opts: tc.opts, cf: cf, snapshotter: snap, layerCache: lc,
|
sb := &stageBuilder{opts: tc.opts, cf: cf, snapshotter: snap, layerCache: lc,
|
||||||
args: dockerfile.NewBuildArgs([]string{})}
|
args: dockerfile.NewBuildArgs([]string{})}
|
||||||
ck := CompositeCache{}
|
ck := CompositeCache{}
|
||||||
file, err := ioutil.TempFile("", "foo")
|
file, err := os.CreateTemp("", "foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
@ -1245,7 +1244,7 @@ FROM ubuntu:16.04
|
||||||
COPY %s bar.txt
|
COPY %s bar.txt
|
||||||
RUN foobar
|
RUN foobar
|
||||||
`, filename)
|
`, filename)
|
||||||
f, _ := ioutil.TempFile("", "")
|
f, _ := os.CreateTemp("", "")
|
||||||
os.WriteFile(f.Name(), []byte(dockerFile), 0755)
|
os.WriteFile(f.Name(), []byte(dockerFile), 0755)
|
||||||
opts := &config.KanikoOptions{
|
opts := &config.KanikoOptions{
|
||||||
DockerfilePath: f.Name(),
|
DockerfilePath: f.Name(),
|
||||||
|
|
@ -1531,7 +1530,7 @@ func tempDirAndFile(t *testing.T) (string, []string) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
filepath := filepath.Join(dir, filename)
|
filepath := filepath.Join(dir, filename)
|
||||||
err := ioutil.WriteFile(filepath, []byte(`meow`), 0777)
|
err := os.WriteFile(filepath, []byte(`meow`), 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("could not create temp file %v", err)
|
t.Errorf("could not create temp file %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -1560,7 +1559,7 @@ func generateTar(t *testing.T, dir string, fileNames ...string) []byte {
|
||||||
t.Errorf("could not write tar header %v", err)
|
t.Errorf("could not write tar header %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(filePath)
|
content, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("could not read tempfile %v", err)
|
t.Errorf("could not read tempfile %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||||
package executor
|
package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -71,7 +70,7 @@ func Test_CompositeCache_AddPath_dir(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
content := `meow meow meow`
|
content := `meow meow meow`
|
||||||
if err := ioutil.WriteFile(filepath.Join(tmpDir, "foo.txt"), []byte(content), 0777); err != nil {
|
if err := os.WriteFile(filepath.Join(tmpDir, "foo.txt"), []byte(content), 0777); err != nil {
|
||||||
t.Errorf("got error writing temp file %v", err)
|
t.Errorf("got error writing temp file %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +97,7 @@ func Test_CompositeCache_AddPath_dir(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func Test_CompositeCache_AddPath_file(t *testing.T) {
|
func Test_CompositeCache_AddPath_file(t *testing.T) {
|
||||||
tmpfile, err := ioutil.TempFile("/tmp", "foo.txt")
|
tmpfile, err := os.CreateTemp("/tmp", "foo.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("got error setting up test %v", err)
|
t.Errorf("got error setting up test %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +145,7 @@ func createFilesystemStructure(root string, directories, files []string) error {
|
||||||
|
|
||||||
for _, fileName := range files {
|
for _, fileName := range files {
|
||||||
filePath := path.Join(root, fileName)
|
filePath := path.Join(root, fileName)
|
||||||
err := ioutil.WriteFile(filePath, []byte(fileName), 0644)
|
err := os.WriteFile(filePath, []byte(fileName), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +157,7 @@ func createFilesystemStructure(root string, directories, files []string) error {
|
||||||
func setIgnoreContext(t *testing.T, content string) (util.FileContext, error) {
|
func setIgnoreContext(t *testing.T, content string) (util.FileContext, error) {
|
||||||
var fileContext util.FileContext
|
var fileContext util.FileContext
|
||||||
dockerIgnoreDir := t.TempDir()
|
dockerIgnoreDir := t.TempDir()
|
||||||
err := ioutil.WriteFile(dockerIgnoreDir+".dockerignore", []byte(content), 0644)
|
err := os.WriteFile(dockerIgnoreDir+".dockerignore", []byte(content), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fileContext, err
|
return fileContext, err
|
||||||
}
|
}
|
||||||
|
|
@ -288,7 +287,7 @@ func Test_CompositeKey_AddPath_WithExtraFile_Works(t *testing.T) {
|
||||||
t.Fatalf("Error creating filesytem structure: %s", err)
|
t.Fatalf("Error creating filesytem structure: %s", err)
|
||||||
}
|
}
|
||||||
extraPath := path.Join(testDir2, test.extraFile)
|
extraPath := path.Join(testDir2, test.extraFile)
|
||||||
err = ioutil.WriteFile(extraPath, []byte(test.extraFile), 0644)
|
err = os.WriteFile(extraPath, []byte(test.extraFile), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error creating filesytem structure: %s", err)
|
t.Fatalf("Error creating filesytem structure: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -431,7 +430,7 @@ func Test_CompositeKey_AddPath_WithExtraFilIgnored_Works(t *testing.T) {
|
||||||
t.Fatalf("Error creating filesytem structure: %s", err)
|
t.Fatalf("Error creating filesytem structure: %s", err)
|
||||||
}
|
}
|
||||||
extraPath := path.Join(testDir2, test.extraFile)
|
extraPath := path.Join(testDir2, test.extraFile)
|
||||||
err = ioutil.WriteFile(extraPath, []byte(test.extraFile), 0644)
|
err = os.WriteFile(extraPath, []byte(test.extraFile), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error creating filesytem structure: %s", err)
|
t.Fatalf("Error creating filesytem structure: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -28,6 +28,24 @@ import (
|
||||||
"github.com/GoogleContainerTools/kaniko/testutil"
|
"github.com/GoogleContainerTools/kaniko/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func readDirectory(dirName string) ([]fs.FileInfo, error) {
|
||||||
|
entries, err := os.ReadDir(dirName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
testDir := make([]fs.FileInfo, 0, len(entries))
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
info, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
testDir = append(testDir, info)
|
||||||
|
}
|
||||||
|
return testDir, err
|
||||||
|
}
|
||||||
|
|
||||||
func TestCopyCommand_Multistage(t *testing.T) {
|
func TestCopyCommand_Multistage(t *testing.T) {
|
||||||
t.Run("copy a file across multistage", func(t *testing.T) {
|
t.Run("copy a file across multistage", func(t *testing.T) {
|
||||||
testDir, fn := setupMultistageTests(t)
|
testDir, fn := setupMultistageTests(t)
|
||||||
|
|
@ -39,7 +57,7 @@ ENV test test
|
||||||
|
|
||||||
From scratch as second
|
From scratch as second
|
||||||
COPY --from=first copied/bam.txt output/bam.txt`
|
COPY --from=first copied/bam.txt output/bam.txt`
|
||||||
ioutil.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755)
|
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755)
|
||||||
opts := &config.KanikoOptions{
|
opts := &config.KanikoOptions{
|
||||||
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"),
|
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"),
|
||||||
SrcContext: filepath.Join(testDir, "workspace"),
|
SrcContext: filepath.Join(testDir, "workspace"),
|
||||||
|
|
@ -48,7 +66,7 @@ COPY --from=first copied/bam.txt output/bam.txt`
|
||||||
_, err := DoBuild(opts)
|
_, err := DoBuild(opts)
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check Image has one layer bam.txt
|
// Check Image has one layer bam.txt
|
||||||
files, err := ioutil.ReadDir(filepath.Join(testDir, "output"))
|
files, err := readDirectory(filepath.Join(testDir, "output"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +85,7 @@ ENV test test
|
||||||
|
|
||||||
From scratch as second
|
From scratch as second
|
||||||
COPY --from=first copied/bam.txt output/`
|
COPY --from=first copied/bam.txt output/`
|
||||||
ioutil.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755)
|
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755)
|
||||||
opts := &config.KanikoOptions{
|
opts := &config.KanikoOptions{
|
||||||
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"),
|
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"),
|
||||||
SrcContext: filepath.Join(testDir, "workspace"),
|
SrcContext: filepath.Join(testDir, "workspace"),
|
||||||
|
|
@ -75,7 +93,7 @@ COPY --from=first copied/bam.txt output/`
|
||||||
}
|
}
|
||||||
_, err := DoBuild(opts)
|
_, err := DoBuild(opts)
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
files, err := ioutil.ReadDir(filepath.Join(testDir, "output"))
|
files, err := readDirectory(filepath.Join(testDir, "output"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +110,7 @@ ENV test test
|
||||||
|
|
||||||
From scratch as second
|
From scratch as second
|
||||||
COPY --from=first copied another`
|
COPY --from=first copied another`
|
||||||
ioutil.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755)
|
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755)
|
||||||
opts := &config.KanikoOptions{
|
opts := &config.KanikoOptions{
|
||||||
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"),
|
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"),
|
||||||
SrcContext: filepath.Join(testDir, "workspace"),
|
SrcContext: filepath.Join(testDir, "workspace"),
|
||||||
|
|
@ -101,7 +119,7 @@ COPY --from=first copied another`
|
||||||
_, err := DoBuild(opts)
|
_, err := DoBuild(opts)
|
||||||
testutil.CheckNoError(t, err)
|
testutil.CheckNoError(t, err)
|
||||||
// Check Image has one layer bam.txt
|
// Check Image has one layer bam.txt
|
||||||
files, err := ioutil.ReadDir(filepath.Join(testDir, "another"))
|
files, err := readDirectory(filepath.Join(testDir, "another"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -145,14 +163,14 @@ func setupMultistageTests(t *testing.T) (string, func()) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
file := filepath.Join(workspace, "foo", "bam.txt")
|
file := filepath.Join(workspace, "foo", "bam.txt")
|
||||||
if err := ioutil.WriteFile(file, []byte("meow"), 0755); err != nil {
|
if err := os.WriteFile(file, []byte("meow"), 0755); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
os.Symlink("bam.txt", filepath.Join(workspace, "foo", "bam.link"))
|
os.Symlink("bam.txt", filepath.Join(workspace, "foo", "bam.link"))
|
||||||
|
|
||||||
// Make a file with contents link
|
// Make a file with contents link
|
||||||
file = filepath.Join(workspace, "exec")
|
file = filepath.Join(workspace, "exec")
|
||||||
if err := ioutil.WriteFile(file, []byte("woof"), 0755); err != nil {
|
if err := os.WriteFile(file, []byte("woof"), 0755); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// Make bin
|
// Make bin
|
||||||
|
|
@ -173,7 +191,7 @@ func setupMultistageTests(t *testing.T) (string, func()) {
|
||||||
`36 35 98:0 /kaniko %s/kaniko rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
`36 35 98:0 /kaniko %s/kaniko rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
||||||
36 35 98:0 /proc %s/proc rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
36 35 98:0 /proc %s/proc rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
||||||
`, testDir, testDir)
|
`, testDir, testDir)
|
||||||
if err := ioutil.WriteFile(mFile, []byte(mountInfo), 0644); err != nil {
|
if err := os.WriteFile(mFile, []byte(mountInfo), 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
config.MountInfoPath = mFile
|
config.MountInfoPath = mFile
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/commands"
|
"github.com/GoogleContainerTools/kaniko/pkg/commands"
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
|
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
|
||||||
|
|
@ -158,7 +157,7 @@ func (f fakeLayer) Compressed() (io.ReadCloser, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
func (f fakeLayer) Uncompressed() (io.ReadCloser, error) {
|
func (f fakeLayer) Uncompressed() (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(bytes.NewReader(f.TarContent)), nil
|
return io.NopCloser(bytes.NewReader(f.TarContent)), nil
|
||||||
}
|
}
|
||||||
func (f fakeLayer) Size() (int64, error) {
|
func (f fakeLayer) Size() (int64, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -74,7 +73,7 @@ func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||||
|
|
||||||
// for testing
|
// for testing
|
||||||
var (
|
var (
|
||||||
fs = afero.NewOsFs()
|
newOsFs = afero.NewOsFs()
|
||||||
checkRemotePushPermission = remote.CheckPushPermission
|
checkRemotePushPermission = remote.CheckPushPermission
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -156,7 +155,7 @@ func writeDigestFile(path string, digestByteArray []byte) error {
|
||||||
}
|
}
|
||||||
logrus.Tracef("Created directory %v", parentDir)
|
logrus.Tracef("Created directory %v", parentDir)
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(path, digestByteArray, 0644)
|
return os.WriteFile(path, digestByteArray, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DoPush is responsible for pushing image to the destinations specified in opts.
|
// DoPush is responsible for pushing image to the destinations specified in opts.
|
||||||
|
|
@ -301,7 +300,7 @@ func writeImageOutputs(image v1.Image, destRefs []name.Tag) error {
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
f, err := fs.Create(filepath.Join(dir, "images"))
|
f, err := newOsFs.Create(filepath.Join(dir, "images"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -81,9 +80,9 @@ func TestWriteImageOutputs(t *testing.T) {
|
||||||
`, d, d),
|
`, d, d),
|
||||||
}} {
|
}} {
|
||||||
t.Run(c.desc, func(t *testing.T) {
|
t.Run(c.desc, func(t *testing.T) {
|
||||||
fs = afero.NewMemMapFs()
|
newOsFs = afero.NewMemMapFs()
|
||||||
if c.want == "" {
|
if c.want == "" {
|
||||||
fs = afero.NewReadOnlyFs(fs) // No files should be written.
|
newOsFs = afero.NewReadOnlyFs(newOsFs) // No files should be written.
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("BUILDER_OUTPUT", c.env)
|
os.Setenv("BUILDER_OUTPUT", c.env)
|
||||||
|
|
@ -95,7 +94,7 @@ func TestWriteImageOutputs(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := afero.ReadFile(fs, filepath.Join(c.env, "images"))
|
b, err := afero.ReadFile(newOsFs, filepath.Join(c.env, "images"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ReadFile: %v", err)
|
t.Fatalf("ReadFile: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +135,7 @@ func TestHeaderAdded(t *testing.T) {
|
||||||
resp, err := rt.RoundTrip(req)
|
resp, err := rt.RoundTrip(req)
|
||||||
testutil.CheckError(t, false, err)
|
testutil.CheckError(t, false, err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
testutil.CheckErrorAndDeepEqual(t, false, err, test.expected, string(body))
|
testutil.CheckErrorAndDeepEqual(t, false, err, test.expected, string(body))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +147,7 @@ type mockRoundTripper struct {
|
||||||
|
|
||||||
func (m *mockRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
func (m *mockRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||||
ua := r.UserAgent()
|
ua := r.UserAgent()
|
||||||
return &http.Response{Body: ioutil.NopCloser(bytes.NewBufferString(ua))}, nil
|
return &http.Response{Body: io.NopCloser(bytes.NewBufferString(ua))}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOCILayoutPath(t *testing.T) {
|
func TestOCILayoutPath(t *testing.T) {
|
||||||
|
|
@ -218,7 +217,7 @@ func TestImageNameDigestFile(t *testing.T) {
|
||||||
|
|
||||||
want := []byte("gcr.io/foo/bar@" + digest.String() + "\nindex.docker.io/bob/image@" + digest.String() + "\n")
|
want := []byte("gcr.io/foo/bar@" + digest.String() + "\nindex.docker.io/bob/image@" + digest.String() + "\n")
|
||||||
|
|
||||||
got, err := ioutil.ReadFile("tmpFile")
|
got, err := os.ReadFile("tmpFile")
|
||||||
|
|
||||||
testutil.CheckErrorAndDeepEqual(t, false, err, want, got)
|
testutil.CheckErrorAndDeepEqual(t, false, err, want, got)
|
||||||
|
|
||||||
|
|
@ -311,7 +310,7 @@ func TestImageNameTagDigestFile(t *testing.T) {
|
||||||
|
|
||||||
want := []byte("gcr.io/foo/bar:123@" + digest.String() + "\nindex.docker.io/bob/image:latest@" + digest.String() + "\n")
|
want := []byte("gcr.io/foo/bar:123@" + digest.String() + "\nindex.docker.io/bob/image:latest@" + digest.String() + "\n")
|
||||||
|
|
||||||
got, err := ioutil.ReadFile("tmpFile")
|
got, err := os.ReadFile("tmpFile")
|
||||||
|
|
||||||
testutil.CheckErrorAndDeepEqual(t, false, err, want, got)
|
testutil.CheckErrorAndDeepEqual(t, false, err, want, got)
|
||||||
}
|
}
|
||||||
|
|
@ -395,7 +394,7 @@ func TestCheckPushPermissions(t *testing.T) {
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.description, func(t *testing.T) {
|
t.Run(test.description, func(t *testing.T) {
|
||||||
resetCalledCount()
|
resetCalledCount()
|
||||||
fs = afero.NewMemMapFs()
|
newOsFs = afero.NewMemMapFs()
|
||||||
opts := config.KanikoOptions{
|
opts := config.KanikoOptions{
|
||||||
CacheRepo: test.cacheRepo,
|
CacheRepo: test.cacheRepo,
|
||||||
Destinations: test.destinations,
|
Destinations: test.destinations,
|
||||||
|
|
@ -403,8 +402,8 @@ func TestCheckPushPermissions(t *testing.T) {
|
||||||
NoPushCache: test.noPushCache,
|
NoPushCache: test.noPushCache,
|
||||||
}
|
}
|
||||||
if test.existingConfig {
|
if test.existingConfig {
|
||||||
afero.WriteFile(fs, util.DockerConfLocation(), []byte(""), os.FileMode(0644))
|
afero.WriteFile(newOsFs, util.DockerConfLocation(), []byte(""), os.FileMode(0644))
|
||||||
defer fs.Remove(util.DockerConfLocation())
|
defer newOsFs.Remove(util.DockerConfLocation())
|
||||||
}
|
}
|
||||||
CheckPushPermissions(&opts)
|
CheckPushPermissions(&opts)
|
||||||
if checkPushPermsCallCount != test.checkPushPermsExpectedCallCount {
|
if checkPushPermsCallCount != test.checkPushPermsExpectedCallCount {
|
||||||
|
|
@ -433,7 +432,7 @@ func TestSkipPushPermission(t *testing.T) {
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.description, func(t *testing.T) {
|
t.Run(test.description, func(t *testing.T) {
|
||||||
resetCalledCount()
|
resetCalledCount()
|
||||||
fs = afero.NewMemMapFs()
|
newOsFs = afero.NewMemMapFs()
|
||||||
opts := config.KanikoOptions{
|
opts := config.KanikoOptions{
|
||||||
CacheRepo: test.cacheRepo,
|
CacheRepo: test.cacheRepo,
|
||||||
Destinations: test.destinations,
|
Destinations: test.destinations,
|
||||||
|
|
@ -442,8 +441,8 @@ func TestSkipPushPermission(t *testing.T) {
|
||||||
SkipPushPermissionCheck: test.skipPushPermission,
|
SkipPushPermissionCheck: test.skipPushPermission,
|
||||||
}
|
}
|
||||||
if test.existingConfig {
|
if test.existingConfig {
|
||||||
afero.WriteFile(fs, util.DockerConfLocation(), []byte(""), os.FileMode(0644))
|
afero.WriteFile(newOsFs, util.DockerConfLocation(), []byte(""), os.FileMode(0644))
|
||||||
defer fs.Remove(util.DockerConfLocation())
|
defer newOsFs.Remove(util.DockerConfLocation())
|
||||||
}
|
}
|
||||||
CheckPushPermissions(&opts)
|
CheckPushPermissions(&opts)
|
||||||
if checkPushPermsCallCount != test.checkPushPermsExpectedCallCount {
|
if checkPushPermsCallCount != test.checkPushPermsExpectedCallCount {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -67,7 +66,7 @@ func Test_ResolvePaths(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(fTarget, []byte{}, 0777); err != nil {
|
if err := os.WriteFile(fTarget, []byte{}, 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +142,7 @@ func Test_ResolvePaths(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(filepath.Join(target, "meow.txt"), []byte{}, 0777); err != nil {
|
if err := os.WriteFile(filepath.Join(target, "meow.txt"), []byte{}, 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,7 +191,7 @@ func Test_resolveSymlinkAncestor(t *testing.T) {
|
||||||
|
|
||||||
targetPath := filepath.Join(targetDir, "bam.txt")
|
targetPath := filepath.Join(targetDir, "bam.txt")
|
||||||
|
|
||||||
if err := ioutil.WriteFile(targetPath, []byte("meow"), 0777); err != nil {
|
if err := os.WriteFile(targetPath, []byte("meow"), 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package snapshot
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -65,7 +64,7 @@ func (s *Snapshotter) Key() (string, error) {
|
||||||
// TakeSnapshot takes a snapshot of the specified files, avoiding directories in the ignorelist, and creates
|
// TakeSnapshot takes a snapshot of the specified files, avoiding directories in the ignorelist, and creates
|
||||||
// a tarball of the changed files. Return contents of the tarball, and whether or not any files were changed
|
// a tarball of the changed files. Return contents of the tarball, and whether or not any files were changed
|
||||||
func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool, forceBuildMetadata bool) (string, error) {
|
func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool, forceBuildMetadata bool) (string, error) {
|
||||||
f, err := ioutil.TempFile(config.KanikoDir, "")
|
f, err := os.CreateTemp(config.KanikoDir, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +123,7 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool, forceBui
|
||||||
// TakeSnapshotFS takes a snapshot of the filesystem, avoiding directories in the ignorelist, and creates
|
// TakeSnapshotFS takes a snapshot of the filesystem, avoiding directories in the ignorelist, and creates
|
||||||
// a tarball of the changed files.
|
// a tarball of the changed files.
|
||||||
func (s *Snapshotter) TakeSnapshotFS() (string, error) {
|
func (s *Snapshotter) TakeSnapshotFS() (string, error) {
|
||||||
f, err := ioutil.TempFile(s.getSnashotPathPrefix(), "")
|
f, err := os.CreateTemp(s.getSnashotPathPrefix(), "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package snapshot
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -88,7 +87,7 @@ func TestSnapshotFSFileChange(t *testing.T) {
|
||||||
if hdr.Typeflag == tar.TypeDir {
|
if hdr.Typeflag == tar.TypeDir {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
contents, _ := ioutil.ReadAll(tr)
|
contents, _ := io.ReadAll(tr)
|
||||||
if string(contents) != snapshotFiles[hdr.Name] {
|
if string(contents) != snapshotFiles[hdr.Name] {
|
||||||
t.Fatalf("Contents of %s incorrect, expected: %s, actual: %s", hdr.Name, snapshotFiles[hdr.Name], string(contents))
|
t.Fatalf("Contents of %s incorrect, expected: %s, actual: %s", hdr.Name, snapshotFiles[hdr.Name], string(contents))
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +175,7 @@ func TestSnapshotFSChangePermissions(t *testing.T) {
|
||||||
if hdr.Typeflag == tar.TypeDir {
|
if hdr.Typeflag == tar.TypeDir {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
contents, _ := ioutil.ReadAll(tr)
|
contents, _ := io.ReadAll(tr)
|
||||||
if string(contents) != snapshotFiles[hdr.Name] {
|
if string(contents) != snapshotFiles[hdr.Name] {
|
||||||
t.Fatalf("Contents of %s incorrect, expected: %s, actual: %s", hdr.Name, snapshotFiles[hdr.Name], string(contents))
|
t.Fatalf("Contents of %s incorrect, expected: %s, actual: %s", hdr.Name, snapshotFiles[hdr.Name], string(contents))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -763,7 +762,7 @@ func getExcludedFiles(dockerfilePath, buildcontext string) ([]string, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
logrus.Infof("Using dockerignore file: %v", path)
|
logrus.Infof("Using dockerignore file: %v", path)
|
||||||
contents, err := ioutil.ReadFile(path)
|
contents, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "parsing .dockerignore")
|
return nil, errors.Wrap(err, "parsing .dockerignore")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -52,7 +51,7 @@ func Test_DetectFilesystemSkiplist(t *testing.T) {
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
|
||||||
t.Fatalf("Error creating tempdir: %s", err)
|
t.Fatalf("Error creating tempdir: %s", err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(path, []byte(fileContents), 0644); err != nil {
|
if err := os.WriteFile(path, []byte(fileContents), 0644); err != nil {
|
||||||
t.Fatalf("Error writing file contents to %s: %s", path, err)
|
t.Fatalf("Error writing file contents to %s: %s", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -492,7 +491,7 @@ func fileExists(p string) checker {
|
||||||
|
|
||||||
func fileMatches(p string, c []byte) checker {
|
func fileMatches(p string, c []byte) checker {
|
||||||
return func(root string, t *testing.T) {
|
return func(root string, t *testing.T) {
|
||||||
actual, err := ioutil.ReadFile(filepath.Join(root, p))
|
actual, err := os.ReadFile(filepath.Join(root, p))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error reading file: %s", p)
|
t.Fatalf("error reading file: %s", p)
|
||||||
}
|
}
|
||||||
|
|
@ -840,7 +839,7 @@ func TestCopySymlink(t *testing.T) {
|
||||||
linkTarget: "/abs/dest",
|
linkTarget: "/abs/dest",
|
||||||
dest: "overwrite_me",
|
dest: "overwrite_me",
|
||||||
beforeLink: func(r string) error {
|
beforeLink: func(r string) error {
|
||||||
return ioutil.WriteFile(filepath.Join(r, "overwrite_me"), nil, 0644)
|
return os.WriteFile(filepath.Join(r, "overwrite_me"), nil, 0644)
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
@ -851,7 +850,7 @@ func TestCopySymlink(t *testing.T) {
|
||||||
r := t.TempDir()
|
r := t.TempDir()
|
||||||
os.MkdirAll(filepath.Join(r, filepath.Dir(tc.linkTarget)), 0777)
|
os.MkdirAll(filepath.Join(r, filepath.Dir(tc.linkTarget)), 0777)
|
||||||
tc.linkTarget = filepath.Join(r, tc.linkTarget)
|
tc.linkTarget = filepath.Join(r, tc.linkTarget)
|
||||||
ioutil.WriteFile(tc.linkTarget, nil, 0644)
|
os.WriteFile(tc.linkTarget, nil, 0644)
|
||||||
|
|
||||||
if tc.beforeLink != nil {
|
if tc.beforeLink != nil {
|
||||||
if err := tc.beforeLink(r); err != nil {
|
if err := tc.beforeLink(r); err != nil {
|
||||||
|
|
@ -980,7 +979,7 @@ func Test_CopyFile_skips_self(t *testing.T) {
|
||||||
tempFile := filepath.Join(tempDir, "foo")
|
tempFile := filepath.Join(tempDir, "foo")
|
||||||
expected := "bar"
|
expected := "bar"
|
||||||
|
|
||||||
if err := ioutil.WriteFile(
|
if err := os.WriteFile(
|
||||||
tempFile,
|
tempFile,
|
||||||
[]byte(expected),
|
[]byte(expected),
|
||||||
0755,
|
0755,
|
||||||
|
|
@ -998,7 +997,7 @@ func Test_CopyFile_skips_self(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure file has expected contents
|
// Ensure file has expected contents
|
||||||
actualData, err := ioutil.ReadFile(tempFile)
|
actualData, err := os.ReadFile(tempFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -1130,7 +1129,7 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_disabled(t *testing.T)
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
// Write a whiteout path
|
// Write a whiteout path
|
||||||
d1 := []byte("Hello World\n")
|
d1 := []byte("Hello World\n")
|
||||||
if err := ioutil.WriteFile(filepath.Join(root, "foobar"), d1, 0644); err != nil {
|
if err := os.WriteFile(filepath.Join(root, "foobar"), d1, 0644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1185,7 +1184,7 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_disabled(t *testing.T)
|
||||||
|
|
||||||
f(layerFiles, tw)
|
f(layerFiles, tw)
|
||||||
|
|
||||||
rc := ioutil.NopCloser(buf)
|
rc := io.NopCloser(buf)
|
||||||
mockLayer.EXPECT().Uncompressed().Return(rc, nil)
|
mockLayer.EXPECT().Uncompressed().Return(rc, nil)
|
||||||
|
|
||||||
secondLayerFiles := []string{
|
secondLayerFiles := []string{
|
||||||
|
|
@ -1200,7 +1199,7 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_disabled(t *testing.T)
|
||||||
mockLayer2 := mockv1.NewMockLayer(ctrl)
|
mockLayer2 := mockv1.NewMockLayer(ctrl)
|
||||||
mockLayer2.EXPECT().MediaType().Return(types.OCILayer, nil)
|
mockLayer2.EXPECT().MediaType().Return(types.OCILayer, nil)
|
||||||
|
|
||||||
rc = ioutil.NopCloser(buf)
|
rc = io.NopCloser(buf)
|
||||||
mockLayer2.EXPECT().Uncompressed().Return(rc, nil)
|
mockLayer2.EXPECT().Uncompressed().Return(rc, nil)
|
||||||
|
|
||||||
layers := []v1.Layer{
|
layers := []v1.Layer{
|
||||||
|
|
@ -1292,7 +1291,7 @@ func Test_GetFSFromLayers_ignorelist(t *testing.T) {
|
||||||
|
|
||||||
f(layerFiles, tw)
|
f(layerFiles, tw)
|
||||||
|
|
||||||
rc := ioutil.NopCloser(buf)
|
rc := io.NopCloser(buf)
|
||||||
mockLayer.EXPECT().Uncompressed().Return(rc, nil)
|
mockLayer.EXPECT().Uncompressed().Return(rc, nil)
|
||||||
|
|
||||||
layers := []v1.Layer{
|
layers := []v1.Layer{
|
||||||
|
|
@ -1346,7 +1345,7 @@ func Test_GetFSFromLayers_ignorelist(t *testing.T) {
|
||||||
|
|
||||||
f(layerFiles, tw)
|
f(layerFiles, tw)
|
||||||
|
|
||||||
rc = ioutil.NopCloser(buf)
|
rc = io.NopCloser(buf)
|
||||||
mockLayer.EXPECT().Uncompressed().Return(rc, nil)
|
mockLayer.EXPECT().Uncompressed().Return(rc, nil)
|
||||||
|
|
||||||
layers = []v1.Layer{
|
layers = []v1.Layer{
|
||||||
|
|
@ -1413,7 +1412,7 @@ func Test_GetFSFromLayers(t *testing.T) {
|
||||||
mockLayer := mockv1.NewMockLayer(ctrl)
|
mockLayer := mockv1.NewMockLayer(ctrl)
|
||||||
mockLayer.EXPECT().MediaType().Return(types.OCILayer, nil)
|
mockLayer.EXPECT().MediaType().Return(types.OCILayer, nil)
|
||||||
|
|
||||||
rc := ioutil.NopCloser(buf)
|
rc := io.NopCloser(buf)
|
||||||
mockLayer.EXPECT().Uncompressed().Return(rc, nil)
|
mockLayer.EXPECT().Uncompressed().Return(rc, nil)
|
||||||
|
|
||||||
layers := []v1.Layer{
|
layers := []v1.Layer{
|
||||||
|
|
@ -1463,7 +1462,7 @@ func TestInitIgnoreList(t *testing.T) {
|
||||||
mountInfo := `36 35 98:0 /kaniko /test/kaniko rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
mountInfo := `36 35 98:0 /kaniko /test/kaniko rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
||||||
36 35 98:0 /proc /test/proc rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
36 35 98:0 /proc /test/proc rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
||||||
`
|
`
|
||||||
mFile, err := ioutil.TempFile("", "mountinfo")
|
mFile, err := os.CreateTemp("", "mountinfo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -1520,7 +1519,7 @@ func Test_setFileTimes(t *testing.T) {
|
||||||
|
|
||||||
p := filepath.Join(testDir, "foo.txt")
|
p := filepath.Join(testDir, "foo.txt")
|
||||||
|
|
||||||
if err := ioutil.WriteFile(p, []byte("meow"), 0777); err != nil {
|
if err := os.WriteFile(p, []byte("meow"), 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -101,7 +100,7 @@ func TestDockerConfLocationWithFileLocation(t *testing.T) {
|
||||||
if err := os.Unsetenv(DockerConfigEnvKey); err != nil {
|
if err := os.Unsetenv(DockerConfigEnvKey); err != nil {
|
||||||
t.Fatalf("Failed to unset DOCKER_CONFIG: %v", err)
|
t.Fatalf("Failed to unset DOCKER_CONFIG: %v", err)
|
||||||
}
|
}
|
||||||
file, err := ioutil.TempFile("", "docker.conf")
|
file, err := os.CreateTemp("", "docker.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not create temp file: %s", err)
|
t.Fatalf("could not create temp file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ package proc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -201,7 +200,7 @@ func readFile(file string) []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b, _ := ioutil.ReadFile(file)
|
b, _ := os.ReadFile(file)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -266,7 +265,7 @@ func fileIsCompressedTar(src string) (bool, archive.Compression) {
|
||||||
return false, -1
|
return false, -1
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
buf, err := ioutil.ReadAll(r)
|
buf, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, -1
|
return false, -1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -61,7 +60,7 @@ func Test_AddFileToTar(t *testing.T) {
|
||||||
testDir := t.TempDir()
|
testDir := t.TempDir()
|
||||||
|
|
||||||
path := filepath.Join(testDir, regularFiles[0])
|
path := filepath.Join(testDir, regularFiles[0])
|
||||||
if err := ioutil.WriteFile(path, []byte("hello"), os.ModePerm); err != nil {
|
if err := os.WriteFile(path, []byte("hello"), os.ModePerm); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// use a pre-determined time with non-zero microseconds to avoid flakiness
|
// use a pre-determined time with non-zero microseconds to avoid flakiness
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/config"
|
"github.com/GoogleContainerTools/kaniko/pkg/config"
|
||||||
|
|
@ -43,7 +43,7 @@ func (p *X509CertPool) value() *x509.CertPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *X509CertPool) append(path string) error {
|
func (p *X509CertPool) append(path string) error {
|
||||||
pem, err := ioutil.ReadFile(path)
|
pem, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -176,7 +175,7 @@ func SHA256(r io.Reader) (string, error) {
|
||||||
|
|
||||||
// GetInputFrom returns Reader content
|
// GetInputFrom returns Reader content
|
||||||
func GetInputFrom(r io.Reader) ([]byte, error) {
|
func GetInputFrom(r io.Reader) ([]byte, error) {
|
||||||
output, err := ioutil.ReadAll(r)
|
output, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package testutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -35,7 +34,7 @@ func SetupFiles(path string, files map[string]string) error {
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(path, []byte(c), 0644); err != nil {
|
if err := os.WriteFile(path, []byte(c), 0644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue