diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index f7f2233c0..5bf79ea6f 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -25,7 +25,9 @@ def load_config_files(*files) def load_config_file(file) if file.exist? - YAML.load(ERB.new(IO.read(file)).result).symbolize_keys + # Newer Psych doesn't load aliases by default + load_method = YAML.respond_to?(:unsafe_load) ? :unsafe_load : :load + YAML.send(load_method, ERB.new(IO.read(file)).result).symbolize_keys else raise "Configuration file not found in #{file}" end diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index 07e47f8de..58465c7b9 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -306,6 +306,19 @@ class CliMainTest < CliTestCase end end + test "config with aliases" do + run_command("config", config_file: "deploy_with_aliases").tap do |output| + config = YAML.load(output) + + assert_equal ["web", "web_tokyo", "workers", "workers_tokyo"], config[:roles] + assert_equal ["1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4"], config[:hosts] + assert_equal "999", config[:version] + assert_equal "registry.digitalocean.com/dhh/app", config[:repository] + assert_equal "registry.digitalocean.com/dhh/app:999", config[:absolute_image] + assert_equal "app-999", config[:service_with_version] + end + end + test "init" do Pathname.any_instance.expects(:exist?).returns(false).times(3) Pathname.any_instance.stubs(:mkpath) diff --git a/test/fixtures/deploy_with_aliases.yml b/test/fixtures/deploy_with_aliases.yml new file mode 100644 index 000000000..90c18b57c --- /dev/null +++ b/test/fixtures/deploy_with_aliases.yml @@ -0,0 +1,36 @@ +# helper aliases +chicago_hosts: &chicago_hosts + hosts: + - 1.1.1.1 + - 1.1.1.2 +tokyo_hosts: &tokyo_hosts + hosts: + - 1.1.1.3 + - 1.1.1.4 +web_common: &web_common + env: + ROLE: "web" + traefik: true + +# actual config +service: app +image: dhh/app +servers: + web: + <<: *chicago_hosts + <<: *web_common + web_tokyo: + <<: *tokyo_hosts + <<: *web_common + workers: + cmd: bin/jobs + <<: *chicago_hosts + workers_tokyo: + cmd: bin/jobs + <<: *tokyo_hosts +env: + REDIS_URL: redis://x/y +registry: + server: registry.digitalocean.com + username: user + password: pw