From c690387ae2b5bcf68ef7e27f96763f26cd46914b Mon Sep 17 00:00:00 2001 From: Gerhard Lazu Date: Mon, 22 Nov 2021 07:12:47 +0000 Subject: [PATCH 1/4] Add support for tcp:// DOCKER_HOST The Docker daemon that I am using is running remotely, and I connect to it via Tailscale tunnel, which means that my DOCKER_HOST is set to tcp://100.113.182.91:2375 This change makes Dagger work with my setup. It's been running well for me for a few weeks now, this started as https://github.com/thechangelog/changelog.com/pull/395 I think there is an opportunity to add support for ssh:// & file://, but I am keeping this first addition small on purpose. Signed-off-by: Gerhard Lazu Signed-off-by: Sam Alba --- stdlib/docker/command.cue | 7 +++++++ stdlib/docker/docker.cue | 14 +++++++++++++ stdlib/docker/tests/command-host/command.cue | 17 +++++++++++++++ stdlib/docker/tests/run-host/simple.cue | 22 ++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 stdlib/docker/tests/command-host/command.cue create mode 100644 stdlib/docker/tests/run-host/simple.cue diff --git a/stdlib/docker/command.cue b/stdlib/docker/command.cue index 2ad6b6c7..76d7e7fc 100644 --- a/stdlib/docker/command.cue +++ b/stdlib/docker/command.cue @@ -30,6 +30,10 @@ import ( keyPassphrase?: dagger.#Secret @dagger(input) } + // Connect via DOCKER_HOST, supports tcp:// + // TODO: Consider refactoring to support ssh:// & even file:// + host?: string @dagger(input) + // Command to execute command: string @@ -203,6 +207,9 @@ import ( FINGERPRINT: ssh.fingerprint } } + if host != _|_ && ssh == _|_ { + DOCKER_HOST: host + } } "mount": { if ssh != _|_ { diff --git a/stdlib/docker/docker.cue b/stdlib/docker/docker.cue index 3fb7637c..36021d31 100644 --- a/stdlib/docker/docker.cue +++ b/stdlib/docker/docker.cue @@ -124,6 +124,10 @@ import ( keyPassphrase?: dagger.#Input & {dagger.#Secret} } + // Connect via DOCKER_HOST, supports tcp:// + // TODO: Consider refactoring to support ssh:// & even file:// + host?: string @dagger(input) + // Mount local docker socket socket?: dagger.#Stream & dagger.#Input @@ -146,6 +150,9 @@ import ( if ssh != _|_ { "ssh": ssh } + if host != _|_ && ssh == _|_ { + "host": host + } if socket != _|_ { "socket": socket } @@ -194,6 +201,10 @@ import ( keyPassphrase?: dagger.#Input & {dagger.#Secret} } + // Connect via DOCKER_HOST, supports tcp:// + // TODO: Consider refactoring to support ssh:// & even file:// + host?: string @dagger(input) + // Mount local docker socket socket?: dagger.#Stream & dagger.#Input @@ -246,6 +257,9 @@ import ( if ssh != _|_ { "ssh": ssh } + if host != _|_ && ssh == _|_ { + "host": host + } if socket != _|_ { "socket": socket } diff --git a/stdlib/docker/tests/command-host/command.cue b/stdlib/docker/tests/command-host/command.cue new file mode 100644 index 00000000..a673a0ff --- /dev/null +++ b/stdlib/docker/tests/command-host/command.cue @@ -0,0 +1,17 @@ +package docker + +import ( + "alpha.dagger.io/dagger" +) + +TestConfig: { + host: string @dagger(input) +} + +TestHost: client: #Command & { + command: #""" + docker $CMD + """# + host: TestConfig.host + env: CMD: "version" +} diff --git a/stdlib/docker/tests/run-host/simple.cue b/stdlib/docker/tests/run-host/simple.cue new file mode 100644 index 00000000..ad9e4294 --- /dev/null +++ b/stdlib/docker/tests/run-host/simple.cue @@ -0,0 +1,22 @@ +package docker + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/random" +) + +TestConfig: { + host: string @dagger(input) +} + +TestHost: { + suffix: random.#String & { + seed: "" + } + + run: #Run & { + name: "daggerci-test-ssh-\(suffix.out)" + ref: "hello-world" + host: TestConfig.host + } +} From 8ce5b3447f04e0aa1e84e39bbfe3e8c38772663b Mon Sep 17 00:00:00 2001 From: Gerhard Lazu Date: Mon, 22 Nov 2021 08:02:28 +0000 Subject: [PATCH 2/4] Fix unused imports Signed-off-by: Gerhard Lazu Signed-off-by: Sam Alba --- stdlib/docker/tests/command-host/command.cue | 4 ---- stdlib/docker/tests/run-host/simple.cue | 1 - 2 files changed, 5 deletions(-) diff --git a/stdlib/docker/tests/command-host/command.cue b/stdlib/docker/tests/command-host/command.cue index a673a0ff..043eb44c 100644 --- a/stdlib/docker/tests/command-host/command.cue +++ b/stdlib/docker/tests/command-host/command.cue @@ -1,9 +1,5 @@ package docker -import ( - "alpha.dagger.io/dagger" -) - TestConfig: { host: string @dagger(input) } diff --git a/stdlib/docker/tests/run-host/simple.cue b/stdlib/docker/tests/run-host/simple.cue index ad9e4294..98dc7add 100644 --- a/stdlib/docker/tests/run-host/simple.cue +++ b/stdlib/docker/tests/run-host/simple.cue @@ -1,7 +1,6 @@ package docker import ( - "alpha.dagger.io/dagger" "alpha.dagger.io/random" ) From 18c387a407254b2fff59131989ec742f1efc092f Mon Sep 17 00:00:00 2001 From: Gerhard Lazu Date: Fri, 26 Nov 2021 18:05:03 +0000 Subject: [PATCH 3/4] Use tcp in the docker host test Co-authored-by: Vasek - Tom C. Signed-off-by: Gerhard Lazu Signed-off-by: Sam Alba --- stdlib/docker/tests/run-host/simple.cue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/docker/tests/run-host/simple.cue b/stdlib/docker/tests/run-host/simple.cue index 98dc7add..89dea796 100644 --- a/stdlib/docker/tests/run-host/simple.cue +++ b/stdlib/docker/tests/run-host/simple.cue @@ -14,7 +14,7 @@ TestHost: { } run: #Run & { - name: "daggerci-test-ssh-\(suffix.out)" + name: "daggerci-test-tcp-\(suffix.out)" ref: "hello-world" host: TestConfig.host } From 95c1b07f3aeb3ee2ce945ee68197b0940f2f56f3 Mon Sep 17 00:00:00 2001 From: Gerhard Lazu Date: Fri, 26 Nov 2021 18:05:19 +0000 Subject: [PATCH 4/4] Use tcp-specific seed. Co-authored-by: Vasek - Tom C. Signed-off-by: Gerhard Lazu Signed-off-by: Sam Alba --- stdlib/docker/tests/run-host/simple.cue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/docker/tests/run-host/simple.cue b/stdlib/docker/tests/run-host/simple.cue index 89dea796..17a15f43 100644 --- a/stdlib/docker/tests/run-host/simple.cue +++ b/stdlib/docker/tests/run-host/simple.cue @@ -10,7 +10,7 @@ TestConfig: { TestHost: { suffix: random.#String & { - seed: "" + seed: "docker-tcp-test" } run: #Run & {