Method: Navo::Suite#container
- Defined in:
- lib/navo/suite.rb
#container ⇒ Docker::Container
Returns the Docker::Container used by this test suite, starting it if necessary.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/navo/suite.rb', line 282 def container @container ||= begin # Dummy reference so we build the image first (ensuring its log output # appears before the container creation log output) image if state['container'] begin container = Docker::Container.get(state['container']) @logger.debug "Loaded existing container #{container.id}" rescue Docker::Error::NotFoundError @logger.debug "Container #{state['container']} no longer exists" end end if !container @logger.info "Building a new container from image #{image.id}" container = Docker::Container.create( 'Image' => image.id, 'OpenStdin' => true, 'StdinOnce' => true, 'HostConfig' => { 'Privileged' => @config['docker']['privileged'], 'Binds' => @config['docker']['volumes'] + %W[ #{Berksfile.vendor_directory}:#{File.join(chef_run_dir, 'cookbooks')} #{File.join(repo_root, 'data_bags')}:#{File.join(chef_run_dir, 'data_bags')} #{File.join(repo_root, 'environments')}:#{File.join(chef_run_dir, 'environments')} #{File.join(repo_root, 'roles')}:#{File.join(chef_run_dir, 'roles')} ], }, ) state['container'] = container.id end unless started?(container.id) @logger.info "Starting container #{container.id}" container.start else @logger.debug "Container #{container.id} already running" end container end end |