OnCommand implements the 'debug' command
( xc *app.ExecutionContext, gparams *command.GenericParams, commandParams *CommandParams)
| 22 | |
| 23 | // OnCommand implements the 'debug' command |
| 24 | func OnCommand( |
| 25 | xc *app.ExecutionContext, |
| 26 | gparams *command.GenericParams, |
| 27 | commandParams *CommandParams) { |
| 28 | logger := log.WithFields(log.Fields{"app": appName, "cmd": Name}) |
| 29 | |
| 30 | viChan := version.CheckAsync(gparams.CheckVersion, gparams.InContainer, gparams.IsDSImage) |
| 31 | |
| 32 | cmdReport := report.NewDebugCommand(gparams.ReportLocation, gparams.InContainer) |
| 33 | cmdReport.State = cmd.StateStarted |
| 34 | |
| 35 | xc.Out.State("started") |
| 36 | paramVars := ovars{ |
| 37 | "runtime": commandParams.Runtime, |
| 38 | "target": commandParams.TargetRef, |
| 39 | "debug-image": commandParams.DebugContainerImage, |
| 40 | "entrypoint": commandParams.Entrypoint, |
| 41 | "cmd": commandParams.Cmd, |
| 42 | "terminal": commandParams.DoTerminal, |
| 43 | } |
| 44 | |
| 45 | if commandParams.Runtime == KubernetesRuntime { |
| 46 | paramVars["namespace"] = commandParams.TargetNamespace |
| 47 | paramVars["pod"] = commandParams.TargetPod |
| 48 | } |
| 49 | |
| 50 | xc.Out.Info("params", paramVars) |
| 51 | |
| 52 | sid := generateSessionID() |
| 53 | debugContainerName := generateContainerName(sid) |
| 54 | logger = logger.WithFields( |
| 55 | log.Fields{ |
| 56 | "sid": sid, |
| 57 | "debug.container.name": debugContainerName, |
| 58 | }) |
| 59 | |
| 60 | switch commandParams.Runtime { |
| 61 | case DockerRuntime: |
| 62 | client, err := dockerclient.New(gparams.ClientConfig) |
| 63 | if err == dockerclient.ErrNoDockerInfo { |
| 64 | exitMsg := "missing Docker connection info" |
| 65 | if gparams.InContainer && gparams.IsDSImage { |
| 66 | exitMsg = "make sure to pass the Docker connect parameters to the slim app container" |
| 67 | } |
| 68 | |
| 69 | xc.Out.Info("docker.connect.error", |
| 70 | ovars{ |
| 71 | "message": exitMsg, |
| 72 | }) |
| 73 | |
| 74 | exitCode := command.ECTCommon | command.ECCNoDockerConnectInfo |
| 75 | xc.Out.State("exited", |
| 76 | ovars{ |
| 77 | "exit.code": exitCode, |
| 78 | "version": v.Current(), |
| 79 | "location": fsutil.ExeDir(), |
| 80 | }) |
| 81 | xc.Exit(exitCode) |
no test coverage detected