Skip to content

Commit

Permalink
(maint) For run_agent map /etc/hosts in from LCOW
Browse files Browse the repository at this point in the history
 - LCOW has a bug where --add-host is not supported for `docker run`
   and extra_hosts is not supported for docker-compose.yml:
   docker/for-win#1455
   moby/moby#30555

 - To workaround this issue, in the run_agent method, write a /etc/hosts
   file and map that directly into the container by mounting a temp
   directory like c:\windows\temp\abcd:/etc
  • Loading branch information
Iristyle committed Aug 27, 2019
1 parent 8b6f72c commit cc6bf37
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions gem/lib/pupperware/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,22 @@ def run_agent(
# setting up a Windows TTY is difficult, so we don't
# allocating a TTY will show container pull output on Linux, but that's not good for tests
STDOUT.puts("running agent #{agent_name} in network #{network} against #{server}")
add_hosts = extra_hosts.empty? ? '' :
extra_hosts.map { |k, v| "--add-host=#{k}:#{v}" }.join(' ')
add_hosts = ''
unless extra_hosts.empty?
# LCOW doesn't support --add-host / extra_hosts as of 7-31-2019
# https://github.com/moby/moby/issues/30555
# https://github.com/docker/for-win/issues/1455
if IS_WINDOWS
path = Pathname.new(Dir.mktmpdir) + 'hosts'
hosts = extra_hosts.map { |k, v| "#{k}\t#{v}" }.join("\n")
# linux containers need LF line endings
File.open(path.realpath, mode: 'w', crlf_newline: false) { |f| f.write(hosts) }
# Windows cannot mount just /etc/hosts, have to mount the entire parent directory
add_hosts = "--volume #{path.dirname}:/etc"
else
add_hosts = extra_hosts.map { |k, v| "--add-host=#{k}:#{v}" }.join(' ')
end
end
result = run_command("docker run --rm --network #{network} --name #{agent_name} --hostname #{agent_name} \
#{add_hosts} puppet/puppet-agent-ubuntu agent --verbose --onetime --no-daemonize --summarize \
--server #{server} --masterport #{masterport} --ca_server #{ca} --ca_port #{ca_port}")
Expand Down

0 comments on commit cc6bf37

Please sign in to comment.