Module: VagrantPlugins::ProxyConf::Cap::CoreOS::DockerProxyConf

Defined in:
lib/vagrant-proxyconf/cap/coreos/docker_proxy_conf.rb

Overview

Capability for docker proxy configuration

Class Method Summary collapse

Class Method Details

.docker_proxy_conf(machine) ⇒ String, false

Returns the path to docker or ‘false` if not found.

Returns:

  • (String, false)

    the path to docker or ‘false` if not found



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-proxyconf/cap/coreos/docker_proxy_conf.rb', line 10

def self.docker_proxy_conf(machine)
  return false unless Util.which(machine, 'docker')

  machine.communicate.tap do |comm|
    src_file = '/usr/lib/systemd/system/docker.service'
    dst_file = '/etc/systemd/system/docker.service'
    tmp_file = '/tmp/docker.service'
    env_file = 'EnvironmentFile=-\/etc\/default\/docker'
    comm.sudo("sed -e 's/\\[Service\\]/[Service]\\n#{env_file}/g' #{src_file} > #{tmp_file}")
    unless comm.test("diff #{tmp_file} #{dst_file}")
      # update config and restart docker when config changed
      comm.sudo("mv -f #{tmp_file} #{dst_file}")
      comm.sudo('systemctl daemon-reload')
    end
    comm.sudo("rm -f #{tmp_file}")
  end
  '/etc/default/docker'
end