Class: Spurious::Server::State::Init
- Defined in:
- lib/spurious/server/state/init.rb
Instance Attribute Summary collapse
-
#completed_containers ⇒ Object
Returns the value of attribute completed_containers.
-
#docker_host ⇒ Object
Returns the value of attribute docker_host.
Attributes inherited from Base
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(connection, config, docker_host) ⇒ Init
constructor
A new instance of Init.
- #operation_complete(complete) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(connection, config, docker_host) ⇒ Init
Returns a new instance of Init.
12 13 14 15 16 |
# File 'lib/spurious/server/state/init.rb', line 12 def initialize(connection, config, docker_host) super(connection, config) connection_timeouts 2, 3600, 3600 @docker_host = docker_host end |
Instance Attribute Details
#completed_containers ⇒ Object
Returns the value of attribute completed_containers.
10 11 12 |
# File 'lib/spurious/server/state/init.rb', line 10 def completed_containers @completed_containers end |
#docker_host ⇒ Object
Returns the value of attribute docker_host.
10 11 12 |
# File 'lib/spurious/server/state/init.rb', line 10 def docker_host @docker_host end |
Instance Method Details
#execute! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/spurious/server/state/init.rb', line 18 def execute! raise "Containers have already been initilised, please run 'spurious start'" if spurious_containers.length > 0 send("Pulling containers from the registry can take some time, please be patient...", :info, false, :blue) containers = app_config.length index = 0 app_config.each do |name, | = {}.tap do |h| h['fromImage'] = [:image] h['Env'] = [:env] unless [:env].nil? end container_cmd = [] if [:image] == 'spurious/s3' container_cmd = ['-H', [:hostname]] end create_container = Proc.new do begin send "Creating #{name} container", :debug Docker::Container.create("name" => name, "Image" => [:image], 'Cmd' => container_cmd) rescue Docker::Error::ArgumentError, Docker::Error::NotFoundError rescue Excon::Errors::Conflict error "#{name} container already exists" end index = index + 1 operation_complete(containers == index) end create_image = Proc.new do begin send "Pulling latest version of #{name} from registry", :debug Docker::Image.create() rescue Docker::Error::ArgumentError, Docker::Error::NotFoundError, Excon::Errors::Timeout, Excon::Errors::SocketError end end EM.defer(create_image, create_container) end end |
#operation_complete(complete) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/spurious/server/state/init.rb', line 64 def operation_complete(complete) if complete send("#{app_config.length} containers successfully initialized", :info, false, :green) send("Please add the following to your /etc/hosts file:\n\n#{docker_host} sqs.spurious.localhost s3.spurious.localhost dynamodb.spurious.localhost browser.spurious.localhost\n", :info, true, :blue) end end |