Sha256: 6913db826032c19d468ea65bbb0a2eef9bd04e48b4c5560f7cfc530bc23c1f55
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
require "shellwords" require "uri" module DockerRunner extend self def docker_installed? system("hash docker > /dev/null 2> /dev/null") end def image_exists?(name) system("docker images | grep -q '^#{name.shellescape} '") end def build_image(name, path: Dir.pwd) system("cd #{path.shellescape} && docker build -t #{name.shellescape} .") end def run_container(name, port:, environment: {}) environment_flags = environment.map { |key, value| "-e #{key.to_s.upcase.shellescape}=#{value.shellescape}" } output = ` docker run \ -dit -p #{port.to_i}:80 \ #{environment_flags.join(" ")} \ #{name.shellescape} ` if $?.success? output.chomp else fail "Failed to start container. Maybe it's already running? Output: #{output}" end end def purge_container(id) output = `docker kill #{id.shellescape}; docker rm #{id.shellescape} ` unless $?.success? message = "Could not clean up docker image #{id}. Output was:\n#{output}.\n" if ENV["CIRCLECI"] puts message else raise message end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wordpress_client-0.0.1 | spec/support/docker_runner.rb |