MCPcopy Index your code
hub / github.com/coder/envbox / dockerCmd

Function dockerCmd

cli/docker.go:156–453  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

154}
155
156func dockerCmd() *cobra.Command {
157 var flags flags
158
159 cmd := &cobra.Command{
160 Use: "docker",
161 Short: "Create a docker-based CVM",
162 RunE: func(cmd *cobra.Command, args []string) (err error) {
163 var (
164 ctx, cancel = context.WithCancel(cmd.Context()) //nolint
165 log = slog.Make(slogjson.Sink(cmd.ErrOrStderr()), slogkubeterminate.Make()).Leveled(slog.LevelDebug)
166 blog buildlog.Logger = buildlog.JSONLogger{Encoder: json.NewEncoder(os.Stderr)}
167 )
168
169 // We technically leak a context here, but it's impact is negligible.
170 signalCtx, signalCancel := context.WithCancel(ctx)
171 sigs := make(chan os.Signal, 1)
172 signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGWINCH)
173
174 // Spawn a goroutine to wait for a signal.
175 go func() {
176 defer signalCancel()
177 log.Info(ctx, "waiting for signal")
178 <-sigs
179 log.Info(ctx, "got signal, canceling context")
180 }()
181
182 if flags.noStartupLogs {
183 log = slog.Make(slogjson.Sink(io.Discard))
184 blog = buildlog.NopLogger{}
185 }
186
187 httpClient, err := xhttp.Client(log, flags.extraCertsPath)
188 if err != nil {
189 //nolint
190 return xerrors.Errorf("http client: %w", err)
191 }
192
193 if !flags.noStartupLogs && flags.agentToken != "" && flags.coderURL != "" {
194 coderURL, err := url.Parse(flags.coderURL)
195 if err != nil {
196 return xerrors.Errorf("parse coder URL %q: %w", flags.coderURL, err)
197 }
198
199 agent, err := buildlog.OpenCoderClient(ctx, log, coderURL, httpClient, flags.agentToken)
200 if err != nil {
201 // Don't fail workspace startup on
202 // an inability to push build logs.
203 log.Error(ctx, "failed to instantiate coder build log client, no logs will be pushed", slog.Error(err))
204 } else {
205 blog = buildlog.MultiLogger(
206 buildlog.OpenCoderLogger(ctx, agent, log),
207 blog,
208 )
209 }
210 }
211 defer blog.Close()
212
213 defer func(err *error) {

Callers 1

RootFunction · 0.85

Calls 15

MakeFunction · 0.92
ClientFunction · 0.92
OpenCoderClientFunction · 0.92
MultiLoggerFunction · 0.92
OpenCoderLoggerFunction · 0.92
NewFunction · 0.92
WaitForManagerFunction · 0.92
ExtractClientFunction · 0.92
IsNoSpaceErrFunction · 0.92
WaitForDaemonFunction · 0.92
WriteCertsForRegistryFunction · 0.92
GetExecPIDFunction · 0.92

Tested by

no test coverage detected