lib/kitchen/driver/docker.rb in kitchen-docker-0.3.0 vs lib/kitchen/driver/docker.rb in kitchen-docker-0.4.0

- old
+ new

@@ -16,10 +16,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'kitchen' +require 'json' module Kitchen module Driver @@ -65,11 +66,11 @@ platform = case config[:platform] when 'debian', 'ubuntu' <<-eos ENV DEBIAN_FRONTEND noninteractive RUN apt-get update - RUN apt-get install -y sudo openssh-server curl + RUN apt-get install -y sudo openssh-server curl lsb-release RUN dpkg-divert --local --rename --add /sbin/initctl RUN ln -s /bin/true /sbin/initctl eos when 'rhel', 'centos' <<-eos @@ -116,23 +117,29 @@ 'Could not parse Docker run output for container ID' end container_id end - def run_container(state) - image_id = state[:image_id] - cmd = "docker run -d" - Array(config[:forward]).each do |port| - cmd << " -p #{port}" - end + def build_run_command(image_id) + cmd = 'docker run -d' + Array(config[:foward]).each {|port| cmd << " -p #{port}"} + Array(config[:dns]).each {|dns| cmd << " -dns #{dns}"} + Array(config[:volume]).each {|volume| cmd << " -v #{volume}"} + cmd << " -m #{config[:memory]}" if config[:memory] + cmd << " -c #{config[:cpu]}" if config[:cpu] cmd << " #{image_id} /usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no" + cmd + end + + def run_container(state) + cmd = build_run_command(state[:image_id]) output = run_command(cmd) parse_container_id(output) end def parse_container_ip(output) begin - info = Array(JSON.parse(output)).first + info = Array(::JSON.parse(output)).first settings = info['NetworkSettings'] settings['IpAddress'] || settings['IPAddress'] rescue raise ActionFailed, 'Could not parse Docker inspect output for container IP address'