Skip to content

Commit

Permalink
all the things i figured out how to fix so far
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Kimmel <jkimmel@vmware.com>
  • Loading branch information
joe-kimmel-vmw committed Mar 22, 2023
1 parent 6f0f6a7 commit aab0f1e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pkg/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (a *AddCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bui

copyCmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: append(unresolvedSrcs, dest)},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: unresolvedSrcs, DestPath: dest},
Chown: a.cmd.Chown,
},
fileContext: a.fileContext,
Expand Down
50 changes: 24 additions & 26 deletions pkg/commands/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ func Test_CachingCopyCommand_ExecuteCommand(t *testing.T) {
},
fileContext: util.FileContext{Root: tempDir},
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{
"foo.txt", "foo.txt",
},
},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{"foo.txt"}, DestPath: "foo.txt"}},
}
count := 0
tc := testCase{
Expand Down Expand Up @@ -274,7 +271,8 @@ func TestCopyExecuteCmd(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: test.sourcesAndDest,
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: test.sourcesAndDest[0 : len(test.sourcesAndDest)-1],
DestPath: test.sourcesAndDest[len(test.sourcesAndDest)-1]},
},
fileContext: fileContext,
}
Expand Down Expand Up @@ -421,7 +419,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{srcDir, "dest"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{srcDir}, DestPath: "dest"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand Down Expand Up @@ -453,7 +451,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
defer os.RemoveAll(testDir)
cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{filepath.Join(srcDir, "bam.txt"), "dest/"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{filepath.Join(srcDir, "bam.txt")}, DestPath: "dest/"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand All @@ -480,7 +478,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
defer os.RemoveAll(testDir)
cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{filepath.Join(srcDir, "bam.txt"), "dest"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{filepath.Join(srcDir, "bam.txt")}, DestPath: "dest"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand Down Expand Up @@ -509,7 +507,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{filepath.Join(srcDir, "bam.txt"), "dest"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{filepath.Join(srcDir, "bam.txt")}, DestPath: "dest"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand Down Expand Up @@ -538,7 +536,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{filepath.Join(srcDir, "sym.link"), "dest/"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{filepath.Join(srcDir, "sym.link")}, DestPath: "dest/"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand Down Expand Up @@ -583,7 +581,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{filepath.Join(srcDir, "dead.link"), "dest/"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{filepath.Join(srcDir, "dead.link")}, DestPath: "dest/"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand Down Expand Up @@ -614,7 +612,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
t.Run("copy src symlink dir to a dir", func(t *testing.T) {
testDir, srcDir := setupDirs(t)
defer os.RemoveAll(testDir)
expected, err := ioutil.ReadDir(filepath.Join(testDir, srcDir))
expected, err := os.ReadDir(filepath.Join(testDir, srcDir))
if err != nil {
t.Fatal(err)
}
Expand All @@ -624,7 +622,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{"another", "dest"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{"another"}, DestPath: "dest"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand All @@ -638,13 +636,13 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
err = cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
testutil.CheckNoError(t, err)
// Check if "dest" dir exists with contents of srcDir
actual, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
actual, err := os.ReadDir(filepath.Join(testDir, "dest"))
if err != nil {
t.Fatal(err)
}
for i, f := range actual {
testutil.CheckDeepEqual(t, expected[i].Name(), f.Name())
testutil.CheckDeepEqual(t, expected[i].Mode(), f.Mode())
testutil.CheckDeepEqual(t, expected[i].Type(), f.Type())
}
})

Expand All @@ -670,7 +668,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{srcDir, "dest"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{srcDir}, DestPath: "dest"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand Down Expand Up @@ -704,7 +702,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
t.Run("copy src symlink dir to a dir", func(t *testing.T) {
testDir, srcDir := setupDirs(t)
defer os.RemoveAll(testDir)
expected, err := ioutil.ReadDir(filepath.Join(testDir, srcDir))
expected, err := os.ReadDir(filepath.Join(testDir, srcDir))
if err != nil {
t.Fatal(err)
}
Expand All @@ -714,7 +712,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{"another", "dest"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{"another"}, DestPath: "dest"},
},
fileContext: util.FileContext{Root: testDir},
}
Expand All @@ -728,13 +726,13 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
err = cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
testutil.CheckNoError(t, err)
// Check if "dest" dir exists with bam.txt and "dest" dir is a symlink
actual, err := ioutil.ReadDir(filepath.Join(testDir, "dest"))
actual, err := os.ReadDir(filepath.Join(testDir, "dest"))
if err != nil {
t.Fatal(err)
}
for i, f := range actual {
testutil.CheckDeepEqual(t, expected[i].Name(), f.Name())
testutil.CheckDeepEqual(t, expected[i].Mode(), f.Mode())
testutil.CheckDeepEqual(t, expected[i].Type(), f.Type())
}
})

Expand All @@ -757,7 +755,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{srcDir, linkedDest},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{srcDir}, DestPath: linkedDest},
},
fileContext: util.FileContext{Root: testDir},
}
Expand Down Expand Up @@ -802,7 +800,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{fmt.Sprintf("%s/bam.txt", srcDir), linkedDest},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{fmt.Sprintf("%s/bam.txt", srcDir)}, DestPath: linkedDest},
},
fileContext: util.FileContext{Root: testDir},
}
Expand Down Expand Up @@ -850,7 +848,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{fmt.Sprintf("%s/bam.txt", srcDir), testDir},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{fmt.Sprintf("%s/bam.txt", srcDir)}, DestPath: testDir},
Chown: "alice:group",
},
fileContext: util.FileContext{Root: testDir},
Expand Down Expand Up @@ -895,7 +893,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {

cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{fmt.Sprintf("%s/bam.txt", srcDir), testDir},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{fmt.Sprintf("%s/bam.txt", srcDir)}, DestPath: testDir},
Chown: "missing:missing",
},
fileContext: util.FileContext{Root: testDir},
Expand Down Expand Up @@ -927,7 +925,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
dest := filepath.Join(testDir, "copy")
cmd := CopyCommand{
cmd: &instructions.CopyCommand{
SourcesAndDest: []string{srcDir, dest},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{srcDir}, DestPath: dest},
},
fileContext: util.FileContext{Root: testDir},
}
Expand All @@ -939,7 +937,7 @@ func TestCopyCommand_ExecuteCommand_Extended(t *testing.T) {
}
err := cmd.ExecuteCommand(cfg, dockerfile.NewBuildArgs([]string{}))
testutil.CheckNoError(t, err)
actual, err := ioutil.ReadDir(filepath.Join(dest, "another"))
actual, err := os.ReadDir(filepath.Join(dest, "another"))
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ func Test_GetOnBuildInstructions(t *testing.T) {
stageToIdx: map[string]string{"builder": "0", "temp": "1"},
expCommands: []instructions.Command{
&instructions.CopyCommand{
SourcesAndDest: []string{"a.txt b.txt"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{"a.txt"}, DestPath: "b.txt"},
From: "0",
},
&instructions.CopyCommand{
SourcesAndDest: []string{"/app /app"},
SourcesAndDest: instructions.SourcesAndDest{SourcePaths: []string{"/app"}, DestPath: "/app"},
From: "1",
},
}},
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func CalculateDependencies(stages []config.KanikoStage, opts *config.KanikoOptio
if err != nil {
return nil, err
}
depGraph[i] = append(depGraph[i], resolved[0:len(resolved)-1]...)
depGraph[i] = append(depGraph[i], resolved[0:len(resolved)]...)
}
case *instructions.EnvCommand:
if err := util.UpdateConfigEnv(cmd.Env, &cfg.Config, ba.ReplacementEnvs(cfg.Config.Env)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ COPY --from=second /bar /bat
initializeConfig = tt.args.mockInitConfig
}

f, _ := ioutil.TempFile("", "")
ioutil.WriteFile(f.Name(), []byte(tt.args.dockerfile), 0755)
f, _ := os.CreateTemp("", "")
os.WriteFile(f.Name(), []byte(tt.args.dockerfile), 0755)
opts := &config.KanikoOptions{
DockerfilePath: f.Name(),
CustomPlatform: platforms.Format(platforms.Normalize(platforms.DefaultSpec())),
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/command_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func ResolveEnvAndWildcards(sd instructions.SourcesAndDest, fileContext FileCont
if len(resolvedEnvs) == 0 {
return nil, "", errors.New("resolved envs is empty")
}
dest := resolvedEnvs[len(resolvedEnvs)-1]
dest := sd.DestPath
// Resolve wildcards and get a list of resolved sources
srcs, err := ResolveSources(resolvedEnvs[0:len(resolvedEnvs)-1], fileContext.Root)
srcs, err := ResolveSources(resolvedEnvs[0:len(resolvedEnvs)], fileContext.Root)
if err != nil {
return nil, "", errors.Wrap(err, "failed to resolve sources")
}
Expand Down Expand Up @@ -226,8 +226,8 @@ func URLDestinationFilepath(rawurl, dest, cwd string, envs []string) (string, er
}

func IsSrcsValid(srcsAndDest instructions.SourcesAndDest, resolvedSources []string, fileContext FileContext) error {
srcs := srcsAndDest.SourcePaths[:len(srcsAndDest.SourcePaths)-1]
dest := srcsAndDest.SourcePaths[len(srcsAndDest.SourcePaths)-1]
srcs := srcsAndDest.SourcePaths
dest := srcsAndDest.DestPath

if !ContainsWildcards(srcs) {
totalSrcs := 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/command_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func Test_IsSrcsValid(t *testing.T) {
if err != nil {
t.Fatalf("error creating file context: %v", err)
}
err = IsSrcsValid(instructions.SourcesAndDest{SourcePaths: test.srcsAndDest}, test.resolvedSources, fileContext)
err = IsSrcsValid(instructions.SourcesAndDest{SourcePaths: test.srcsAndDest[0 : len(test.srcsAndDest)-1], DestPath: test.srcsAndDest[len(test.srcsAndDest)-1]}, test.resolvedSources, fileContext)
testutil.CheckError(t, test.shouldErr, err)
})
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/fs_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_enabled(t *testing.T)
root := t.TempDir()
// Write a whiteout path
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)
}

Expand Down Expand Up @@ -1067,7 +1067,7 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_enabled(t *testing.T)
mockLayer := mockv1.NewMockLayer(ctrl)
mockLayer.EXPECT().MediaType().Return(types.OCILayer, nil)

rc := ioutil.NopCloser(buf)
rc := io.NopCloser(buf)
mockLayer.EXPECT().Uncompressed().Return(rc, nil)

secondLayerFiles := []string{
Expand All @@ -1082,7 +1082,7 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_enabled(t *testing.T)
mockLayer2 := mockv1.NewMockLayer(ctrl)
mockLayer2.EXPECT().MediaType().Return(types.OCILayer, nil)

rc = ioutil.NopCloser(buf)
rc = io.NopCloser(buf)
mockLayer2.EXPECT().Uncompressed().Return(rc, nil)

layers := []v1.Layer{
Expand Down

0 comments on commit aab0f1e

Please sign in to comment.