Skip to content

chore: add CODER_DEBUG to enable troubleshooting bootstrap script #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cli/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var (
EnvMemory = "CODER_MEMORY"
EnvAddGPU = "CODER_ADD_GPU"
EnvUsrLibDir = "CODER_USR_LIB_DIR"
EnvDebug = "CODER_DEBUG"
)

var envboxPrivateMounts = map[string]struct{}{
Expand Down Expand Up @@ -126,14 +127,17 @@ type flags struct {
addTUN bool
addFUSE bool
addGPU bool
noStartupLogs bool
dockerdBridgeCIDR string
boostrapScript string
ethlink string
containerMounts string
hostUsrLibDir string
cpus int
memory int

// Test flags.
noStartupLogs bool
debug bool
ethlink string
}

func dockerCmd() *cobra.Command {
Expand Down Expand Up @@ -333,6 +337,7 @@ func dockerCmd() *cobra.Command {

// Test flags.
cliflag.BoolVarP(cmd.Flags(), &flags.noStartupLogs, "no-startup-log", "", "", false, "Do not log startup logs. Useful for testing.")
cliflag.BoolVarP(cmd.Flags(), &flags.debug, "debug", "", EnvDebug, false, "Log additional output.")
cliflag.StringVarP(cmd.Flags(), &flags.ethlink, "ethlink", "", "", defaultNetLink, "The ethernet link to query for the MTU that is passed to docerd. Used for tests.")

return cmd
Expand Down Expand Up @@ -644,6 +649,15 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker

blog.Info("Envbox startup complete!")

// The bootstrap script doesn't return since it execs the agent
// meaning that it can get pretty noisy if we were to log by default.
// In order to allow users to discern issues getting the bootstrap script
// to complete successfully we pipe the output to stdout if
// CODER_DEBUG=true.
debugWriter := io.Discard
if flags.debug {
debugWriter = os.Stdout
}
// Bootstrap the container if a script has been provided.
blog.Infof("Bootstrapping workspace...")
err = dockerutil.BootstrapContainer(ctx, client, dockerutil.BootstrapConfig{
Expand All @@ -654,7 +668,8 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker
// to /tmp/coder.XXXX. This causes a race to happen where we finish
// downloading the binary but before we can execute systemd remounts
// /tmp.
Env: []string{fmt.Sprintf("BINARY_DIR=%s", bootDir)},
Env: []string{fmt.Sprintf("BINARY_DIR=%s", bootDir)},
StdOutErr: debugWriter,
})
if err != nil {
return xerrors.Errorf("boostrap container: %w", err)
Expand Down
3 changes: 3 additions & 0 deletions dockerutil/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dockerutil
import (
"context"
"fmt"
"io"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -100,6 +101,7 @@ type BootstrapConfig struct {
Script string
Env []string
Detach bool
StdOutErr io.Writer
}

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