diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index 48c6cd3aa..afd13b7f3 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -250,12 +250,14 @@ def role_names raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort end + # git version will be part of container hostname, DNS has a limit of 63 characters + # so, make this a bit shorter, see: https://en.wikipedia.org/wiki/Subdomain#Overview def git_version @git_version ||= if system("git rev-parse") - uncommitted_suffix = Mrsk::Utils.uncommitted_changes.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : "" + uncommitted_suffix = Mrsk::Utils.uncommitted_changes.present? ? "_#{SecureRandom.hex(2)}" : "" - "#{`git rev-parse HEAD`.strip}#{uncommitted_suffix}" + "#{`git rev-parse --short HEAD`.strip}#{uncommitted_suffix}" else raise "Can't use commit hash as version, no git repository found in #{Dir.pwd}" end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index d58fd6564..7511d22fb 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -83,7 +83,7 @@ class ConfigurationTest < ActiveSupport::TestCase test "version from git committed" do ENV.delete("VERSION") - @config.expects(:`).with("git rev-parse HEAD").returns("git-version") + @config.expects(:`).with("git rev-parse --short HEAD").returns("git-version") Mrsk::Utils.expects(:uncommitted_changes).returns("") assert_equal "git-version", @config.version end @@ -91,9 +91,9 @@ class ConfigurationTest < ActiveSupport::TestCase test "version from git uncommitted" do ENV.delete("VERSION") - @config.expects(:`).with("git rev-parse HEAD").returns("git-version") + @config.expects(:`).with("git rev-parse --short HEAD").returns("git-version") Mrsk::Utils.expects(:uncommitted_changes).returns("M file\n") - assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, @config.version + assert_match /^git-version_[0-9a-f]{4}$/, @config.version end test "version from env" do