mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
Merge pull request #313 from jesseduffield/fix-goreleaser
This commit is contained in:
commit
bba2feac94
4 changed files with 44 additions and 48 deletions
|
|
@ -60,20 +60,6 @@ jobs:
|
||||||
- image: circleci/golang:1.17
|
- image: circleci/golang:1.17
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
#- run:
|
|
||||||
# name: Install snapcraft
|
|
||||||
# command: |
|
|
||||||
# ./.circleci/install_snapcraft.sh
|
|
||||||
#- run:
|
|
||||||
# name: Login to snapcraft
|
|
||||||
# # if you ever lose this, you can recreate it via
|
|
||||||
# # `snapcraft export-login snapcraft.login && base64 snapcraft.login` and then chuck that
|
|
||||||
# # in circle ci as the SNAPCRAFT_LOGIN_FILE env variable
|
|
||||||
# # You'll need your ubuntu one password
|
|
||||||
# command: |
|
|
||||||
# echo $SNAPCRAFT_LOGIN_FILE | base64 --decode --ignore-garbage > snapcraft.login
|
|
||||||
# snapcraft login --with snapcraft.login
|
|
||||||
# rm snapcraft.login
|
|
||||||
- run:
|
- run:
|
||||||
name: Run gorelease
|
name: Run gorelease
|
||||||
command: |
|
command: |
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject {
|
||||||
|
|
||||||
// NewDockerCommand it runs docker commands
|
// NewDockerCommand it runs docker commands
|
||||||
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) {
|
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) {
|
||||||
tunnelCloser, err := ssh.NewSSHHandler().HandleSSHDockerHost()
|
tunnelCloser, err := ssh.NewSSHHandler(osCommand).HandleSSHDockerHost()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ogLog.Fatal(err)
|
ogLog.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -237,7 +237,7 @@ func (c *DockerCommand) RefreshContainersAndServices() error {
|
||||||
|
|
||||||
c.assignContainersToServices(containers, services)
|
c.assignContainersToServices(containers, services)
|
||||||
|
|
||||||
var displayContainers = containers
|
displayContainers := containers
|
||||||
if !c.Config.UserConfig.Gui.ShowAllContainers {
|
if !c.Config.UserConfig.Gui.ShowAllContainers {
|
||||||
displayContainers = c.obtainStandaloneContainers(containers, services)
|
displayContainers = c.obtainStandaloneContainers(containers, services)
|
||||||
}
|
}
|
||||||
|
|
@ -468,7 +468,6 @@ func (c *DockerCommand) DockerComposeConfig() string {
|
||||||
c.NewCommandObject(CommandObject{}),
|
c.NewCommandObject(CommandObject{}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
output = err.Error()
|
output = err.Error()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,18 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type dependencies struct {
|
// we only need these two methods from our OSCommand struct, for killing commands
|
||||||
// storing all these dependencies as fields for the sake of testing
|
type CmdKiller interface {
|
||||||
|
Kill(cmd *exec.Cmd) error
|
||||||
|
PrepareForChildren(cmd *exec.Cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
type SSHHandler struct {
|
||||||
|
oSCommand CmdKiller
|
||||||
|
|
||||||
dialContext func(ctx context.Context, network, addr string) (io.Closer, error)
|
dialContext func(ctx context.Context, network, addr string) (io.Closer, error)
|
||||||
startCmd func(*exec.Cmd) error
|
startCmd func(*exec.Cmd) error
|
||||||
tempDir func(dir string, pattern string) (name string, err error)
|
tempDir func(dir string, pattern string) (name string, err error)
|
||||||
|
|
@ -23,21 +29,17 @@ type dependencies struct {
|
||||||
setenv func(key, value string) error
|
setenv func(key, value string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type SSHHandler struct {
|
func NewSSHHandler(oSCommand CmdKiller) *SSHHandler {
|
||||||
deps dependencies
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSSHHandler() *SSHHandler {
|
|
||||||
return &SSHHandler{
|
return &SSHHandler{
|
||||||
deps: dependencies{
|
oSCommand: oSCommand,
|
||||||
dialContext: func(ctx context.Context, network, addr string) (io.Closer, error) {
|
|
||||||
return (&net.Dialer{}).DialContext(ctx, network, addr)
|
dialContext: func(ctx context.Context, network, addr string) (io.Closer, error) {
|
||||||
},
|
return (&net.Dialer{}).DialContext(ctx, network, addr)
|
||||||
startCmd: func(cmd *exec.Cmd) error { return cmd.Start() },
|
|
||||||
tempDir: ioutil.TempDir,
|
|
||||||
getenv: os.Getenv,
|
|
||||||
setenv: os.Setenv,
|
|
||||||
},
|
},
|
||||||
|
startCmd: func(cmd *exec.Cmd) error { return cmd.Start() },
|
||||||
|
tempDir: ioutil.TempDir,
|
||||||
|
getenv: os.Getenv,
|
||||||
|
setenv: os.Setenv,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +48,7 @@ func NewSSHHandler() *SSHHandler {
|
||||||
func (self *SSHHandler) HandleSSHDockerHost() (io.Closer, error) {
|
func (self *SSHHandler) HandleSSHDockerHost() (io.Closer, error) {
|
||||||
const key = "DOCKER_HOST"
|
const key = "DOCKER_HOST"
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
u, err := url.Parse(self.deps.getenv(key))
|
u, err := url.Parse(self.getenv(key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// if no or an invalid docker host is specified, continue nominally
|
// if no or an invalid docker host is specified, continue nominally
|
||||||
return noopCloser{}, nil
|
return noopCloser{}, nil
|
||||||
|
|
@ -58,7 +60,7 @@ func (self *SSHHandler) HandleSSHDockerHost() (io.Closer, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return noopCloser{}, fmt.Errorf("tunnel ssh docker host: %w", err)
|
return noopCloser{}, fmt.Errorf("tunnel ssh docker host: %w", err)
|
||||||
}
|
}
|
||||||
err = self.deps.setenv(key, tunnel.socketPath)
|
err = self.setenv(key, tunnel.socketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return noopCloser{}, fmt.Errorf("override DOCKER_HOST to tunneled socket: %w", err)
|
return noopCloser{}, fmt.Errorf("override DOCKER_HOST to tunneled socket: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -75,16 +77,17 @@ func (noopCloser) Close() error { return nil }
|
||||||
type tunneledDockerHost struct {
|
type tunneledDockerHost struct {
|
||||||
socketPath string
|
socketPath string
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
|
oSCommand CmdKiller
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ io.Closer = (*tunneledDockerHost)(nil)
|
var _ io.Closer = (*tunneledDockerHost)(nil)
|
||||||
|
|
||||||
func (t *tunneledDockerHost) Close() error {
|
func (t *tunneledDockerHost) Close() error {
|
||||||
return syscall.Kill(-t.cmd.Process.Pid, syscall.SIGKILL)
|
return t.oSCommand.Kill(t.cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SSHHandler) createDockerHostTunnel(ctx context.Context, remoteHost string) (*tunneledDockerHost, error) {
|
func (self *SSHHandler) createDockerHostTunnel(ctx context.Context, remoteHost string) (*tunneledDockerHost, error) {
|
||||||
socketDir, err := self.deps.tempDir("/tmp", "lazydocker-sshtunnel-")
|
socketDir, err := self.tempDir("/tmp", "lazydocker-sshtunnel-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("create ssh tunnel tmp file: %w", err)
|
return nil, fmt.Errorf("create ssh tunnel tmp file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +114,7 @@ func (self *SSHHandler) createDockerHostTunnel(ctx context.Context, remoteHost s
|
||||||
return &tunneledDockerHost{
|
return &tunneledDockerHost{
|
||||||
socketPath: newDockerHostURL.String(),
|
socketPath: newDockerHostURL.String(),
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
|
oSCommand: self.oSCommand,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,7 +141,7 @@ func (self *SSHHandler) retrySocketDial(ctx context.Context, socketPath string)
|
||||||
|
|
||||||
// Try to dial the specified unix socket, immediately close the connection if successfully created.
|
// Try to dial the specified unix socket, immediately close the connection if successfully created.
|
||||||
func (self *SSHHandler) tryDial(ctx context.Context, socketPath string) error {
|
func (self *SSHHandler) tryDial(ctx context.Context, socketPath string) error {
|
||||||
conn, err := self.deps.dialContext(ctx, "unix", socketPath)
|
conn, err := self.dialContext(ctx, "unix", socketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -147,8 +151,8 @@ func (self *SSHHandler) tryDial(ctx context.Context, socketPath string) error {
|
||||||
|
|
||||||
func (self *SSHHandler) tunnelSSH(ctx context.Context, host, localSocket string) (*exec.Cmd, error) {
|
func (self *SSHHandler) tunnelSSH(ctx context.Context, host, localSocket string) (*exec.Cmd, error) {
|
||||||
cmd := exec.CommandContext(ctx, "ssh", "-L", localSocket+":/var/run/docker.sock", host, "-N")
|
cmd := exec.CommandContext(ctx, "ssh", "-L", localSocket+":/var/run/docker.sock", host, "-N")
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
self.oSCommand.PrepareForChildren(cmd)
|
||||||
err := self.deps.startCmd(cmd)
|
err := self.startCmd(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,6 @@ func TestSSHHandlerHandleSSHDockerHost(t *testing.T) {
|
||||||
startCmdCount := 0
|
startCmdCount := 0
|
||||||
startCmd := func(cmd *exec.Cmd) error {
|
startCmd := func(cmd *exec.Cmd) error {
|
||||||
assert.EqualValues(t, []string{"ssh", "-L", "/tmp/lazydocker-ssh-tunnel-12345/dockerhost.sock:/var/run/docker.sock", "192.168.5.178", "-N"}, cmd.Args)
|
assert.EqualValues(t, []string{"ssh", "-L", "/tmp/lazydocker-ssh-tunnel-12345/dockerhost.sock:/var/run/docker.sock", "192.168.5.178", "-N"}, cmd.Args)
|
||||||
assert.Equal(t, true, cmd.SysProcAttr.Setpgid)
|
|
||||||
|
|
||||||
startCmdCount++
|
startCmdCount++
|
||||||
|
|
||||||
|
|
@ -83,13 +82,13 @@ func TestSSHHandlerHandleSSHDockerHost(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
handler := &SSHHandler{
|
handler := &SSHHandler{
|
||||||
deps: dependencies{
|
oSCommand: &fakeCmdKiller{},
|
||||||
dialContext: dialContext,
|
|
||||||
startCmd: startCmd,
|
dialContext: dialContext,
|
||||||
tempDir: tempDir,
|
startCmd: startCmd,
|
||||||
getenv: getenv,
|
tempDir: tempDir,
|
||||||
setenv: setenv,
|
getenv: getenv,
|
||||||
},
|
setenv: setenv,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := handler.HandleSSHDockerHost()
|
_, err := handler.HandleSSHDockerHost()
|
||||||
|
|
@ -100,3 +99,11 @@ func TestSSHHandlerHandleSSHDockerHost(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type fakeCmdKiller struct{}
|
||||||
|
|
||||||
|
func (self *fakeCmdKiller) Kill(cmd *exec.Cmd) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *fakeCmdKiller) PrepareForChildren(cmd *exec.Cmd) {}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue