diff --git a/README.md b/README.md index 609f494..00a711b 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,17 @@ Ran on 1 node in 33.96 seconds Provision allows for passing additional command line arguments to the docker run when specifying `vars['docker_run_opts']` as an array of arguments. +When running Debian or Ubuntu containers, the following flags will be added to the $docker_run_opts by default. +``` +--volume /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host +``` + +These defaults can be overriden by passing the flags with different values i.e. + +``` +--volume /sys/fs/cgroup:/sys/fs/cgroup:ro --cgroupns=private +``` + ``` $ bundle exec bolt --modulepath /Users/tp/workspace/git/ task run provision::docker --targets localhost action=provision platform=ubuntu:14.04 inventory=/Users/tp/workspace/git/provision vars='{ "docker_run_opts": ["-p 8086:8086", "-p 3000:3000"]}' ``` diff --git a/tasks/docker.rb b/tasks/docker.rb index d0535bb..eca209a 100755 --- a/tasks/docker.rb +++ b/tasks/docker.rb @@ -161,11 +161,7 @@ def provision(image, inventory_location, vars) warn '!!! Using private port forwarding!!!' front_facing_port = random_ssh_forwarding_port full_container_name = "#{image.gsub(%r{[\/:\.]}, '_')}-#{front_facing_port}" - deb_family_systemd_volume = if (image =~ %r{debian|ubuntu}) && (image !~ %r{debian8|ubuntu14}) - '--volume /sys/fs/cgroup:/sys/fs/cgroup:ro' - else - '' - end + node = { 'uri' => "#{hostname}:#{front_facing_port}", 'config' => { @@ -179,12 +175,19 @@ def provision(image, inventory_location, vars) 'os-release' => os_release_facts, }, } + docker_run_opts = '' unless vars.nil? var_hash = YAML.safe_load(vars) node['vars'] = var_hash docker_run_opts = var_hash['docker_run_opts'].flatten.join(' ') unless var_hash['docker_run_opts'].nil? end - creation_command = "docker run -d -it --privileged #{deb_family_systemd_volume} --tmpfs /tmp:exec -p #{front_facing_port}:22 --name #{full_container_name} " + + docker_run_opts += ' --volume /sys/fs/cgroup:/sys/fs/cgroup:rw' if (image =~ %r{debian|ubuntu}) \ + && (docker_run_opts !~ %r{--volume /sys/fs/cgroup:/sys/fs/cgroup}) + docker_run_opts += ' --cgroupns=host' if (image =~ %r{debian|ubuntu}) \ + && (docker_run_opts !~ %r{--cgroupns}) + + creation_command = "docker run -d -it --privileged --tmpfs /tmp:exec -p #{front_facing_port}:22 --name #{full_container_name} " creation_command += "#{docker_run_opts} " unless docker_run_opts.nil? creation_command += image run_local_command(creation_command).strip diff --git a/tasks/docker_exp.rb b/tasks/docker_exp.rb index 9b730c4..65deb16 100755 --- a/tasks/docker_exp.rb +++ b/tasks/docker_exp.rb @@ -13,17 +13,19 @@ def provision(docker_platform, inventory_location, vars) include PuppetLitmus::InventoryManipulation inventory_full_path = File.join(inventory_location, '/spec/fixtures/litmus_inventory.yaml') inventory_hash = get_inventory_hash(inventory_full_path) + + docker_run_opts = '' unless vars.nil? var_hash = YAML.safe_load(vars) docker_run_opts = var_hash['docker_run_opts'].flatten.join(' ') unless var_hash['docker_run_opts'].nil? end - deb_family_systemd_volume = if (docker_platform =~ %r{debian|ubuntu}) && (docker_platform !~ %r{debian8|ubuntu14}) - '--volume /sys/fs/cgroup:/sys/fs/cgroup:ro' - else - '' - end - creation_command = "docker run -d -it #{deb_family_systemd_volume} --privileged #{docker_run_opts} #{docker_platform}" + docker_run_opts += ' --volume /sys/fs/cgroup:/sys/fs/cgroup:rw' if (docker_platform =~ %r{debian|ubuntu}) \ + && (docker_run_opts !~ %r{--volume /sys/fs/cgroup:/sys/fs/cgroup}) + docker_run_opts += ' --cgroupns=host' if (docker_platform =~ %r{debian|ubuntu}) \ + && (docker_run_opts !~ %r{--cgroupns}) + + creation_command = "docker run -d -it --privileged #{docker_run_opts} #{docker_platform}" container_id = run_local_command(creation_command).strip[0..11] fix_missing_tty_error_message(container_id) unless platform_is_windows?(docker_platform) node = { 'uri' => container_id, @@ -33,6 +35,7 @@ def provision(docker_platform, inventory_location, vars) var_hash = YAML.safe_load(vars) node['vars'] = var_hash end + group_name = 'docker_nodes' add_node_to_group(inventory_hash, node, group_name) File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }