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

Add option to set an absolute directory path #507

Merged
merged 1 commit into from
Nov 28, 2023
Merged
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
16 changes: 10 additions & 6 deletions lib/kamal/configuration/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def files

def directories
specifics["directories"]&.to_h do |host_to_container_mapping|
host_relative_path, container_path = host_to_container_mapping.split(":")
[ expand_host_path(host_relative_path), container_path ]
host_path, container_path = host_to_container_mapping.split(":")
[ expand_host_path(host_path), container_path ]
end || {}
end

Expand Down Expand Up @@ -138,13 +138,17 @@ def remote_files_as_volumes

def remote_directories_as_volumes
specifics["directories"]&.collect do |host_to_container_mapping|
host_relative_path, container_path = host_to_container_mapping.split(":")
[ expand_host_path(host_relative_path), container_path ].join(":")
host_path, container_path = host_to_container_mapping.split(":")
[ expand_host_path(host_path), container_path ].join(":")
end || []
end

def expand_host_path(host_relative_path)
"#{service_data_directory}/#{host_relative_path}"
def expand_host_path(host_path)
absolute_path?(host_path) ? host_path : "#{service_data_directory}/#{host_path}"
end

def absolute_path?(path)
Pathname.new(path).absolute?
end

def service_data_directory
Expand Down
8 changes: 7 additions & 1 deletion test/configuration/accessory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,16 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
assert_match "%", @config.accessory(:mysql).files.keys[2].read
end

test "directories" do
test "directory with a relative path" do
@deploy[:accessories]["mysql"]["directories"] = [ "data:/var/lib/mysql" ]
assert_equal({"$PWD/app-mysql/data"=>"/var/lib/mysql"}, @config.accessory(:mysql).directories)
end

test "directory with an absolute path" do
@deploy[:accessories]["mysql"]["directories"] = [ "/var/data/mysql:/var/lib/mysql" ]
assert_equal({"/var/data/mysql"=>"/var/lib/mysql"}, @config.accessory(:mysql).directories)
end

test "options" do
assert_equal ["--cpus", "\"4\"", "--memory", "\"2GB\""], @config.accessory(:redis).option_args
end
Expand Down
Loading