Skip to content

Commit 19b235d

Browse files
committed
use feature added in coder/kaniko#16
1 parent 4138dc5 commit 19b235d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

envbuilder.go

+20-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"fmt"
1212
"io"
1313
"io/fs"
14-
"log"
1514
"maps"
1615
"net"
1716
"net/http"
@@ -343,21 +342,6 @@ func Run(ctx context.Context, options Options) error {
343342
}
344343
}
345344

346-
if options.PushImage {
347-
// 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-
353-
binPath := filepath.Join(MagicDir, "bin", "envbuilder")
354-
dst := filepath.Join(buildParams.BuildContext, binPath)
355-
err := copyFile(binPath, dst)
356-
if err != nil {
357-
return fmt.Errorf("aaa : %v", err)
358-
}
359-
}
360-
361345
HijackLogrus(func(entry *logrus.Entry) {
362346
for _, line := range strings.Split(entry.Message, "\r") {
363347
options.Logger(notcodersdk.LogLevelInfo, "#%d: %s", stageNumber, color.HiBlackString(line))
@@ -421,9 +405,29 @@ func Run(ctx context.Context, options Options) error {
421405
util.AddToDefaultIgnoreList(util.IgnoreListEntry{
422406
Path: ignorePath,
423407
PrefixMatchOnly: false,
408+
AllowedPaths: map[string]struct{}{},
424409
})
425410
}
426411

412+
// In order to allow 'resuming' envbuilder, embed the binary into the image
413+
// if it is being pushed
414+
if options.PushImage {
415+
exePath, err := os.Executable()
416+
if err != nil {
417+
return xerrors.Errorf("get exe path: %w", err)
418+
}
419+
// Add an exception for the current running binary in kaniko ignore list
420+
if err := util.AddAllowedPathToDefaultIgnoreList(exePath); err != nil {
421+
return xerrors.Errorf("add exe path to ignore list: %w", err)
422+
}
423+
// Copy the envbuilder binary into the build context.
424+
buildParams.DockerfileContent += fmt.Sprintf("\nCOPY %s %s", exePath, exePath)
425+
dst := filepath.Join(buildParams.BuildContext, exePath)
426+
if err := copyFile(exePath, dst); err != nil {
427+
return xerrors.Errorf("copy running binary to build context: %w", err)
428+
}
429+
}
430+
427431
// temp move of all ro mounts
428432
tempRemountDest := filepath.Join("/", MagicDir, "mnt")
429433
ignorePrefixes := []string{tempRemountDest, "/proc", "/sys"}

0 commit comments

Comments
 (0)