Commit 4b1f2164 authored by Terence Lee's avatar Terence Lee

don't delete containers in Circle CI

Circle CI does not allow deletion of containers:

Cannot destroy container
6f30ab3de4f445d4fe47059d68d9798d40f5f66b9a1120dcfd130c0cab378cb5: Driver
btrfs failed to remove root filesystem
6f30ab3de4f445d4fe47059d68d9798d40f5f66b9a1120dcfd130c0cab378cb5: Failed
to destroy btrfs snapshot: operation not permitted
parent e3ce4e63
...@@ -21,7 +21,7 @@ RSpec.describe "Simple" do ...@@ -21,7 +21,7 @@ RSpec.describe "Simple" do
end end
let(:proxy) { nil } let(:proxy) { nil }
let(:app) { AppRunner.new(name, proxy, env, @debug, ENV['CIRCLECI']) } let(:app) { AppRunner.new(name, proxy, env, @debug, !ENV['CIRCLECI']) }
let(:name) { "hello_world" } let(:name) { "hello_world" }
let(:env) { Hash.new } let(:env) { Hash.new }
......
...@@ -14,15 +14,15 @@ class AppRunner ...@@ -14,15 +14,15 @@ class AppRunner
attr_reader :proxy attr_reader :proxy
def initialize(fixture, proxy = nil, env = {}, debug = false) def initialize(fixture, proxy = nil, env = {}, debug = false, delete = true)
@run = false @run = false
@debug = debug @debug = debug
@tmpdir = nil @tmpdir = nil
@proxy = nil @proxy = nil
@delete = delete
env.merge!("STATIC_DEBUG" => "true") if @debug env.merge!("STATIC_DEBUG" => "true") if @debug
app_options = { app_options = {
"name" => "app",
"Image" => BuildpackBuilder::TAG, "Image" => BuildpackBuilder::TAG,
# Env format is [KEY1=VAL1 KEY2=VAL2] # Env format is [KEY1=VAL1 KEY2=VAL2]
"Env" => env.to_a.map {|i| i.join("=") }, "Env" => env.to_a.map {|i| i.join("=") },
...@@ -32,7 +32,6 @@ class AppRunner ...@@ -32,7 +32,6 @@ class AppRunner
} }
if proxy if proxy
app_options["Links"] = ["proxy:proxy"]
if proxy.is_a?(String) if proxy.is_a?(String)
@tmpdir = Dir.mktmpdir @tmpdir = Dir.mktmpdir
File.open("#{@tmpdir}/config.ru", "w") do |file| File.open("#{@tmpdir}/config.ru", "w") do |file|
...@@ -42,7 +41,8 @@ class AppRunner ...@@ -42,7 +41,8 @@ class AppRunner
end end
end end
@proxy = ProxyRunner.new(@tmpdir) @proxy = ProxyRunner.new(@tmpdir, @delete)
app_options["Links"] = ["#{@proxy.id}:proxy"]
@proxy.start @proxy.start
# need to interpolate the PROXY_IP_ADDRESS since env is a parameter to this constructor and # need to interpolate the PROXY_IP_ADDRESS since env is a parameter to this constructor and
...@@ -55,7 +55,7 @@ class AppRunner ...@@ -55,7 +55,7 @@ class AppRunner
end end
@app = Docker::Container.create(app_options) @app = Docker::Container.create(app_options)
@router = RouterRunner.new @router = RouterRunner.new(@app.id, @delete)
end end
def run(capture_io = false) def run(capture_io = false)
...@@ -106,7 +106,7 @@ class AppRunner ...@@ -106,7 +106,7 @@ class AppRunner
@proxy.destroy @proxy.destroy
end end
@router.destroy @router.destroy
@app.delete(force: true) @app.delete(force: true) if @delete
ensure ensure
FileUtils.rm_rf(@tmpdir) if @tmpdir FileUtils.rm_rf(@tmpdir) if @tmpdir
end end
......
...@@ -2,12 +2,16 @@ require "fiber" ...@@ -2,12 +2,16 @@ require "fiber"
require "docker" require "docker"
class ContainerRunner class ContainerRunner
extend Forwardable
attr_reader :ip_address attr_reader :ip_address
def_delegators :@container, :id
def initialize(options) def initialize(options, delete = true)
@container = Docker::Container.create(options) @container = Docker::Container.create(options)
@ip_address = nil @ip_address = nil
@thread = nil @thread = nil
@delete = delete
end end
def start def start
...@@ -24,6 +28,6 @@ class ContainerRunner ...@@ -24,6 +28,6 @@ class ContainerRunner
end end
def destroy def destroy
@container.delete(force: true) @container.delete(force: true) if @delete
end end
end end
...@@ -2,13 +2,12 @@ require_relative "proxy_builder" ...@@ -2,13 +2,12 @@ require_relative "proxy_builder"
require_relative "container_runner" require_relative "container_runner"
class ProxyRunner < ContainerRunner class ProxyRunner < ContainerRunner
def initialize(config_ru = nil) def initialize(config_ru = nil, delete = true)
options = { options = {
"name" => "proxy",
"Image" => ProxyBuilder::TAG "Image" => ProxyBuilder::TAG
} }
options["HostConfig"] = { "Binds" => ["#{config_ru}:/app/config/"] } if config_ru options["HostConfig"] = { "Binds" => ["#{config_ru}:/app/config/"] } if config_ru
super(options) super(options, delete)
end end
end end
...@@ -11,12 +11,11 @@ class RouterRunner < ContainerRunner ...@@ -11,12 +11,11 @@ class RouterRunner < ContainerRunner
HTTPS_PORT = "443" HTTPS_PORT = "443"
HOST_IP = boot2docker_ip || "127.0.0.1" HOST_IP = boot2docker_ip || "127.0.0.1"
def initialize def initialize(app_id, delete = true)
super({ super({
"name" => "router",
"Image" => RouterBuilder::TAG, "Image" => RouterBuilder::TAG,
"HostConfig" => { "HostConfig" => {
"Links" => ["app:app"], "Links" => ["#{app_id}:app"],
"PortBindings" => { "PortBindings" => {
"#{HTTP_PORT}/tcp" => [{ "#{HTTP_PORT}/tcp" => [{
"HostIp" => HOST_IP, "HostIp" => HOST_IP,
...@@ -28,6 +27,6 @@ class RouterRunner < ContainerRunner ...@@ -28,6 +27,6 @@ class RouterRunner < ContainerRunner
}] }]
} }
} }
}) }, delete)
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment