Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/connhelper: support overriding the docker binary over SSH #5627

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mattmacleod
Copy link

This change adds the ability to override the docker binary used when executing commands over SSH. This is useful when the docker binary is not in the PATH of the SSH user, or when the binary is not named docker.

If DOCKER_SSH_REMOTE_BINARY is set in the environment, the value will be used as the docker binary when executing commands over SSH. If the environment variable is not set, the default value of docker will be used.

Closes #5626

- Description for the changelog

Support the `DOCKER_SSH_REMOTE_BINARY` environment variable for overriding the `docker` binary used on remote SSH hosts.

- A picture of a cute animal (not mandatory but encouraged)

IMG_1013

@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 59.51%. Comparing base (9861ce9) to head (1fdc2b8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5627   +/-   ##
=======================================
  Coverage   59.50%   59.51%           
=======================================
  Files         346      346           
  Lines       29365    29371    +6     
=======================================
+ Hits        17474    17480    +6     
  Misses      10916    10916           
  Partials      975      975           

@@ -49,7 +56,7 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*ConnectionHelper
sshFlags = disablePseudoTerminalAllocation(sshFlags)
return &ConnectionHelper{
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
args := []string{"docker"}
args := []string{dockerSSHRemoteBinary()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this inside of the Dialer means that it'll possibly get evaluated multiple times during a single CLI invocation – so, if something unexpected happens causing the environment variable to get unset while the process is running and Dialer gets called again a different value would get returned.

I think it'd be safer to move this evaluation up to L56 to make sure it only happens once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like

remoteDockerBinary := dockerSSHRemoteBinary()
return &ConnectionHelper{
			Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
				args := []string{remoteDockerBinary}
...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point – thanks @laurazard! I've updated as suggested.

@mattmacleod mattmacleod force-pushed the 5626-allow-binary-override-over-ssh branch from f5737e8 to 82352ff Compare November 18, 2024 15:27
This change adds the ability to override the docker binary used when executing
commands over SSH. This is useful when the docker binary is not in the PATH of
the SSH user, or when the binary is not named `docker`.

If `DOCKER_SSH_REMOTE_BINARY` is set in the environment, the value will be used
as the docker binary when executing commands over SSH. If the environment
variable is not set, the default value of `docker` will be used.

Signed-off-by: Matthew MacLeod <matt@umm.io>
Signed-off-by: Matthew MacLeod <matt@umm.io>
@mattmacleod mattmacleod force-pushed the 5626-allow-binary-override-over-ssh branch from 82352ff to 43dd6ea Compare November 18, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove hardcoded docker CLI command name for SSH hosts
3 participants