class HttpStubDocker::Rake::ContainerTasks
Public Class Methods
new(args)
click to toggle source
# File lib/http_stub_docker/rake/container_tasks.rb, line 6 def initialize(args) define_build_task(args) define_start_task(args) define_connect_task(args) define_stop_task(args) end
Private Instance Methods
container_ids(args)
click to toggle source
# File lib/http_stub_docker/rake/container_tasks.rb, line 46 def container_ids(args) `docker ps -a --filter ancestor=#{args.stub_name} --format "{{.ID}}"`.split end
define_build_task(args)
click to toggle source
# File lib/http_stub_docker/rake/container_tasks.rb, line 15 def define_build_task(args) desc "Builds the image" task(:build) do sh "docker build -t #{args.stub_name} ." end end
define_connect_task(args)
click to toggle source
# File lib/http_stub_docker/rake/container_tasks.rb, line 32 def define_connect_task(args) desc "Connects to a running container" task(:connect) do sh "docker exec -it #{container_ids(args).first} /bin/sh" end end
define_start_task(args)
click to toggle source
# File lib/http_stub_docker/rake/container_tasks.rb, line 22 def define_start_task(args) desc "Starts a container" task(:start) do sh "docker run -d " \ "-p #{args.port}:#{args.port} " \ "-e STUB_EXTERNAL_BASE_URI=#{args.external_base_uri} " \ "#{args.stub_name}" end end
define_stop_task(args)
click to toggle source
# File lib/http_stub_docker/rake/container_tasks.rb, line 39 def define_stop_task(args) desc "Stops all containers" task(:stop) do container_ids(args).each { |container_id| sh "docker rm -f #{container_id}" } end end