Skip to content

Commit

Permalink
Support refreshonly flag
Browse files Browse the repository at this point in the history
Allow for the refreshonly flag to be passed through to the underlying
exec resource.

This allows for Docker::Exec resources to be defined to only run when
notified, which allows for construction of manifests that can check
whether updated configuration made available to running containers
(provided they are using directory mount binds) are valid before
triggering a service restart.

Use case for this is to test generated nginx configuration for the
running nginx container using a Docker::Exec call that is notified by
the file resource and in turn will notify the service resource to
restart.

Partial fix for garethr#687
  • Loading branch information
electrofelix committed Jun 9, 2017
1 parent 40194a2 commit 3f13650
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions manifests/exec.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$tty = false,
$container = undef,
$command = undef,
$refreshonly = false,
$unless = undef,
$sanitise_name = true,
) {
Expand All @@ -21,6 +22,7 @@
validate_string($unless)
validate_bool($detach)
validate_bool($interactive)
validate_bool($refreshonly)
validate_bool($tty)

$docker_exec_flags = docker_exec_flags({
Expand All @@ -45,6 +47,7 @@
exec { $exec:
environment => 'HOME=/root',
path => ['/bin', '/usr/bin'],
refreshonly => $refreshonly,
timeout => 0,
unless => $unless_command,
}
Expand Down
49 changes: 49 additions & 0 deletions spec/acceptance/docker_full_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,55 @@ class { 'docker':}
expect(r.stdout).to match(/test_command_file.txt/)
end
end

it 'should only run if notified when refreshonly is true' do
container_name = 'container_4_2'
pp=<<-EOS
class { 'docker': }
docker::image { 'ubuntu': }
docker::run { '#{container_name}':
image => 'ubuntu',
command => 'init',
}
docker::exec { 'test_command':
container => '#{container_name}',
command => 'touch /root/test_command_file.txt',
refreshonly => true,
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true) unless fact('selinux') == 'true'

# A sleep to give docker time to execute properly
sleep 4

shell("docker exec #{container_name} ls /root") do |r|
expect(r.stdout).to_not match(/test_command_file.txt/)
end

pp_extra=<<-EOS
file { '/tmp/dummy_file':
ensure => 'present',
notify => Docker::Exec['test_command'],
}
EOS

pp2 = pp + pp_extra

apply_manifest(pp2, :catch_failures => true)
apply_manifest(pp2, :catch_changes => true) unless fact('selinux') == 'true'

# A sleep to give docker time to execute properly
sleep 4

shell("docker exec #{container_name} ls /root") do |r|
expect(r.stdout).to match(/test_command_file.txt/)
end
end
end
end
end

0 comments on commit 3f13650

Please sign in to comment.