Skip to content

Commit

Permalink
Support sshkit.default_env
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
filipesilva committed Dec 9, 2024
1 parent 495b3cd commit 3b72e62
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/kamal/commander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def configure_sshkit_with(config)
end
SSHKit.config.command_map[:docker] = "docker" # No need to use /usr/bin/env, just clogs up the logs
SSHKit.config.output_verbosity = verbosity
SSHKit.config.default_env = config.sshkit.default_env
end

def specifics
Expand Down
7 changes: 7 additions & 0 deletions lib/kamal/configuration/docs/sshkit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ sshkit:
# Kamal sets a long idle timeout of 900 seconds on connections to try to avoid
# re-connection storms after an idle period, such as building an image or waiting for CI.
pool_idle_timeout: 300

# Default Env
#
# SSHKit sessions do not inherit the host PATH value. If you need to set custom env vars on
# a SSHKit session, like PATH or DOCKER_DEFAULT_PLATFORM you can map them here.
default_env:
path: /usr/local/bin:$PATH"
6 changes: 5 additions & 1 deletion lib/kamal/configuration/sshkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Kamal::Configuration::Sshkit

def initialize(config:)
@sshkit_config = config.raw_config.sshkit || {}
validate! sshkit_config
validate! sshkit_config, with: Kamal::Configuration::Validator::Sshkit
end

def max_concurrent_starts
Expand All @@ -16,6 +16,10 @@ def pool_idle_timeout
sshkit_config.fetch("pool_idle_timeout", 900)
end

def default_env
sshkit_config.fetch("default_env", {}).transform_keys(&:to_sym)
end

def to_h
sshkit_config
end
Expand Down
9 changes: 9 additions & 0 deletions lib/kamal/configuration/validator/sshkit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Kamal::Configuration::Validator::Sshkit < Kamal::Configuration::Validator
def validate!
validate_against_example! \
config.except("default_env"),
example.except("default_env")

validate_hash_of!(config["default_env"], String)
end
end
6 changes: 6 additions & 0 deletions test/configuration/sshkit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ class ConfigurationSshkitTest < ActiveSupport::TestCase
@config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "pool_idle_timeout" => 600 }) })
assert_equal 600, @config.sshkit.pool_idle_timeout
end

test "sshkit default env" do
assert_equal {}, @config.sshkit.default_env
@config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "default_env" => {"path" => "/usr/local/bin:$PATH" } }) })
assert_equal {path: "/usr/local/bin:$PATH" }, @config.sshkit.default_env
end
end

0 comments on commit 3b72e62

Please sign in to comment.