lib/navo/suite.rb
# Returns the {Docker::Container} used by this test suite, starting it if
# necessary.
#
# @return [Docker::Container]
Returns the {Docker::Container} used by this test suite, starting it if
necessary.
Returns the { Docker :: Container } used by this test suite starting it if necessary .
def container
      @container ||=
        begin
          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}"
            data_volumes, bind_mounts = container_volumes.partition { |spec| spec =~ %r{^/[^:]*$} }
            data_volumes_hash = Hash[data_volumes.map { |path| [path, {}] }]
            container = Docker::Container.create(
              'name' => container_name, 
              'Image' => image.id,
              'Hostname' => hostname,
              'OpenStdin' => true,
              'StdinOnce' => true,
              'Volumes' => data_volumes_hash,
              'HostConfig' => {
                'Privileged' => @config['docker']['privileged'],
                'Binds' => bind_mounts + %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
def container @container ||= begin 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}" data_volumes , bind_mounts = container_volumes . partition { | spec | spec =~ %r{ ^/[^:]*$ } } data_volumes_hash = Hash [ data_volumes . map { | path | [ path , { } ] } ] container = Docker :: Container . create ( 'name' => container_name , 'Image' => image . id , 'Hostname' => hostname , 'OpenStdin' => true , 'StdinOnce' => true , 'Volumes' => data_volumes_hash , 'HostConfig' => { 'Privileged' => @config [ 'docker' ] [ 'privileged' ] , 'Binds' => bind_mounts + %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
Returns the {Docker::Container} used by this test suite, starting it if
necessary.
Returns the { Docker :: Container } used by this test suite starting it if necessary .
# Dummy reference so we build the image first (ensuring its log output # appears before the container creation log output) # Until Docker supports colons in paths for volume specs [1], we # assume that a spec containing no colons indicates the user wants # to create a data volume. # [1] https://github.com/docker/docker/issues/8604 # Special key handled by docker-api gem
None
Docker::Container