Skip to content

Commit 561e33e

Browse files
committed
Support sshkit.default_env
Enables deploy to MacOS hosts. Will still need further configuration though: - `default_env` needs to be set to a PATH that contains docker and coreutils `cp` - desktop docker config needs to have no `credsStore` - shell needs to be changed to `bash` All this can be done by the user though, whereas passing on `default_env` to SSHKit needed to happen on Kamal. cc @dhh, @HLFH See #432 (comment) for details.
1 parent 495b3cd commit 561e33e

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

lib/kamal/commander.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def configure_sshkit_with(config)
168168
end
169169
SSHKit.config.command_map[:docker] = "docker" # No need to use /usr/bin/env, just clogs up the logs
170170
SSHKit.config.output_verbosity = verbosity
171+
SSHKit.config.default_env = config.sshkit.default_env
171172
end
172173

173174
def specifics

lib/kamal/configuration/docs/sshkit.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ sshkit:
2121
# Kamal sets a long idle timeout of 900 seconds on connections to try to avoid
2222
# re-connection storms after an idle period, such as building an image or waiting for CI.
2323
pool_idle_timeout: 300
24+
25+
# Default Env
26+
#
27+
# SSHKit sessions do not inherit the host PATH value. If you need to set custom env vars on
28+
# a SSHKit session, like PATH or DOCKER_DEFAULT_PLATFORM you can map them here.
29+
default_env:
30+
path: /usr/local/bin:$PATH"

lib/kamal/configuration/sshkit.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Kamal::Configuration::Sshkit
55

66
def initialize(config:)
77
@sshkit_config = config.raw_config.sshkit || {}
8-
validate! sshkit_config
8+
validate! sshkit_config, with: Kamal::Configuration::Validator::Sshkit
99
end
1010

1111
def max_concurrent_starts
@@ -16,6 +16,10 @@ def pool_idle_timeout
1616
sshkit_config.fetch("pool_idle_timeout", 900)
1717
end
1818

19+
def default_env
20+
sshkit_config.fetch("default_env", {}).transform_keys(&:to_sym)
21+
end
22+
1923
def to_h
2024
sshkit_config
2125
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Kamal::Configuration::Validator::Sshkit < Kamal::Configuration::Validator
2+
def validate!
3+
validate_against_example! \
4+
config.except("default_env"),
5+
example.except("default_env")
6+
7+
if config["default_env"]
8+
validate_hash_of!(config["default_env"], String)
9+
end
10+
end
11+
end

test/configuration/sshkit_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ class ConfigurationSshkitTest < ActiveSupport::TestCase
2525
@config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "pool_idle_timeout" => 600 }) })
2626
assert_equal 600, @config.sshkit.pool_idle_timeout
2727
end
28+
29+
test "sshkit default env" do
30+
assert_equal({}, @config.sshkit.default_env)
31+
@config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "default_env" => {"path" => "/usr/local/bin:$PATH" } }) })
32+
assert_equal({path: "/usr/local/bin:$PATH" }, @config.sshkit.default_env)
33+
end
2834
end

0 commit comments

Comments
 (0)