Skip to content

Commit e41935d

Browse files
committed
chore: add logging to bootstrap script
1 parent 591328a commit e41935d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cli/docker.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker
655655
// downloading the binary but before we can execute systemd remounts
656656
// /tmp.
657657
Env: []string{fmt.Sprintf("BINARY_DIR=%s", bootDir)},
658+
StdOutErr: slogWriter{
659+
ctx: ctx,
660+
Logger: log,
661+
},
658662
})
659663
if err != nil {
660664
return xerrors.Errorf("boostrap container: %w", err)
@@ -797,3 +801,13 @@ func isHomeDir(fpath string) bool {
797801
func shiftedID(id int) int {
798802
return id + UserNamespaceOffset
799803
}
804+
805+
type slogWriter struct {
806+
ctx context.Context
807+
slog.Logger
808+
}
809+
810+
func (s slogWriter) Write(p []byte) (int, error) {
811+
s.Debug(s.ctx, string(p))
812+
return len(p), nil
813+
}

dockerutil/container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dockerutil
33
import (
44
"context"
55
"fmt"
6+
"io"
67
"path/filepath"
78
"strconv"
89
"strings"
@@ -100,6 +101,7 @@ type BootstrapConfig struct {
100101
Script string
101102
Env []string
102103
Detach bool
104+
StdOutErr io.Writer
103105
}
104106

105107
// BoostrapContainer runs a script inside the container as the provided user.
@@ -119,6 +121,7 @@ func BootstrapContainer(ctx context.Context, client DockerClient, conf Bootstrap
119121
Args: []string{"-s"},
120122
Stdin: strings.NewReader(conf.Script),
121123
Env: conf.Env,
124+
StdOutErr: conf.StdOutErr,
122125
})
123126
if err != nil {
124127
err = xerrors.Errorf("boostrap container (%s): %w", out, err)

0 commit comments

Comments
 (0)