Skip to content

Commit

Permalink
Merge pull request #1 from otahi/fix_ubuntu_docker
Browse files Browse the repository at this point in the history
Fix ubuntu docker
  • Loading branch information
mrsheepuk committed Sep 19, 2015
2 parents 690cb77 + 89b8bac commit 730bb31
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/vagrant-proxyconf/cap/debian/docker_proxy_conf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require_relative '../util'

module VagrantPlugins
module ProxyConf
module Cap
module Debian
# Capability for docker proxy configuration
module DockerProxyConf
CONFIG_DIR = '/etc/default/'

# @return [String, false] the path to docker or `false` if not found
def self.docker_proxy_conf(machine)
docker_command = find_docker_command(machine)
return false if docker_command.nil?

config_path = CONFIG_DIR + docker_command
return config_path unless Util.which(machine, 'systemctl')

machine.communicate.tap do |comm|
src_file = "/lib/systemd/system/#{docker_command}.service"
dst_file = "/etc/systemd/system/#{docker_command}.service"
tmp_file = "/tmp/#{docker_command}.service"
env_file = "EnvironmentFile=-\\/etc\\/default\\/#{docker_command}"
if comm.test("grep -q -e '#{env_file}' #{src_file}")
comm.sudo("cp -p #{src_file} #{tmp_file}")
else
comm.sudo("sed -e 's/\\[Service\\]/[Service]\\n#{env_file}/g' #{src_file} > #{tmp_file}")
end
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
config_path
end

private

def self.find_docker_command(machine)
return 'docker' if Util.which(machine, 'docker')
return 'docker.io' if Util.which(machine, 'docker.io')
nil
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions lib/vagrant-proxyconf/capability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class Plugin < Vagrant.plugin('2')
Cap::CoreOS::DockerProxyConf
end

guest_capability 'debian', 'docker_proxy_conf' do
require_relative 'cap/debian/docker_proxy_conf'
Cap::Debian::DockerProxyConf
end

guest_capability 'linux', 'env_proxy_conf' do
require_relative 'cap/linux/env_proxy_conf'
Cap::Linux::EnvProxyConf
Expand Down

0 comments on commit 730bb31

Please sign in to comment.