From f366b0602c5e74fa23333e4c75349d2df868053d Mon Sep 17 00:00:00 2001 From: Omer Levi Hevroni Date: Sun, 9 Jul 2017 16:41:31 +0300 Subject: [PATCH] added refreshonly support --- README.md | 2 ++ manifests/image.pp | 4 +++- spec/defines/image_spec.rb | 12 +++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ba750e1d..c16792d3f 100755 --- a/README.md +++ b/README.md @@ -238,6 +238,8 @@ You can trigger a rebuild of the image by subscribing to external events like Do docker::image { 'ubuntu': docker_file => '/tmp/Dockerfile' subscribe => File['/tmp/Dockerfile'], + ensure => 'latest', + refreshonly => 'true' } file { '/tmp/Dockerfile': diff --git a/manifests/image.pp b/manifests/image.pp index 35b2b97fd..f1c6294d5 100644 --- a/manifests/image.pp +++ b/manifests/image.pp @@ -32,6 +32,7 @@ $docker_file = undef, $docker_dir = undef, $docker_tar = undef, + $refreshonly = false ) { include docker::params $docker_command = $docker::params::docker_command @@ -117,6 +118,7 @@ timeout => 0, onlyif => $image_install, require => File['/usr/local/bin/update_docker_image.sh'], + refreshonly => $refreshonly } } elsif $ensure == 'present' { exec { $image_install: @@ -125,7 +127,7 @@ path => ['/bin', '/usr/bin'], timeout => 0, returns => ['0', '2'], - require => File['/usr/local/bin/update_docker_image.sh'], + require => File['/usr/local/bin/update_docker_image.sh'] } } diff --git a/spec/defines/image_spec.rb b/spec/defines/image_spec.rb index e5d190e77..8eb1e5c06 100644 --- a/spec/defines/image_spec.rb +++ b/spec/defines/image_spec.rb @@ -32,6 +32,7 @@ it { should contain_exec('/usr/local/bin/update_docker_image.sh base') } end + context 'with docker_file => Dockerfile' do let(:params) { { 'docker_file' => 'Dockerfile' }} it { should contain_exec('docker build -t base - < Dockerfile') } @@ -138,7 +139,16 @@ context 'with ensure => latest' do let(:params) { { 'ensure' => 'latest' } } - it { should contain_exec("echo 'Update of base complete'").with_onlyif('/usr/local/bin/update_docker_image.sh base') } + it { should contain_exec("echo 'Update of base complete'").with_onlyif('/usr/local/bin/update_docker_image.sh base').with( + 'refreshonly' => 'false' + ) } + end + + context 'with ensure => latest and refreshonly = true' do + let(:params) { { 'ensure' => 'latest', 'refreshonly' => 'true' } } + it { should contain_exec("echo 'Update of base complete'").with_onlyif('/usr/local/bin/update_docker_image.sh base').with( + 'refreshonly' => 'true' + ) } end context 'with ensure => latest and image_tag => precise' do