@@ -16,10 +16,13 @@ def start(argv)
1616 end
1717
1818 attr_reader :argv , :command
19+ attr_accessor :threads , :matrixeval_results
1920
2021 def initialize ( argv )
2122 @argv = argv
2223 @command = CommandLine . new ( argv )
24+ @threads ||= [ ]
25+ @matrixeval_results ||= [ ]
2326 end
2427
2528 def start
@@ -68,6 +71,8 @@ def run_all_contexts
6871 GemfileLocks . create
6972 Gitignore . update
7073
74+ pull_all_images
75+
7176 if workers_count == 1
7277 run_all_contexts_sequentially
7378 else
@@ -90,10 +95,10 @@ def run_all_contexts_sequentially
9095 end
9196
9297 def run_all_contexts_in_parallel
93- parallel do |contexts |
98+ parallel ( contexts ) do |sub_contexts |
9499 Thread . current [ :matrixeval_results ] = [ ]
95100
96- contexts . each do |context |
101+ sub_contexts . each do |context |
97102 docker_compose = DockerCompose . new ( context )
98103 success = docker_compose . run ( command . rest_arguments )
99104
@@ -119,6 +124,18 @@ def run_a_specific_context
119124 docker_compose . run ( command . rest_arguments )
120125 end
121126
127+ def pull_all_images
128+ parallel ( Config . main_vector_variants ) do |sub_variants |
129+ sub_variants . each do |variant |
130+ puts "Docker image check/pull #{ variant . container . image } "
131+ image_exists = system %Q{[ -n "$(docker images -q #{ variant . container . image } )" ]}
132+ next if image_exists
133+
134+ system "docker pull #{ variant . container . image } "
135+ end
136+ end
137+ end
138+
122139 def report
123140 turn_on_stty_opost
124141
@@ -142,33 +159,30 @@ def report
142159 puts table
143160 end
144161
145- def parallel
146- contexts = Context . all
162+ def parallel ( collection )
163+ threads = [ ]
164+ matrixeval_results = [ ]
147165
148- per_worker_contexts_count = [ ( contexts . count / workers_count ) , 1 ] . max
149- contexts . each_slice ( per_worker_contexts_count ) do |sub_contexts |
166+ collection . each_slice ( per_worker_contexts_count ) do |sub_collection |
150167 threads << Thread . new do
151- yield sub_contexts
168+ yield sub_collection
152169 end
153170 end
154171
155172 threads . each ( &:join )
156173
157174 threads . each do |thread |
158- self . matrixeval_results += thread [ :matrixeval_results ]
175+ self . matrixeval_results += ( thread [ :matrixeval_results ] || [ ] )
159176 end
160177 end
161178
162- def threads
163- @threads ||= [ ]
164- end
165179
166- def matrixeval_results
167- @matrixeval_results ||= [ ]
180+ def per_worker_contexts_count
181+ [ ( contexts . count / workers_count ) , 1 ] . max
168182 end
169183
170- def matrixeval_results = ( results )
171- @matrixeval_results = results
184+ def contexts
185+ @contexts ||= Context . all
172186 end
173187
174188 def workers_count
0 commit comments