Class: RubyYacht::Runner::RunContainers
- Defined in:
- lib/ruby_yacht/runner/run_containers.rb
Overview
This class provides a command for running all the images in new containers.
It will also remove any existing containers with conflicting names.
Class Method Summary collapse
-
.command ⇒ Object
THe name of the command.
-
.description ⇒ Object
The short description of the command.
Instance Method Summary collapse
-
#dns_server_flags ⇒ Object
This method gets the flags for defining DNS server config when running a container.
-
#remove_container(container_name) ⇒ Object
This method removes a container.
-
#run ⇒ Object
This method runs the logic of the command.
-
#run_container(name) ⇒ Object
This method runs a container.
-
#volume_flags(container_name) ⇒ Object
This method gets the flags for mapping the code volume to a local path for a container.
Methods inherited from Command
#backtick, #default_project, #docker, #get_machine_info, #log, #option_parser, #parse_positional_arguments, #project_named, #projects, short_script_name, #system
Class Method Details
.command ⇒ Object
THe name of the command.
7 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 7 def self.command; 'run_containers'; end |
.description ⇒ Object
The short description of the command.
10 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 10 def self.description; 'Runs containers for all the apps'; end |
Instance Method Details
#dns_server_flags ⇒ Object
This method gets the flags for defining DNS server config when running a container.
44 45 46 47 48 49 50 51 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 44 def dns_server_flags flags = [] if @project.dns_server flags += @project.dns_server.servers.map { |server| "--dns=#{server}" } flags += @project.dns_server.search_domains.map { |domain| "--dns-search=#{domain}" } end flags end |
#remove_container(container_name) ⇒ Object
This method removes a container.
### Parameters
-
**container_name: String** The full name of the container.
101 102 103 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 101 def remove_container(container_name) IO.popen("docker rm -f #{container_name}", err: :close) {} end |
#run ⇒ Object
This method runs the logic of the command.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 13 def run @network = projects.first.system_prefix projects.each do |project| @project = project if @project.check_out_locally FileUtils.mkdir_p File.join(ENV["PWD"], '..', 'code') end if project.database.local? run_container :database end project.apps.each do |app| run_container app.name end if @project.create_deploy_container run_container :deploy end end @project = projects.first run_container :web true end |
#run_container(name) ⇒ Object
This method runs a container.
It will also remove any existing containers with conflicting names.
### Parameters
-
**name: Symbol** The name of the container, not including the system
prefix.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 80 def run_container(name) container_name = "#{@project.system_prefix}-#{name}" remove_container container_name flags = ["-d"] flags += dns_server_flags flags += volume_flags(name) flags << "-it" if name == :deploy flags << "-p 80:80" if name == :web flags << "--net=#{@network}" flags << "--net-alias=#{container_name}" flag_text = flags.join(' ') docker "run #{flag_text} --name=#{container_name} #{container_name}" end |
#volume_flags(container_name) ⇒ Object
This method gets the flags for mapping the code volume to a local path for a container.
### Parameters
-
**container_name: Symbol** The name of the container, not including
the system prefix.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 60 def volume_flags(container_name) if @project.check_out_locally && ![:database, :web].include?(container_name) if container_name == :deploy return ["-v $PWD/../code:/var/code"] else return ["-v $PWD/../code/#{container_name}:/var/code"] end else return [] end end |