Skip to content

Commit 4138dc5

Browse files
committed
Simple copy file operation
1 parent 3eb4217 commit 4138dc5

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

envbuilder.go

+27-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"io"
1313
"io/fs"
14+
"log"
1415
"maps"
1516
"net"
1617
"net/http"
@@ -27,7 +28,6 @@ import (
2728

2829
"github.com/kballard/go-shellquote"
2930
"github.com/mattn/go-isatty"
30-
cp "github.com/otiai10/copy"
3131

3232
"github.com/GoogleContainerTools/kaniko/pkg/config"
3333
"github.com/GoogleContainerTools/kaniko/pkg/creds"
@@ -345,13 +345,17 @@ func Run(ctx context.Context, options Options) error {
345345

346346
if options.PushImage {
347347
// Copy the envbuilder binary into the build context.
348+
buildParams.DockerfileContent = buildParams.DockerfileContent + "\n" +
349+
fmt.Sprintf("COPY %s %s", ".envbuilder", "/.envbuilder")
350+
351+
log.Println("FIXME show me the Dockerfile now: " + buildParams.DockerfileContent)
352+
348353
binPath := filepath.Join(MagicDir, "bin", "envbuilder")
349-
err := cp.Copy(binPath, filepath.Join(buildParams.BuildContext, binPath))
354+
dst := filepath.Join(buildParams.BuildContext, binPath)
355+
err := copyFile(binPath, dst)
350356
if err != nil {
351-
return err
357+
return fmt.Errorf("aaa : %v", err)
352358
}
353-
buildParams.DockerfileContent = buildParams.DockerfileContent + "\n" +
354-
"COPY " + binPath + " " + binPath
355359
}
356360

357361
HijackLogrus(func(entry *logrus.Entry) {
@@ -1171,3 +1175,21 @@ func maybeDeleteFilesystem(log LoggerFunc, force bool) error {
11711175

11721176
return util.DeleteFilesystem()
11731177
}
1178+
1179+
func copyFile(src, dst string) error {
1180+
content, err := os.ReadFile(src)
1181+
if err != nil {
1182+
return xerrors.Errorf("read file failed: %w", err)
1183+
}
1184+
1185+
err = os.MkdirAll(filepath.Dir(dst), 0755)
1186+
if err != nil {
1187+
return xerrors.Errorf("mkdir all failed: %w", err)
1188+
}
1189+
1190+
err = os.WriteFile(dst, content, 0644)
1191+
if err != nil {
1192+
return xerrors.Errorf("write file failed: %w", err)
1193+
}
1194+
return nil
1195+
}

0 commit comments

Comments
 (0)