From 6c27cf3f32be73a948113b8125008c78ca2eb2e4 Mon Sep 17 00:00:00 2001 From: Konstantin Mikhailov Date: Sat, 27 Mar 2021 06:37:04 +1000 Subject: [PATCH 1/8] Open service in browser --- docs/keybindings/Keybindings_de.md | 1 + docs/keybindings/Keybindings_en.md | 1 + docs/keybindings/Keybindings_nl.md | 1 + docs/keybindings/Keybindings_pl.md | 1 + docs/keybindings/Keybindings_tr.md | 1 + pkg/gui/keybindings.go | 7 +++++++ pkg/gui/services_panel.go | 28 ++++++++++++++++++++++++++++ 7 files changed, 40 insertions(+) diff --git a/docs/keybindings/Keybindings_de.md b/docs/keybindings/Keybindings_de.md index 2ec26c14..ea89147d 100644 --- a/docs/keybindings/Keybindings_de.md +++ b/docs/keybindings/Keybindings_de.md @@ -42,6 +42,7 @@ R: zeige Neustartoptionen c: führe vordefinierten benutzerdefinierten Befehl aus b: view bulk commands + w: open in browser (first port is http) enter: fokussieren aufs Hauptpanel diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index ac16e92e..85e67026 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -42,6 +42,7 @@ R: view restart options c: run predefined custom command b: view bulk commands + w: open in browser (first port is http) enter: focus main panel diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 10f7d524..f0f50dbc 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -42,6 +42,7 @@ R: bekijk herstart opties c: draai een vooraf bedacht aangepaste opdracht b: view bulk commands + w: open in browser (first port is http) enter: focus hoofdpaneel diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index af32ec47..a902386f 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -42,6 +42,7 @@ R: pokaż opcje restartu c: wykonaj predefiniowaną własną komende b: view bulk commands + w: open in browser (first port is http) enter: skup na głównym panelu diff --git a/docs/keybindings/Keybindings_tr.md b/docs/keybindings/Keybindings_tr.md index a7079d42..85b43165 100644 --- a/docs/keybindings/Keybindings_tr.md +++ b/docs/keybindings/Keybindings_tr.md @@ -42,6 +42,7 @@ R: yeniden başlatma seçeneklerini görüntüle c: önceden tanımlanmış özel komutu çalıştır b: view bulk commands + w: open in browser (first port is http) enter: ana panele odaklan diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index d7784a41..cfb9c42f 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -346,6 +346,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.handleServicesBulkCommand, Description: gui.Tr.ViewBulkCommands, }, + { + ViewName: "services", + Key: 'w', + Modifier: gocui.ModNone, + Handler: gui.handleServicesOpenInBrowserCommand, + Description: gui.Tr.OpenInBrowser, + }, { ViewName: "images", Key: '[', diff --git a/pkg/gui/services_panel.go b/pkg/gui/services_panel.go index 460a3a07..8ce15913 100644 --- a/pkg/gui/services_panel.go +++ b/pkg/gui/services_panel.go @@ -409,3 +409,31 @@ func (gui *Gui) handleServicesBulkCommand(g *gocui.Gui, v *gocui.View) error { return gui.createBulkCommandMenu(bulkCommands, commandObject) } + +func (gui *Gui) handleServicesOpenInBrowserCommand(g *gocui.Gui, v *gocui.View) error { + service, err := gui.getSelectedService() + if err != nil { + return nil + } + + container := service.Container + if container == nil { + return gui.createErrorPanel(gui.g, gui.Tr.NoContainers) + } + + // skip if no any ports + if len(container.Container.Ports) == 0 { + return nil + } + // skip if the first port is not published + port := container.Container.Ports[0] + if port.IP == "" { + return nil + } + ip := port.IP + if ip == "0.0.0.0" { + ip = "localhost" + } + link := fmt.Sprintf("http://%s:%d/", ip, port.PublicPort) + return gui.OSCommand.OpenLink(link) +} From 58d1d286526aee6308e1f55a9f14a10f25d652f9 Mon Sep 17 00:00:00 2001 From: Guruprasad Kulkarni Date: Fri, 14 May 2021 13:26:02 +0200 Subject: [PATCH 2/8] Added link to asdf-vm installation method :) --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 4eb708ab..a22d020e 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,14 @@ Automated install/update, don't forget to always verify what you're piping into curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash ``` +#### Or Use [asdf-vm](https://asdf-vm.com/) to install the [asdf-lazydocker plugin](https://github.com/comdotlinux/asdf-lazydocker) once and then keep updating to get the latest version whenever you want. +```sh +asdf plugin add https://github.com/comdotlinux/asdf-lazydocker.git +asdf list all lazydocker +asdf install lazydocker 0.12 +asdf global lazydocker 0.12 +``` + The script installs downloaded binary to `/usr/local/bin` directory by default, but it can be changed by setting `DIR` environment variable. ### Go From 926ab3a40b12e6645da5ed5376fbbd1cae0f0645 Mon Sep 17 00:00:00 2001 From: Guruprasad Kulkarni Date: Fri, 18 Jun 2021 14:21:56 +0200 Subject: [PATCH 3/8] Moved the asdf instructions above binary releases --- README.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a22d020e..acc7e2c0 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,20 @@ You can install `lazydocker` using [Chocolatey](https://chocolatey.org/): ```sh choco install lazydocker ``` +### asdf-vm + +You can install [asdf-lazydocker plugin](https://github.com/comdotlinux/asdf-lazydocker) using [asdf-vm](https://asdf-vm.com/): +#### Setup (Once) +```sh +asdf plugin add https://github.com/comdotlinux/asdf-lazydocker.git +``` + +#### For Install / Upgrade +```sh +asdf list all lazydocker +asdf install lazydocker 0.12 +asdf global lazydocker 0.12 +``` ### Binary Release (Linux/OSX/Windows) @@ -81,15 +95,6 @@ Automated install/update, don't forget to always verify what you're piping into ```sh curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash ``` - -#### Or Use [asdf-vm](https://asdf-vm.com/) to install the [asdf-lazydocker plugin](https://github.com/comdotlinux/asdf-lazydocker) once and then keep updating to get the latest version whenever you want. -```sh -asdf plugin add https://github.com/comdotlinux/asdf-lazydocker.git -asdf list all lazydocker -asdf install lazydocker 0.12 -asdf global lazydocker 0.12 -``` - The script installs downloaded binary to `/usr/local/bin` directory by default, but it can be changed by setting `DIR` environment variable. ### Go From 43f83f64ec74af47c91cf7b50f87ef312a587b27 Mon Sep 17 00:00:00 2001 From: Dwarven YANG Date: Mon, 30 Aug 2021 09:54:55 +0800 Subject: [PATCH 4/8] allow user to configure the gui language --- docs/Config.md | 1 + pkg/app/app.go | 5 ++++- pkg/commands/dummies.go | 5 +++-- pkg/config/app_config.go | 4 ++++ pkg/i18n/i18n.go | 23 ++++++++++++++++++----- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 5f35dc72..20221fa2 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -16,6 +16,7 @@ Changes to the user config will only take place after closing and re-opening laz ```yml gui: scrollHeight: 2 + language: 'auto' # one of 'auto' | 'en' | 'pl' | 'nl' | 'de' | 'tr' theme: activeBorderColor: - green diff --git a/pkg/app/app.go b/pkg/app/app.go index ffc73494..c1b426b8 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -34,7 +34,10 @@ func NewApp(config *config.AppConfig) (*App, error) { } var err error app.Log = log.NewLogger(config, "23432119147a4367abf7c0de2aa99a2d") - app.Tr = i18n.NewTranslationSet(app.Log) + app.Tr, err = i18n.NewTranslationSetFromConfig(app.Log, config.UserConfig.Gui.Language) + if err != nil { + return app, err + } app.OSCommand = commands.NewOSCommand(app.Log, config) // here is the place to make use of the docker-compose.yml file in the current directory diff --git a/pkg/commands/dummies.go b/pkg/commands/dummies.go index c32e8f76..416a57dd 100644 --- a/pkg/commands/dummies.go +++ b/pkg/commands/dummies.go @@ -42,10 +42,11 @@ func NewDummyDockerCommand() *DockerCommand { // NewDummyDockerCommandWithOSCommand creates a new dummy DockerCommand for testing func NewDummyDockerCommandWithOSCommand(osCommand *OSCommand) *DockerCommand { + newAppConfig := NewDummyAppConfig() return &DockerCommand{ Log: NewDummyLog(), OSCommand: osCommand, - Tr: i18n.NewTranslationSet(NewDummyLog()), - Config: NewDummyAppConfig(), + Tr: i18n.NewTranslationSet(NewDummyLog(), newAppConfig.UserConfig.Gui.Language), + Config: newAppConfig, } } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 8c8fa8a9..00f62208 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -79,6 +79,9 @@ type GuiConfig struct { // scrolling the main panel ScrollHeight int `yaml:"scrollHeight,omitempty"` + // Language determines which language the GUI displayed. + Language string `yaml:"language,omitempty"` + // ScrollPastBottom determines whether you can scroll past the bottom of the // main view ScrollPastBottom bool `yaml:"scrollPastBottom,omitempty"` @@ -311,6 +314,7 @@ func GetDefaultConfig() UserConfig { return UserConfig{ Gui: GuiConfig{ ScrollHeight: 2, + Language: "auto", ScrollPastBottom: false, IgnoreMouseEvents: false, Theme: ThemeConfig{ diff --git a/pkg/i18n/i18n.go b/pkg/i18n/i18n.go index bdc62ab1..914ec1ba 100644 --- a/pkg/i18n/i18n.go +++ b/pkg/i18n/i18n.go @@ -6,6 +6,7 @@ import ( "github.com/imdario/mergo" "github.com/cloudfoundry/jibber_jabber" + "github.com/go-errors/errors" "github.com/sirupsen/logrus" ) @@ -16,16 +17,28 @@ type Localizer struct { S TranslationSet } -// NewTranslationSet creates a new Localizer -func NewTranslationSet(log *logrus.Entry) *TranslationSet { - userLang := detectLanguage(jibber_jabber.DetectLanguage) +func NewTranslationSetFromConfig(log *logrus.Entry, configLanguage string) (*TranslationSet, error) { + if configLanguage == "auto" { + language := detectLanguage(jibber_jabber.DetectLanguage) + return NewTranslationSet(log, language), nil + } - log.Info("language: " + userLang) + for key := range GetTranslationSets() { + if key == configLanguage { + return NewTranslationSet(log, configLanguage), nil + } + } + + return NewTranslationSet(log, "en"), errors.New("Language not found: " + configLanguage) +} + +func NewTranslationSet(log *logrus.Entry, language string) *TranslationSet { + log.Info("language: " + language) baseSet := englishSet() for languageCode, translationSet := range GetTranslationSets() { - if strings.HasPrefix(userLang, languageCode) { + if strings.HasPrefix(language, languageCode) { _ = mergo.Merge(&baseSet, translationSet, mergo.WithOverride) } } From 8acb257abe9b9cf5ec9adc2b9172336ab8ba9bd7 Mon Sep 17 00:00:00 2001 From: Kevin Degeling Date: Sun, 19 Sep 2021 13:45:41 +0200 Subject: [PATCH 5/8] Improved installation script that avoids sudo rights --- scripts/install_update_linux.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_update_linux.sh b/scripts/install_update_linux.sh index d4e0cee0..6c497196 100755 --- a/scripts/install_update_linux.sh +++ b/scripts/install_update_linux.sh @@ -1,7 +1,7 @@ #!/bin/bash # allow specifying different destination directory -DIR="${DIR:-"/usr/local/bin"}" +DIR="${DIR:-"$HOME/.local/bin"}" # map different architecture variations to the available binaries ARCH=$(uname -m) @@ -20,5 +20,5 @@ GITHUB_URL="https://github.com/jesseduffield/lazydocker/releases/download/${GITH # install/update the local binary curl -L -o lazydocker.tar.gz $GITHUB_URL tar xzvf lazydocker.tar.gz lazydocker -sudo mv -f lazydocker "$DIR" +install -Dm 755 lazydocker -t "$DIR" rm lazydocker.tar.gz From 9db6eeac9dc60734f58b520aad8af59c46805ec6 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 26 Nov 2021 20:49:51 +1100 Subject: [PATCH 6/8] do not panic if docker client not running --- go.mod | 1 - go.sum | 22 ---------------------- pkg/commands/docker.go | 3 ++- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index e6a128ad..d142f368 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/integrii/flaggy v1.4.0 github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee github.com/jesseduffield/gocui v0.3.1-0.20200201013258-57fdcf23edc5 - github.com/jesseduffield/rollrus v0.0.0-20190701125922-dd028cb0bfd7 // indirect github.com/jesseduffield/termbox-go v0.0.0-20200130214842-1d31d1faa3c9 // indirect github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56 github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect diff --git a/go.sum b/go.sum index 1d9338df..2f96303e 100644 --- a/go.sum +++ b/go.sum @@ -48,23 +48,14 @@ github.com/integrii/flaggy v1.4.0 h1:A1x7SYx4jqu5NSrY14z8Z+0UyX2S5ygfJJrfolWR3zM github.com/integrii/flaggy v1.4.0/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI= github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee h1:7Zi/OQlGbMz4MT2V1+prN/gv1C64NDyVb/MbJnS0ZfA= github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee/go.mod h1:Z9UKHveKXXgyo8ME7R8yxh/BUTFOK+FgfWKlhy8oOAg= -github.com/jesseduffield/gocui v0.3.1-0.20190803023616-ad0cd60f29f9 h1:v2Pf3RaIN+MlFfSDnJw2d9Qksr4Tw08+pjL4LEY+JLM= -github.com/jesseduffield/gocui v0.3.1-0.20190803023616-ad0cd60f29f9/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw= github.com/jesseduffield/gocui v0.3.1-0.20200201013258-57fdcf23edc5 h1:tE0w3tuL/bj1o5VMhjjE0ep6i7Fva+RYjKcMFcniJEY= github.com/jesseduffield/gocui v0.3.1-0.20200201013258-57fdcf23edc5/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw= -github.com/jesseduffield/roll v0.0.0-20190629104057-695be2e62b00 h1:+JaOkfBNYQYlGD7dgru8mCwYNEc5tRRI8mThlVANhSM= -github.com/jesseduffield/roll v0.0.0-20190629104057-695be2e62b00/go.mod h1:cWNQljQAWYBp4wchyGfql4q2jRNZXxiE1KhVQgz+JaM= -github.com/jesseduffield/rollrus v0.0.0-20190701125922-dd028cb0bfd7 h1:CRD7bVjlGIiV+M0jlsa+XWpneW0KY0e7Y4z3GWb5S4o= -github.com/jesseduffield/rollrus v0.0.0-20190701125922-dd028cb0bfd7/go.mod h1:VspA3aTkEo0Q7TPCLmX1uHNP+Wb4iSDX09hmTRo1QYc= -github.com/jesseduffield/termbox-go v0.0.0-20190630083001-9dd53af7214e h1:tth7wr6+sfSbdpRWWrwvLYyS56HyIRVfq0Qcl2h28wM= -github.com/jesseduffield/termbox-go v0.0.0-20190630083001-9dd53af7214e/go.mod h1:anMibpZtqNxjDbxrcDEAwSdaJ37vyUeM1f/M4uekib4= github.com/jesseduffield/termbox-go v0.0.0-20200130214842-1d31d1faa3c9 h1:iBBk1lhFwjwJw//J2m1yyz9S368GeXQTpMVACTyQMh0= github.com/jesseduffield/termbox-go v0.0.0-20200130214842-1d31d1faa3c9/go.mod h1:anMibpZtqNxjDbxrcDEAwSdaJ37vyUeM1f/M4uekib4= github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56 h1:33wSxJWU/f2TAozHYtJ8zqBxEnEVYM+22moLoiAkxvg= github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56/go.mod h1:FZJBwOhE+RXz8EVZfY+xnbCw2cVOwxlK3/aIi581z/s= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -73,8 +64,6 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= -github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0= github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mcuadros/go-lookup v0.0.0-20171110082742-5650f26be767 h1:BrhJNdEFWGuiJk/3/SwsG5Rex3zjFxYsDi2bpd7382Y= @@ -96,8 +85,6 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME= -github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= @@ -107,27 +94,18 @@ github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 2dc5e6ae..ce228705 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + ogLog "log" "os/exec" "sort" "strings" @@ -70,7 +71,7 @@ func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject { func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) { cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(APIVersion)) if err != nil { - return nil, err + ogLog.Fatal(err) } dockerCommand := &DockerCommand{ From 3c9437f801dcacf7aad25a44942cf7a5e58315d1 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 26 Nov 2021 21:16:47 +1100 Subject: [PATCH 7/8] slightly more responsive --- pkg/gui/containers_panel.go | 90 +++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 25fb6770..8aabc66f 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -178,58 +178,62 @@ func (gui *Gui) renderContainerLogs(container *commands.Container) error { mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel return gui.T.NewTickerTask(time.Millisecond*200, nil, func(stop, notifyStopped chan struct{}) { - gui.clearMainView() + gui.renderContainerLogsAux(container, stop, notifyStopped) + }) +} - command := utils.ApplyTemplate( - gui.Config.UserConfig.CommandTemplates.ContainerLogs, - gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}), - ) - cmd := gui.OSCommand.RunCustomCommand(command) +func (gui *Gui) renderContainerLogsAux(container *commands.Container, stop, notifyStopped chan struct{}) { + gui.clearMainView() - // Ensure the child process is treated as a group, as the child process spawns - // its own children. Termination requires sending the signal to the group - // process ID. - gui.OSCommand.PrepareForChildren(cmd) + command := utils.ApplyTemplate( + gui.Config.UserConfig.CommandTemplates.ContainerLogs, + gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}), + ) + cmd := gui.OSCommand.RunCustomCommand(command) - mainView := gui.getMainView() - cmd.Stdout = mainView - cmd.Stderr = mainView + // Ensure the child process is treated as a group, as the child process spawns + // its own children. Termination requires sending the signal to the group + // process ID. + gui.OSCommand.PrepareForChildren(cmd) - cmd.Start() + mainView := gui.getMainView() + cmd.Stdout = mainView + cmd.Stderr = mainView - go func() { - <-stop - if err := gui.OSCommand.Kill(cmd); err != nil { - gui.Log.Warn(err) - } - gui.Log.Info("killed container logs process") + cmd.Start() + + go func() { + <-stop + if err := gui.OSCommand.Kill(cmd); err != nil { + gui.Log.Warn(err) + } + gui.Log.Info("killed container logs process") + return + }() + + cmd.Wait() + + // if we are here because the task has been stopped, we should return + // if we are here then the container must have exited, meaning we should wait until it's back again before + ticker := time.NewTicker(time.Millisecond * 100) + defer ticker.Stop() + for { + select { + case <-stop: return - }() - - cmd.Wait() - - // if we are here because the task has been stopped, we should return - // if we are here then the container must have exited, meaning we should wait until it's back again before - L: - for { - select { - case <-stop: + case <-ticker.C: + result, err := container.Inspect() + if err != nil { + // if we get an error, then the container has probably been removed so we'll get out of here + gui.Log.Error(err) + notifyStopped <- struct{}{} + return + } + if result.State.Running { return - default: - result, err := container.Inspect() - if err != nil { - // if we get an error, then the container has probably been removed so we'll get out of here - gui.Log.Error(err) - notifyStopped <- struct{}{} - return - } - if result.State.Running { - break L - } - time.Sleep(time.Millisecond * 100) } } - }) + } } func (gui *Gui) refreshContainersAndServices() error { From 52fb944bfb345eceb236d55b45b0882984617134 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 26 Nov 2021 21:26:24 +1100 Subject: [PATCH 8/8] refactor --- pkg/gui/containers_panel.go | 5 +++++ pkg/gui/services_panel.go | 16 +--------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 25fb6770..7a0c8639 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -593,6 +593,11 @@ func (gui *Gui) handleContainersOpenInBrowserCommand(g *gocui.Gui, v *gocui.View if err != nil { return nil } + + return gui.openContainerInBrowser(container) +} + +func (gui *Gui) openContainerInBrowser(container *commands.Container) error { // skip if no any ports if len(container.Container.Ports) == 0 { return nil diff --git a/pkg/gui/services_panel.go b/pkg/gui/services_panel.go index 8ce15913..fd2bdd45 100644 --- a/pkg/gui/services_panel.go +++ b/pkg/gui/services_panel.go @@ -421,19 +421,5 @@ func (gui *Gui) handleServicesOpenInBrowserCommand(g *gocui.Gui, v *gocui.View) return gui.createErrorPanel(gui.g, gui.Tr.NoContainers) } - // skip if no any ports - if len(container.Container.Ports) == 0 { - return nil - } - // skip if the first port is not published - port := container.Container.Ports[0] - if port.IP == "" { - return nil - } - ip := port.IP - if ip == "0.0.0.0" { - ip = "localhost" - } - link := fmt.Sprintf("http://%s:%d/", ip, port.PublicPort) - return gui.OSCommand.OpenLink(link) + return gui.openContainerInBrowser(container) }