class DockerRailsProxy::Docker
Attributes
kubernetes_running[RW]
vm_provisioner[RW]
app_container_id[RW]
docker_options[RW]
Private Instance Methods
additional_arguments_parser()
click to toggle source
Calls superclass method
DockerRailsProxy::Base#additional_arguments_parser
# File lib/docker_rails_proxy.rb, line 244 def additional_arguments_parser super do |opts| opts.on('--docker-workdir WORKDIR', 'Working directory inside the container') do |workdir| docker_options['-w'] = workdir end opts.on('--docker-user USER', 'Username or UID (format: <name|uid>[:<group|gid>])') do |user| docker_options['-u'] = user end opts.on('--docker-tty', 'Allocate a pseudo-TTY') do |tty| docker_options['-t'] = nil end opts.on('--docker-interactive', 'Keep STDIN open even if not attached') do |interactive| docker_options['-i'] = nil end end end
docker_compose?()
click to toggle source
# File lib/docker_rails_proxy.rb, line 202 def docker_compose? !!Docker.kubernetes_running == false end
execute(command, tty: false, container_id: app_container_id, replace_process: false, **)
click to toggle source
# File lib/docker_rails_proxy.rb, line 226 def execute(command, tty: false, container_id: app_container_id, replace_process: false, **) docker_options['-ti'] = nil if tty command = [ 'docker exec', docker_options.map { |key, value| [key, value].compact.join(' ') }, container_id, command ].join(' '.freeze) replace_process ? exec(command) : system(command) end
get_docker_container_id(app, container: nil)
click to toggle source
# File lib/docker_rails_proxy.rb, line 214 def get_docker_container_id(app, container: nil) if docker_compose? %x(docker ps -q --filter "name=#{[app, container].compact.join('_')}$").strip elsif kubernetes? pod_name = %x(kubectl get pod -l "app=#{app}" 2> /dev/null | grep Running | awk '{print $1}').strip return '' if pod_name.empty? full_id = %x(kubectl get pod #{pod_name} -o jsonpath='{ .status.containerStatuses[?(@.name=="#{container || app}")].containerID }').strip full_id.split('//').last end end
kubernetes?()
click to toggle source
# File lib/docker_rails_proxy.rb, line 206 def kubernetes? Docker.kubernetes_running end
set_app_container_id()
click to toggle source
# File lib/docker_rails_proxy.rb, line 210 def set_app_container_id self.app_container_id = get_docker_container_id(APP_NAME) end