class EtFullSystem::DockerCommand
!/usr/bin/env ruby
frozen_string_literal: true
Public Instance Methods
admin_env()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 114 def admin_env service_env('admin') end
api_env()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 102 def api_env service_env('api') end
bootstrap()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 12 def bootstrap unbundled do cmd = File.absolute_path('../../../shell_scripts/docker_bootstrap.sh', __dir__) puts cmd exec(cmd) end end
ccd_export_env()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 90 def ccd_export_env service_env('et_ccd_export') end
compose(*args)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 32 def compose(*args) unbundled do gem_root = File.absolute_path('../../..', __dir__) cmd = "UID=#{Process.uid} GEM_VERSION=#{EtFullSystem::VERSION} LOCALHOST_FROM_DOCKER_IP=#{host_ip} docker-compose -f #{gem_root}/docker/docker-compose.yml #{args.join(' ')}" puts cmd exec(cmd) end end
disable_admin()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 191 def disable_admin run_on_local("disable_admin") end
disable_api()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 186 def disable_api run_on_local("disable_api") end
disable_atos_api()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 181 def disable_atos_api run_on_local("disable_atos_api") end
disable_ccd_export()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 176 def disable_ccd_export run_on_local("disable_ccd_export") end
disable_et1()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 171 def disable_et1 run_on_local("disable_et1") end
disable_et3()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 196 def disable_et3 run_on_local("disable_et3") end
enable_admin()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 161 def enable_admin run_on_local("enable_admin") end
enable_api()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 156 def enable_api run_on_local("enable_api") end
enable_atos_api()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 151 def enable_atos_api run_on_local("enable_atos_api") end
enable_ccd_export()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 146 def enable_ccd_export run_on_local("enable_ccd_export") end
enable_et1()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 141 def enable_et1 run_on_local("enable_et1") end
enable_et3()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 166 def enable_et3 run_on_local("enable_et3") end
et1_env()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 79 def et1_env service_env('et1') end
et3_env()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 127 def et3_env service_env('et3') end
invoker(*args)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 42 def invoker(*args) run_on_local("invoker #{args.join(' ')}") end
local_admin(port)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 107 def local_admin(port) local_service('admin', port) disable_admin puts "Admin is now expected to be hosted on port #{port} on your machine. To configure your environment, run 'et_full_system docker admin_env > .env'" end
local_api(port)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 95 def local_api(port) local_service('api', port) disable_api puts "api is now expected to be hosted on port #{port} on your machine. Also, you must provide your own sidekiq. To configure your environment, run 'et_full_system docker api_env > .env'" end
local_ccd_export()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 84 def local_ccd_export run_on_local('disable_ccd_export') puts "ccd_export is now expected to be running on your machine. To configure your environment, run 'et_full_system docker ccd_export_env > .env'" end
local_et1(port)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 71 def local_et1(port) local_service('et1', port) disable_et1 puts "ET1 is now expected to be hosted on port #{port} on your machine. To configure your environment, run 'et_full_system docker et1_env > .env'" end
local_et3(port)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 119 def local_et3(port) local_service('et3', port) disable_et3 puts "ET3 is now expected to be hosted on port #{port} on your machine. To configure your environment, run 'et_full_system docker et3_env > .env'" end
local_service(service, port)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 66 def local_service(service, port) update_service_url(service, local_service_url(port)) end
reset()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 47 def reset unbundled do gem_root = File.absolute_path('../../..', __dir__) cmd = "UID=#{Process.uid} GEM_VERSION=#{EtFullSystem::VERSION} LOCALHOST_FROM_DOCKER_IP=#{host_ip} docker-compose -f #{gem_root}/docker/docker-compose.yml down -v" puts cmd next unless system(cmd) cmd = "UID=#{Process.uid} GEM_VERSION=#{EtFullSystem::VERSION} LOCALHOST_FROM_DOCKER_IP=#{host_ip} docker-compose -f #{gem_root}/docker/docker-compose.yml build --no-cache" puts cmd next unless system(cmd) self.class.start(['setup']) end end
restart_admin()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 216 def restart_admin run_on_local("restart_admin") end
restart_api()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 206 def restart_api run_on_local("restart_api") end
restart_atos_api()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 221 def restart_atos_api run_on_local("restart_atos_api") end
restart_ccd_export()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 226 def restart_ccd_export run_on_local("restart_ccd_export") end
restart_et1()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 201 def restart_et1 run_on_local("restart_et1") end
restart_et3()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 211 def restart_et3 run_on_local("restart_et3") end
service_env(service)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 132 def service_env(service) result = run_on_local("service_env #{service}", return_output: true) replace_db_host_port(result) replace_redis_host_port(result) replace_smtp_host_port(result) puts result end
setup()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 21 def setup unbundled do gem_root = File.absolute_path('../../..', __dir__) cmd = "/bin/bash --login -c \"cd /home/app/full_system && et_full_system docker bootstrap && et_full_system local setup\"" compose_cmd = "UID=#{Process.uid} GEM_VERSION=#{EtFullSystem::VERSION} LOCALHOST_FROM_DOCKER_IP=#{host_ip} docker-compose -f #{gem_root}/docker/docker-compose.yml run --rm et #{cmd}" puts compose_cmd exec(compose_cmd) end end
update_service_url(service, url)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 61 def update_service_url(service, url) run_on_local("update_service_url #{service} #{url}") end
Private Instance Methods
db_port()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 294 def db_port result = run_compose_command :port, :db, 5432, silent: true result.split(':').last.strip end
host_ip()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 259 def host_ip result = JSON.parse `docker network inspect docker_et_full_system` return '0.0.0.0' if result.empty? result.first.dig('IPAM', 'Config').first['Gateway'] end
local_service_url(port)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 266 def local_service_url(port) case ::EtFullSystem.os when :linux, :unix "http://#{host_ip}:#{port}" when :macosx "http://docker.for.mac.localhost" when :windows "http://docker.for.windows.localhost" else raise "Unknown host type - this tool only supports mac, linux and windows" end end
redis_port()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 299 def redis_port result = run_compose_command :port, :redis, 6379, silent: true result.split(':').last.strip end
replace_db_host_port(env)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 279 def replace_db_host_port(env) env.gsub!(/^DB_HOST=.*$/, 'DB_HOST=localhost') env.gsub!(/^DB_PORT=.*$/, "DB_PORT=#{db_port}") end
replace_redis_host_port(env)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 284 def replace_redis_host_port(env) env.gsub!(/^REDIS_HOST=.*$/, 'REDIS_HOST=localhost') env.gsub!(/^REDIS_PORT=.*$/, "REDIS_PORT=#{redis_port}") end
replace_smtp_host_port(env)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 289 def replace_smtp_host_port(env) env.gsub!(/^SMTP_HOSTNAME=.*$/, 'SMTP_HOSTNAME=localhost') env.gsub!(/^SMTP_PORT=.*$/, "SMTP_PORT=#{smtp_port}") end
run_compose_command(*args, silent: false)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 250 def run_compose_command(*args, silent: false) unbundled do gem_root = File.absolute_path('../../..', __dir__) cmd = "UID=#{Process.uid} GEM_VERSION=#{EtFullSystem::VERSION} LOCALHOST_FROM_DOCKER_IP=#{host_ip} docker-compose -f #{gem_root}/docker/docker-compose.yml #{args.join(' ')}" puts cmd unless silent `#{cmd}` end end
run_on_local(cmd, return_output: false)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 237 def run_on_local(cmd, return_output: false) unbundled do gem_root = File.absolute_path('../../..', __dir__) cmd = "/bin/bash --login -c \"et_full_system local #{cmd}\"" compose_cmd = "UID=#{Process.uid} GEM_VERSION=#{EtFullSystem::VERSION} LOCALHOST_FROM_DOCKER_IP=#{host_ip} docker-compose -f #{gem_root}/docker/docker-compose.yml exec et #{cmd}" if return_output `#{compose_cmd}` else system(compose_cmd) end end end
smtp_port()
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 304 def smtp_port result = run_compose_command :port, :et, 1025, silent: true result.split(':').last.strip end
unbundled(&block)
click to toggle source
# File lib/et_full_system/cli/docker.rb, line 232 def unbundled(&block) method = Bundler.respond_to?(:with_unbundled_env) ? :with_unbundled_env : :with_original_env Bundler.send(method, &block) end