diff --git a/README.md b/README.md index 27ec1d9b..e6f23b56 100755 --- a/README.md +++ b/README.md @@ -332,6 +332,7 @@ This is equivalent to running the `docker run -d base /bin/sh -c "while true; d ```puppet docker::run { 'helloworld': image => 'base', + detach => true, service_prefix => 'docker-', command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', ports => ['4444', '4555'], diff --git a/manifests/run.pp b/manifests/run.pp index 5b19937e..f5d39ce4 100755 --- a/manifests/run.pp +++ b/manifests/run.pp @@ -109,6 +109,7 @@ Variant[String,Boolean] $docker_service = false, Optional[Boolean] $disable_network = false, Optional[Boolean] $privileged = false, + Optional[Boolean] $detach = undef, Variant[String,Array[String],Undef] $extra_parameters = undef, Optional[String] $systemd_restart = 'on-failure', Variant[String,Hash,Undef] $extra_systemd_parameters = {}, @@ -169,6 +170,12 @@ assert_type(Pattern[/^(no|always|on-success|on-failure|on-abnormal|on-abort|on-watchdog)$/], $systemd_restart) } + if $detach == undef { + $valid_detach = $docker::params::detach_service_in_init + } else { + $valid_detach = $detach + } + $extra_parameters_array = any2array($extra_parameters) $after_array = any2array($after) $depends_array = any2array($depends) diff --git a/spec/defines/run_spec.rb b/spec/defines/run_spec.rb index ddec7743..bfbaae30 100755 --- a/spec/defines/run_spec.rb +++ b/spec/defines/run_spec.rb @@ -379,6 +379,11 @@ end end + context 'should be able to override detached' do + let(:params) { {'command' => 'command', 'image' => 'base', 'detach' => false} } + it { should contain_file(startscript_or_init).without_content(/--detach=true/) } + end + context 'when running with a tty' do let(:params) { {'command' => 'command', 'image' => 'base', 'tty' => true} } it { should contain_file(startscript_or_init).with_content(/-t/) }