MCPcopy Create free account
hub / github.com/devspace-sh/devspace / startTerminal

Function startTerminal

pkg/devspace/services/terminal/terminal.go:159–235  ·  view source on GitHub ↗
(
	ctx devspacecontext.Context,
	command []string,
	tty bool,
	disableScreen bool,
	screenSession string,
	stdout io.Writer,
	stderr io.Writer,
	stdin io.Reader,
	container *selector.SelectedPodContainer,
)

Source from the content-addressed store, hash-verified

157}
158
159func startTerminal(
160 ctx devspacecontext.Context,
161 command []string,
162 tty bool,
163 disableScreen bool,
164 screenSession string,
165 stdout io.Writer,
166 stderr io.Writer,
167 stdin io.Reader,
168 container *selector.SelectedPodContainer,
169) error {
170 interruptpkg.Global.Stop()
171 defer interruptpkg.Global.Start()
172
173 // try to install screen
174 useScreen := false
175 if term.IsTerminal(stdin) && !disableScreen {
176 ctx.Log().Debugf("Installing screen in container...")
177 bufferStdout, bufferStderr, err := ctx.KubeClient().ExecBuffered(ctx.Context(), container.Pod, container.Container.Name, []string{
178 "sh",
179 "-c",
180 `if ! command -v screen; then
181 if command -v apk; then
182 apk add --no-cache screen
183 elif command -v apt-get; then
184 apt-get -qq update && apt-get install -y screen && rm -rf /var/lib/apt/lists/*
185 else
186 echo "Couldn't install screen using neither apt-get nor apk."
187 exit 1
188 fi
189fi
190if command -v screen; then
191 echo "Screen installed successfully."
192
193 if [ ! -f ~/.screenrc ]; then
194 echo "termcapinfo xterm* ti@:te@" > ~/.screenrc
195 echo "logfile /tmp/terminal-log.0" >> ~/.screenrc
196 echo "escape ^tt" >> ~/.screenrc
197 fi
198else
199 echo "Couldn't find screen, need to fallback."
200 exit 1
201fi`,
202 }, nil)
203 if err != nil {
204 ctx.Log().Debugf("Error installing screen: %s %s %v", string(bufferStdout), string(bufferStderr), err)
205 } else {
206 useScreen = true
207 }
208 }
209 if useScreen {
210 newCommand := []string{"screen", "-dRSqL", screenSession, "--"}
211 newCommand = append(newCommand, command...)
212 command = newCommand
213 }
214
215 ctx.Log().Debugf("Starting terminal...")
216

Callers 2

StartTerminalFromCMDFunction · 0.85
StartTerminalFunction · 0.85

Calls 11

GetBaseInstanceFunction · 0.92
StopMethod · 0.65
StartMethod · 0.65
LogMethod · 0.65
ExecBufferedMethod · 0.65
KubeClientMethod · 0.65
ContextMethod · 0.65
ExecStreamMethod · 0.65
DebugfMethod · 0.45
GetLevelMethod · 0.45
SetLevelMethod · 0.45

Tested by

no test coverage detected