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(server) ⇒ Object
This method runs a container.
-
#volume_flags(server) ⇒ 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, #docker_machine, #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.
37 38 39 40 41 42 43 44 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 37 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.
89 90 91 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 89 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 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 13 def run @network = projects.first.system_prefix projects.each do |project| @project = project project.databases.select(&:local?).each do |database| run_container database end project.apps.each do |app| run_container app end project.web_servers.each do |web_server| run_container web_server end end true end |
#run_container(server) ⇒ Object
This method runs a container.
It will also remove any existing containers with conflicting names.
Parameters
- server: App/Database/WebServer The server we are running a container for.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 69 def run_container(server) container_name = server.container_name remove_container container_name flags = ["-d"] flags += dns_server_flags flags += volume_flags(server) flags << "-p #{server.port}:80" if server.is_a?(RubyYacht::WebServer) flags << "--net=#{@network}" flags << "--net-alias=#{container_name}" flag_text = flags.join(' ') docker "run #{flag_text} --name=#{container_name} #{container_name}" end |
#volume_flags(server) ⇒ Object
This method gets the flags for mapping the code volume to a local path for a container.
Parameters
- server: App/Database/WebServer The server we are running a container for.
53 54 55 56 57 58 59 |
# File 'lib/ruby_yacht/runner/run_containers.rb', line 53 def volume_flags(server) if @project.check_out_locally && server.is_a?(RubyYacht::App) return ["-v $PWD/../#{server.name}:/var/code"] else return [] end end |