mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-24 08:01:03 +00:00
Merge 0f8786995e into 7e7aadc207
This commit is contained in:
commit
c9e2d32afd
3 changed files with 52 additions and 9 deletions
|
|
@ -220,6 +220,9 @@ type CommandTemplatesConfig struct {
|
||||||
|
|
||||||
// ServiceTop is the command for viewing the processes under a given service
|
// ServiceTop is the command for viewing the processes under a given service
|
||||||
ServiceTop string `yaml:"serviceTop,omitempty"`
|
ServiceTop string `yaml:"serviceTop,omitempty"`
|
||||||
|
|
||||||
|
// List of shells that, in given order, will be tried when attaching to a container.
|
||||||
|
PreferredExecShells []string `yaml:"preferedExecShell,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OSConfig contains config on the level of the os
|
// OSConfig contains config on the level of the os
|
||||||
|
|
@ -402,6 +405,7 @@ func GetDefaultConfig() UserConfig {
|
||||||
DockerComposeConfig: "{{ .DockerCompose }} config",
|
DockerComposeConfig: "{{ .DockerCompose }} config",
|
||||||
CheckDockerComposeConfig: "{{ .DockerCompose }} config --quiet",
|
CheckDockerComposeConfig: "{{ .DockerCompose }} config --quiet",
|
||||||
ServiceTop: "{{ .DockerCompose }} top {{ .Service.Name }}",
|
ServiceTop: "{{ .DockerCompose }} top {{ .Service.Name }}",
|
||||||
|
PreferredExecShells: []string{},
|
||||||
},
|
},
|
||||||
CustomCommands: CustomCommands{
|
CustomCommands: CustomCommands{
|
||||||
Containers: []CustomCommand{},
|
Containers: []CustomCommand{},
|
||||||
|
|
|
||||||
|
|
@ -466,11 +466,32 @@ func (gui *Gui) containerExecShell(container *commands.Container) error {
|
||||||
commandObject := gui.DockerCommand.NewCommandObject(commands.CommandObject{
|
commandObject := gui.DockerCommand.NewCommandObject(commands.CommandObject{
|
||||||
Container: container,
|
Container: container,
|
||||||
})
|
})
|
||||||
|
var command string
|
||||||
|
shell := ""
|
||||||
|
|
||||||
// TODO: use SDK
|
preferredExecShells := gui.Config.UserConfig.CommandTemplates.PreferredExecShells
|
||||||
resolvedCommand := utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", commandObject)
|
if len(preferredExecShells) > 0 {
|
||||||
|
for _, preferredExecShell := range preferredExecShells {
|
||||||
|
command := utils.ApplyTemplate(fmt.Sprintf("docker exec {{ .Container.ID }} which %s", preferredExecShell), commandObject)
|
||||||
|
|
||||||
|
err := gui.runCommandSilently(gui.OSCommand.ExecutableFromString(command))
|
||||||
|
if err == nil {
|
||||||
|
shell = preferredExecShell
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Use SDK
|
||||||
|
// Use default implementation in case we cannot fulfill user's preference
|
||||||
|
if shell == "" {
|
||||||
|
command = utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", commandObject)
|
||||||
|
} else {
|
||||||
|
command = utils.ApplyTemplate(fmt.Sprintf("docker exec -it {{ .Container.ID }} %s", shell), commandObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := gui.OSCommand.ExecutableFromString(command)
|
||||||
// attach and return the subprocess error
|
// attach and return the subprocess error
|
||||||
cmd := gui.OSCommand.ExecutableFromString(resolvedCommand)
|
|
||||||
return gui.runSubprocess(cmd)
|
return gui.runSubprocess(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ func (gui *Gui) runSubprocessWithMessage(cmd *exec.Cmd, msg string) error {
|
||||||
|
|
||||||
gui.PauseBackgroundThreads = true
|
gui.PauseBackgroundThreads = true
|
||||||
|
|
||||||
gui.runCommand(cmd, msg)
|
err := gui.runCommand(cmd, msg)
|
||||||
|
|
||||||
if err := gui.g.Resume(); err != nil {
|
if err := gui.g.Resume(); err != nil {
|
||||||
return gui.createErrorPanel(err.Error())
|
return gui.createErrorPanel(err.Error())
|
||||||
|
|
@ -34,10 +34,26 @@ func (gui *Gui) runSubprocessWithMessage(cmd *exec.Cmd, msg string) error {
|
||||||
|
|
||||||
gui.PauseBackgroundThreads = false
|
gui.PauseBackgroundThreads = false
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) {
|
func (gui *Gui) runCommandSilently(cmd *exec.Cmd) error {
|
||||||
|
stop := make(chan os.Signal, 1)
|
||||||
|
defer signal.Stop(stop)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
signal.Notify(stop, os.Interrupt)
|
||||||
|
<-stop
|
||||||
|
|
||||||
|
if err := gui.OSCommand.Kill(cmd); err != nil {
|
||||||
|
gui.Log.Error(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) error {
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stdout
|
cmd.Stderr = os.Stdout
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
|
|
@ -58,9 +74,9 @@ func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) {
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
fmt.Fprintf(os.Stdout, "\n%s\n\n", utils.ColoredString(msg, color.FgGreen))
|
fmt.Fprintf(os.Stdout, "\n%s\n\n", utils.ColoredString(msg, color.FgGreen))
|
||||||
}
|
}
|
||||||
if err := cmd.Run(); err != nil {
|
err := cmd.Run()
|
||||||
// not handling the error explicitly because usually we're going to see it
|
|
||||||
// in the output anyway
|
if err != nil {
|
||||||
gui.Log.Error(err)
|
gui.Log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,4 +85,6 @@ func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) {
|
||||||
cmd.Stderr = io.Discard
|
cmd.Stderr = io.Discard
|
||||||
|
|
||||||
gui.promptToReturn()
|
gui.promptToReturn()
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue