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

Support sshkit.default_env #1279

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 additions & 0 deletions lib/kamal/configuration/validator/sshkit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Kamal::Configuration::Validator::Sshkit < Kamal::Configuration::Validator
def validate!
validate_against_example! \
config.except("default_env"),
example.except("default_env")

if config["default_env"]
validate_hash_of!(config["default_env"], String)
end
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