Skip to content

Commit e134199

Browse files
committed
Nested image in container for support override docker env
1 parent 53ae9c3 commit e134199

File tree

9 files changed

+46
-23
lines changed

9 files changed

+46
-23
lines changed

lib/matrixeval/ruby/container.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Matrixeval
2+
module Ruby
3+
class Container
4+
5+
attr_reader :image, :env
6+
7+
def initialize(options)
8+
options ||= {}
9+
@image = options["image"]
10+
@env = options["env"] || {}
11+
end
12+
13+
end
14+
end
15+
end

lib/matrixeval/ruby/docker_compose/yaml.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ def services_json
2929

3030
Config.main_vector_variants.map do |variant|
3131
services[variant.docker_compose_service_name] = {
32-
"image" => variant.image,
32+
"image" => variant.container.image,
3333
"volumes" => mounts(variant),
3434
"environment" => {
3535
"BUNDLE_PATH" => "/bundle",
3636
"GEM_HOME" => "/bundle",
3737
"BUNDLE_APP_CONFIG" => "/bundle",
3838
"BUNDLE_BIN" => "/bundle/bin",
3939
"PATH" => "/app/bin:/bundle/bin:$PATH"
40-
},
40+
}.merge(variant.container.env),
4141
"working_dir" => "/app"
4242
}
4343
end

lib/matrixeval/ruby/templates/matrixeval.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ matrix:
55
ruby:
66
variants:
77
- key: 2.7
8-
image: ruby:2.7.1
8+
container:
9+
image: ruby:2.7.1
910
- key: 3.0
10-
image: ruby:3.0.0
1111
default: true
12+
container:
13+
image: ruby:3.0.0
1214
- key: 3.1
13-
image: ruby:3.1.0
15+
container:
16+
image: ruby:3.1.0

lib/matrixeval/ruby/variant.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative "./container"
2+
13
module Matrixeval
24
module Ruby
35
class Variant
@@ -7,14 +9,14 @@ def default(key, vector)
79
end
810
end
911

10-
attr_reader :key, :image, :env, :vector, :default
12+
attr_reader :key, :env, :vector, :default, :container
1113

1214
def initialize(config = {}, vector)
1315
raise Error.new("Variant#key is missing") if config["key"].nil?
1416

1517
@vector = vector
1618
@key = config["key"].to_s
17-
@image = config["image"]
19+
@container = Container.new(config["container"])
1820
@env = config["env"] || {}
1921
@default = config["default"] || false
2022
end
@@ -24,7 +26,7 @@ def name
2426
end
2527

2628
def bundle_volume_name
27-
"bundle_#{image.gsub(/[^A-Za-z0-9]/,'_')}"
29+
"bundle_#{container.image.gsub(/[^A-Za-z0-9]/,'_')}"
2830
end
2931

3032
def id

lib/matrixeval/ruby/vector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def id
3030
def default_variant
3131
variant = variants.find(&:default?)
3232
if variant.nil?
33-
raise Error.new("Please set a default variant for matrix #{vector.key}")
33+
raise Error.new("Please set a default variant for matrix #{key}")
3434
end
3535

3636
variant

test/matrixeval/ruby/command_line/parse_context_arguments_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ def setup
1111
"matrix" => {
1212
"ruby" => {
1313
"variants" => [
14-
{ "key" => "3.0" },
14+
{ "key" => "3.0", "default" => true },
1515
{ "key" => "3.1" }
1616
]
1717
},
1818
"active_model" => {
1919
"variants" => [
20-
{ "key" => "6.1" },
20+
{ "key" => "6.1", "default" => true },
2121
{ "key" => "7.0" }
2222
]
2323
}

test/matrixeval/ruby/docker_compose/yaml_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ def test_create
1818
"matrix" => {
1919
"ruby" => {
2020
"variants" => [
21-
{ "key" => "3.0", "image" => "ruby:3.0.0" },
22-
{ "key" => "3.1", "image" => "ruby:3.1.0" },
21+
{ "key" => "3.0", "container" => { "image" => "ruby:3.0.0" } },
22+
{ "key" => "3.1", "container" => { "image" => "ruby:3.1.0" } }
2323
]
2424
},
2525
"active_model" => {
2626
"variants" => [
2727
{ "key" => "6.1", "env" => { "ACTIVE_MODEL_VERSION" => "6.1.4" } },
28-
{ "key" => "7.0", "env" => { "ACTIVE_MODEL_VERSION" => "7.0.0" } },
28+
{ "key" => "7.0", "env" => { "ACTIVE_MODEL_VERSION" => "7.0.0" } }
2929
]
3030
}
3131
}

test/matrixeval/ruby/runner_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ def test_start_with_existing_config_file
4747
ruby:
4848
variants:
4949
- key: 3.0
50-
image: ruby:3.0.0
50+
container:
51+
image: ruby:3.0.0
5152
default: true
5253
- key: 3.1
53-
image: ruby:3.1.0
54+
container:
55+
image: ruby:3.1.0
5456
rails:
5557
variants:
5658
- key: 6.0

test/matrixeval/ruby/variant_test.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ def test_key_missing
1919
end
2020
end
2121

22-
def test_image
23-
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "image" => "ruby:3.1.0"}, @vector)
24-
assert_equal "3.1", variant.key
22+
def test_container
23+
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "container" => { "image" => "ruby:3.1.0"} }, @vector)
24+
assert variant.container.is_a?(Matrixeval::Ruby::Container)
25+
assert_equal "ruby:3.1.0", variant.container.image
2526
end
2627

2728
def test_env
@@ -35,22 +36,22 @@ def test_vector
3536
end
3637

3738
def test_bundle_volume_name
38-
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "image" => "ruby:3.1.0"}, @vector)
39+
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "container" => { "image" => "ruby:3.1.0"} }, @vector)
3940
assert_equal "bundle_ruby_3_1_0", variant.bundle_volume_name
4041
end
4142

4243
def test_id
43-
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "image" => "ruby:3.1.0"}, @vector)
44+
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "container" => { "image" => "ruby:3.1.0"} }, @vector)
4445
assert_equal "ruby_3_1", variant.id
4546
end
4647

4748
def test_docker_compose_service_name
48-
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "image" => "ruby:3.1.0"}, @vector)
49+
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "container" => { "image" => "ruby:3.1.0"} }, @vector)
4950
assert_equal "ruby_3_1", variant.docker_compose_service_name
5051
end
5152

5253
def test_pathname
53-
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "image" => "ruby:3.1.0"}, @vector)
54+
variant = Matrixeval::Ruby::Variant.new({"key" => 3.1, "container" => { "image" => "ruby:3.1.0"} }, @vector)
5455
assert_equal "ruby_3_1", variant.pathname
5556
end
5657

0 commit comments

Comments
 (0)