Skip to content

Commit

Permalink
Add a minimum version setting
Browse files Browse the repository at this point in the history
Allow a minimum MRSK version to be specified in the config.
  • Loading branch information
djmb committed Jun 15, 2023
1 parent f0301d2 commit 98c12a2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,16 @@ servers:

That'll start the job containers with `docker run ... --cap-add --cpu-count 4 ...`.

### Setting a minimum version

You can set the minimum MRSK version with:

```yaml
minimum_version: 0.13.3
```

Note: versions <= 0.13.2 will ignore this setting.

### Configuring logging

You can configure the logging driver and options passed to Docker using `logging`:
Expand Down
15 changes: 14 additions & 1 deletion lib/mrsk/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ def readiness_delay
raw_config.readiness_delay || 7
end

def minimum_version
raw_config.minimum_version
end

def valid?
ensure_required_keys_present && ensure_env_available
ensure_required_keys_present && ensure_env_available && ensure_valid_mrsk_version
end


Expand Down Expand Up @@ -229,6 +233,15 @@ def ensure_env_available
true
end

def ensure_valid_mrsk_version
if minimum_version && Gem::Version.new(minimum_version) > Gem::Version.new(Mrsk::VERSION)
raise ArgumentError, "Current version is #{Mrsk::VERSION}, minimum required is #{minimum_version}"
end

true
end


def role_names
raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort
end
Expand Down
16 changes: 16 additions & 0 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,20 @@ class ConfigurationTest < ActiveSupport::TestCase
test "to_h" do
assert_equal({ :roles=>["web"], :hosts=>["1.1.1.1", "1.1.1.2"], :primary_host=>"1.1.1.1", :version=>"missing", :repository=>"dhh/app", :absolute_image=>"dhh/app:missing", :service_with_version=>"app-missing", :env_args=>["-e", "REDIS_URL=\"redis://x/y\""], :ssh_options=>{:user=>"root", :auth_methods=>["publickey"]}, :volume_args=>["--volume", "/local/path:/container/path"], :logging=>["--log-opt", "max-size=\"10m\""], :healthcheck=>{"path"=>"/up", "port"=>3000, "max_attempts" => 7 }}, @config.to_h)
end

test "min version is lower" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: "0.0.1") })
assert_equal "0.0.1", config.minimum_version
end

test "min version is equal" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: Mrsk::VERSION) })
assert_equal Mrsk::VERSION, config.minimum_version
end

test "min version is higher" do
assert_raises(ArgumentError) do
Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: "10000.0.0") })
end
end
end

0 comments on commit 98c12a2

Please sign in to comment.