Skip to content

Commit 9cc8e03

Browse files
committed
feat: add screen to automatically reattach terminal
1 parent d8f39df commit 9cc8e03

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/devspace/config/versions/latest/schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ type Terminal struct {
972972

973973
// Needed to turn pod replace off
974974
DisableReplace bool `yaml:"disableReplace,omitempty" json:"disableReplace,omitempty"`
975+
DisableScreen bool `yaml:"disableScreen,omitempty" json:"disableScreen,omitempty"`
975976
}
976977

977978
// PodPatch will patch a pod's owning ReplicaSet, Deployment or StatefulSet with the givens patches or image

pkg/devspace/services/terminal/terminal.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,41 @@ func StartTerminal(
126126
interruptpkg.Global.Stop()
127127
defer interruptpkg.Global.Start()
128128

129+
// try to install screen
130+
useScreen := false
131+
if !devContainer.Terminal.DisableScreen {
132+
bufferStdout, bufferStderr, err := ctx.KubeClient.ExecBuffered(ctx.Context, container.Pod, container.Container.Name, []string{
133+
"sh",
134+
"-c",
135+
`if ! command -v screen; then
136+
if command -v apk; then
137+
apk add --no-cache screen
138+
elif command -v apt-get; then
139+
apt-get -qq update && apt-get install -y screen && rm -rf /var/lib/apt/lists/*
140+
else
141+
echo "Couldn't install screen using neither apt-get nor apk."
142+
exit 1
143+
fi
144+
fi
145+
if command -v screen; then
146+
echo "Screen installed successfully."
147+
else
148+
echo "Couldn't find screen, need to fallback."
149+
exit 1
150+
fi`,
151+
}, nil)
152+
if err != nil {
153+
ctx.Log.Debugf("Error installing screen: %s %s %v", string(bufferStdout), string(bufferStderr), err)
154+
} else {
155+
useScreen = true
156+
}
157+
}
158+
if useScreen {
159+
newCommand := []string{"screen", "-dRSq", "dev"}
160+
newCommand = append(newCommand, command...)
161+
command = newCommand
162+
}
163+
129164
errChan <- ctx.KubeClient.ExecStream(ctx.Context, &kubectl.ExecStreamOptions{
130165
Pod: container.Pod,
131166
Container: container.Container.Name,

0 commit comments

Comments
 (0)