Skip to content

Commit 05b07d3

Browse files
authored
Merge pull request #203 from puppetlabs/maint-remove_deb_family_system_volume
(Maint) - remove deb family system volume
2 parents e136c34 + 9bd9713 commit 05b07d3

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ Ran on 1 node in 33.96 seconds
144144

145145
Provision allows for passing additional command line arguments to the docker run when specifying `vars['docker_run_opts']` as an array of arguments.
146146

147+
When running Debian or Ubuntu containers, the following flags will be added to the $docker_run_opts by default.
148+
```
149+
--volume /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host
150+
```
151+
152+
These defaults can be overriden by passing the flags with different values i.e.
153+
154+
```
155+
--volume /sys/fs/cgroup:/sys/fs/cgroup:ro --cgroupns=private
156+
```
157+
147158
```
148159
$ 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"]}'
149160
```

tasks/docker.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ def provision(image, inventory_location, vars)
161161
warn '!!! Using private port forwarding!!!'
162162
front_facing_port = random_ssh_forwarding_port
163163
full_container_name = "#{image.gsub(%r{[\/:\.]}, '_')}-#{front_facing_port}"
164-
deb_family_systemd_volume = if (image =~ %r{debian|ubuntu}) && (image !~ %r{debian8|ubuntu14})
165-
'--volume /sys/fs/cgroup:/sys/fs/cgroup:ro'
166-
else
167-
''
168-
end
164+
169165
node = {
170166
'uri' => "#{hostname}:#{front_facing_port}",
171167
'config' => {
@@ -179,12 +175,19 @@ def provision(image, inventory_location, vars)
179175
'os-release' => os_release_facts,
180176
},
181177
}
178+
docker_run_opts = ''
182179
unless vars.nil?
183180
var_hash = YAML.safe_load(vars)
184181
node['vars'] = var_hash
185182
docker_run_opts = var_hash['docker_run_opts'].flatten.join(' ') unless var_hash['docker_run_opts'].nil?
186183
end
187-
creation_command = "docker run -d -it --privileged #{deb_family_systemd_volume} --tmpfs /tmp:exec -p #{front_facing_port}:22 --name #{full_container_name} "
184+
185+
docker_run_opts += ' --volume /sys/fs/cgroup:/sys/fs/cgroup:rw' if (image =~ %r{debian|ubuntu}) \
186+
&& (docker_run_opts !~ %r{--volume /sys/fs/cgroup:/sys/fs/cgroup})
187+
docker_run_opts += ' --cgroupns=host' if (image =~ %r{debian|ubuntu}) \
188+
&& (docker_run_opts !~ %r{--cgroupns})
189+
190+
creation_command = "docker run -d -it --privileged --tmpfs /tmp:exec -p #{front_facing_port}:22 --name #{full_container_name} "
188191
creation_command += "#{docker_run_opts} " unless docker_run_opts.nil?
189192
creation_command += image
190193
run_local_command(creation_command).strip

tasks/docker_exp.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ def provision(docker_platform, inventory_location, vars)
1313
include PuppetLitmus::InventoryManipulation
1414
inventory_full_path = File.join(inventory_location, '/spec/fixtures/litmus_inventory.yaml')
1515
inventory_hash = get_inventory_hash(inventory_full_path)
16+
17+
docker_run_opts = ''
1618
unless vars.nil?
1719
var_hash = YAML.safe_load(vars)
1820
docker_run_opts = var_hash['docker_run_opts'].flatten.join(' ') unless var_hash['docker_run_opts'].nil?
1921
end
2022

21-
deb_family_systemd_volume = if (docker_platform =~ %r{debian|ubuntu}) && (docker_platform !~ %r{debian8|ubuntu14})
22-
'--volume /sys/fs/cgroup:/sys/fs/cgroup:ro'
23-
else
24-
''
25-
end
26-
creation_command = "docker run -d -it #{deb_family_systemd_volume} --privileged #{docker_run_opts} #{docker_platform}"
23+
docker_run_opts += ' --volume /sys/fs/cgroup:/sys/fs/cgroup:rw' if (docker_platform =~ %r{debian|ubuntu}) \
24+
&& (docker_run_opts !~ %r{--volume /sys/fs/cgroup:/sys/fs/cgroup})
25+
docker_run_opts += ' --cgroupns=host' if (docker_platform =~ %r{debian|ubuntu}) \
26+
&& (docker_run_opts !~ %r{--cgroupns})
27+
28+
creation_command = "docker run -d -it --privileged #{docker_run_opts} #{docker_platform}"
2729
container_id = run_local_command(creation_command).strip[0..11]
2830
fix_missing_tty_error_message(container_id) unless platform_is_windows?(docker_platform)
2931
node = { 'uri' => container_id,
@@ -33,6 +35,7 @@ def provision(docker_platform, inventory_location, vars)
3335
var_hash = YAML.safe_load(vars)
3436
node['vars'] = var_hash
3537
end
38+
3639
group_name = 'docker_nodes'
3740
add_node_to_group(inventory_hash, node, group_name)
3841
File.open(inventory_full_path, 'w') { |f| f.write inventory_hash.to_yaml }

0 commit comments

Comments
 (0)