Class: Mobilis::DockerComposeProjector
- Inherits:
-
Object
- Object
- Mobilis::DockerComposeProjector
- Defined in:
- lib/mobilis/docker_compose_projector.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_cwd_path ⇒ Object
-
#initialize(project) ⇒ DockerComposeProjector
constructor
A new instance of DockerComposeProjector.
- #mysql_service(service) ⇒ Object
- #postgresql_service(service) ⇒ Object
- #rack_service(service) ⇒ Object
- #rails_service(service) ⇒ Object
- #redis_service(service) ⇒ Object
Constructor Details
#initialize(project) ⇒ DockerComposeProjector
Returns a new instance of DockerComposeProjector.
123 124 125 |
# File 'lib/mobilis/docker_compose_projector.rb', line 123 def initialize project @project = project end |
Class Method Details
.port_skip ⇒ Object
6 7 8 |
# File 'lib/mobilis/docker_compose_projector.rb', line 6 def self.port_skip return 10 end |
.project(project) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mobilis/docker_compose_projector.rb', line 10 def self.project project projector = DockerComposeProjector.new project services = {} project.projects.each_with_index do |service, index| services[service.name] = projector.send "#{service.type}_service", service if service.links.count > 0 then services[service.name]["links"] = service.links.map(&:to_s) services[service.name]["depends_on"] = service.links.map(&:to_s) service.links.each do |link| linked_service = project.project_by_name link linked_service.child_env_vars.each do |var| services[service.name]["environment"] << var end end end end {"version" => "3.8", "services" => services} end |
Instance Method Details
#get_cwd_path ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/mobilis/docker_compose_projector.rb', line 114 def get_cwd_path f = Dir.getwd if f[1] == ':' then f[1] = f[0].downcase f[0] = '/' end f end |
#mysql_service(service) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/mobilis/docker_compose_projector.rb', line 84 def mysql_service service attributes = @project.attributes keyname = "#{service.name}_internal_port_no".to_sym { "image" => "mysql:debian", "restart" => "always", "environment" => service.env_vars, "ports" => ["#{ attributes[keyname] }:3306"], "volumes" => [ "#{ service.data_dir }:/var/lib/mysql" ], } end |
#postgresql_service(service) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mobilis/docker_compose_projector.rb', line 70 def postgresql_service service attributes = @project.attributes keyname = "#{service.name}_internal_port_no".to_sym { "image" => "postgres:14.1-alpine", "restart" => "always", "environment" => service.env_vars, "ports" => ["#{ attributes[keyname] }:5432"], "volumes" => [ "#{ service.data_dir }:/var/lib/postgresql/data" ], } end |
#rack_service(service) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mobilis/docker_compose_projector.rb', line 57 def rack_service service attributes = @project.attributes keyname = "#{ service.name }_internal_port_no".to_sym { "image" => service.docker_image_name, "ports" => ["#{ attributes[keyname] }:9292"], "environment" => [], "build" => { "context" => "./#{ service.name }" } } end |
#rails_service(service) ⇒ Object
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 |
# File 'lib/mobilis/docker_compose_projector.rb', line 30 def rails_service service attributes = @project.attributes keyname = "#{ service.name }_internal_port_no".to_sym vars = [] vars << "RAILS_ENV=production" vars << "RAILS_MASTER_KEY=#{ service.rails_master_key }" vars << "RAILS_MIN_THREADS=5" vars << "RAILS_MAX_THREADS=5" database = service.database if database then vars << "DATABASE_URL=#{ database.url }" end #vars << "NEW_RELIC_APP_NAME=#{ service.name }" #vars << "NEW_RELIC_LICENSE_KEY=#{ attributes[:new_relic_license_key] }" #vars << "NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true" { "image" => service.docker_image_name, "ports" => ["#{ attributes[keyname] }:3000"], "environment" => vars, "build" => { "context" => "./#{ service.name }" } } end |
#redis_service(service) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/mobilis/docker_compose_projector.rb', line 98 def redis_service service attributes = @project.attributes port_key = "#{service.name}_internal_port_no".to_sym { "image" => "redis:7.0.5-alpine", "restart" => "always", "command" => "redis-server --save 20 1 --loglevel warning --requirepass #{ service.password }", "environment" => [ ], "ports" => [ "#{ attributes[port_key] }:6379" ], "volumes" => [ "#{ service.data_dir }:/data" ], } end |