From a2046798977cdad3035e6f241cb5658274866b94 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 4 Mar 2019 11:11:34 +0100 Subject: [PATCH 1/9] docker::services: Fix using multiple published ports (#447) While the class docker::services already allowed arrays to be specified for `publish` ports, it didn't handle this correctly since this array was simply converted to a string and passed onto Docker, like so: --publish '["80:80", "443:443"]' To correctly publish multiple ports, the `--publish` parameter has to be called specified for each port. --publish '80:80' --publish '443:443' This patch also introduces a new spec test to check this behavior --- README.md | 2 +- .../parser/functions/docker_service_flags.rb | 6 +++++- manifests/services.pp | 3 ++- spec/defines/services_spec.rb | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index af84526d..1a0335a7 100755 --- a/README.md +++ b/README.md @@ -799,7 +799,7 @@ docker::services {'redis': } ``` -To base the service off an image, include the `image` parameter and include the `publish` parameter to expose the service ports. To set the amount of containers running in the service, include the `replicas` parameter. To attach one or multiple filesystems to the service, use the `mounts` parameter. For information regarding the `extra_params` parameter, see `docker service create --help`. +To base the service off an image, include the `image` parameter and include the `publish` parameter to expose the service port (use an array to specify multiple published ports). To set the amount of containers running in the service, include the `replicas` parameter. To attach one or multiple filesystems to the service, use the `mounts` parameter. For information regarding the `extra_params` parameter, see `docker service create --help`. To update the service, add the following code to the manifest file: diff --git a/lib/puppet/parser/functions/docker_service_flags.rb b/lib/puppet/parser/functions/docker_service_flags.rb index 61a8441b..3ca2713b 100644 --- a/lib/puppet/parser/functions/docker_service_flags.rb +++ b/lib/puppet/parser/functions/docker_service_flags.rb @@ -36,7 +36,11 @@ module Puppet::Parser::Functions end end - if opts['publish'] && opts['publish'].to_s != 'undef' + if opts['publish'].is_a? Array + opts['publish'].each do |port| + flags << "--publish #{port}" + end + elsif opts['publish'].to_s != 'undef' flags << "--publish '#{opts['publish']}'" end diff --git a/manifests/services.pp b/manifests/services.pp index 8da17125..937a4a1b 100644 --- a/manifests/services.pp +++ b/manifests/services.pp @@ -26,7 +26,7 @@ # Defaults to [] # # [*publish*] -# Publish a port as a node port. +# Publish port(s) as node ports. # Defaults to undef # # [*replicas*] @@ -66,6 +66,7 @@ # [*registry_mirror*] # This will allow the service to set a registry mirror. # defaults to undef +# # [*mounts*] # Allows attacking filesystem mounts to the service (specified as an array) # defaults to [] diff --git a/spec/defines/services_spec.rb b/spec/defines/services_spec.rb index 302ac5a8..abbbb343 100644 --- a/spec/defines/services_spec.rb +++ b/spec/defines/services_spec.rb @@ -41,6 +41,20 @@ it { should contain_exec('test_service docker service create').with_command(/docker service create/) } it { should contain_exec('test_service_2 docker service create').with_command(/docker service create/) } end + + context 'multiple publish ports' do + let(:pre_condition) { + " + docker::services { 'test_service_3': + service_name => 'foo_3', + image => 'foo:bar', + publish => ['80:8080', '9000:9000' ], + } + " + } + it { should contain_exec('test_service_3 docker service create').with_command(/--publish 80:8080/) } + it { should contain_exec('test_service_3 docker service create').with_command(/--publish 9000:9000/) } + end end context 'with ensure => present and service update' do From 059d8a803535896c727db67a5c5b06f3ea628099 Mon Sep 17 00:00:00 2001 From: esalberg Date: Mon, 4 Mar 2019 10:08:10 -0500 Subject: [PATCH 2/9] Add ability to override After for docker.service (#446) --- README.md | 7 ++++++- manifests/init.pp | 1 + manifests/params.pp | 6 ++++++ manifests/service.pp | 1 + spec/classes/docker_spec.rb | 5 +++++ .../docker.service.d/service-overrides-debian.conf.erb | 5 +++++ .../docker.service.d/service-overrides-rhel.conf.erb | 5 +++++ 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a0335a7..7fe68d37 100755 --- a/README.md +++ b/README.md @@ -129,6 +129,8 @@ class { 'docker': } ``` +For more information about the configuration options for the default docker bridge, see the [Docker documentation](https://docs.docker.com/v17.09/engine/userguide/networking/default_network/custom-docker0/). + The default group ownership of the Unix control socket differs based on OS. For example, on RHEL using docker-ce packages >=18.09.1, the socket file used by /usr/lib/systemd/system/docker.socket is owned by the docker group. To override this value in /etc/sysconfig/docker and docker.socket (e.g. to use the 'root' group): ```puppet @@ -144,8 +146,11 @@ The socket_group parameter also takes a boolean for legacy cases where setting - docker::socket_group: false ``` -For more information about the configuration options for the default docker bridge, see the [Docker documentation](https://docs.docker.com/v17.09/engine/userguide/networking/default_network/custom-docker0/). +To add another service to the After= line in the [Unit] section of the systemd /etc/systemd/system/service-overrides.conf file, use the service_after_override parameter: +```puppet +docker::service_after_override: containerd.service +``` When setting up TLS, upload the related files (CA certificate, server certificate, and key) and include their paths in the manifest file: diff --git a/manifests/init.pp b/manifests/init.pp index 0a4f43ef..c4fa6e5e 100755 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -498,6 +498,7 @@ Variant[String,Boolean,Undef] $service_overrides_template = $docker::params::service_overrides_template, Variant[String,Boolean,Undef] $socket_overrides_template = $docker::params::socket_overrides_template, Optional[Boolean] $socket_override = $docker::params::socket_override, + Optional[String] $service_after_override = $docker::params::service_after_override, Optional[Boolean] $service_hasstatus = $docker::params::service_hasstatus, Optional[Boolean] $service_hasrestart = $docker::params::service_hasrestart, Optional[String] $registry_mirror = $docker::params::registry_mirror, diff --git a/manifests/params.pp b/manifests/params.pp index fe7dd98a..75453c91 100755 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -120,6 +120,7 @@ $service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb' $socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb' $socket_override = false + $service_after_override = undef $service_hasstatus = true $service_hasrestart = true include docker::systemd_reload @@ -128,6 +129,7 @@ $service_overrides_template = undef $socket_overrides_template = undef $socket_override = false + $service_after_override = undef $service_provider = 'upstart' $service_hasstatus = true $service_hasrestart = false @@ -142,6 +144,7 @@ $service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb' $socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb' $socket_override = false + $service_after_override = undef $service_hasstatus = true $service_hasrestart = true include docker::systemd_reload @@ -192,6 +195,7 @@ $service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-rhel.conf.erb' $socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb' $socket_override = false + $service_after_override = undef $use_upstream_package_source = true $package_ce_source_location = "https://download.docker.com/linux/centos/$%7B::operatingsystemmajrelease%7D/$%7B::architecture%7D/$%7Bdocker_ce_channel%7D" @@ -264,6 +268,7 @@ $service_overrides_template = undef $socket_overrides_template = undef $socket_override = false + $service_after_override = undef $service_hasstatus = undef $service_hasrestart = undef $detach_service_in_init = true @@ -292,6 +297,7 @@ $service_overrides_template = undef $socket_overrides_template = undef $socket_override = false + $service_after_override = undef $service_hasstatus = undef $service_hasrestart = undef $service_provider = undef diff --git a/manifests/service.pp b/manifests/service.pp index 0b57cce2..f2d75020 100755 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -108,6 +108,7 @@ $service_overrides_template = $docker::service_overrides_template, $socket_overrides_template = $docker::socket_overrides_template, $socket_override = $docker::socket_override, + $service_after_override = $docker::service_after_override, $service_hasstatus = $docker::service_hasstatus, $service_hasrestart = $docker::service_hasrestart, $daemon_environment_files = $docker::daemon_environment_files, diff --git a/spec/classes/docker_spec.rb b/spec/classes/docker_spec.rb index ecace1c5..ed727974 100755 --- a/spec/classes/docker_spec.rb +++ b/spec/classes/docker_spec.rb @@ -441,6 +441,11 @@ it { should contain_file('/etc/systemd/system/docker.service.d/service-overrides.conf').with_content(/docker.io/) } end + context 'with an extra After entry' do + let(:params) {{ 'service_after_override' => 'containerd.service' }} + it { should contain_file('/etc/systemd/system/docker.service.d/service-overrides.conf').with_content(/containerd.service/) } + end + context 'with a specific socket group and override' do let(:params) { { 'socket_group' => 'root', diff --git a/templates/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb b/templates/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb index a60a4778..d7463095 100644 --- a/templates/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb +++ b/templates/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb @@ -1,3 +1,8 @@ +<% if @service_after_override -%> +[Unit] +After=<%= @service_after_override %> + +<% end -%> [Service] EnvironmentFile=-/etc/default/docker EnvironmentFile=-/etc/default/docker-storage diff --git a/templates/etc/systemd/system/docker.service.d/service-overrides-rhel.conf.erb b/templates/etc/systemd/system/docker.service.d/service-overrides-rhel.conf.erb index 071b44a7..2313e93c 100644 --- a/templates/etc/systemd/system/docker.service.d/service-overrides-rhel.conf.erb +++ b/templates/etc/systemd/system/docker.service.d/service-overrides-rhel.conf.erb @@ -1,3 +1,8 @@ +<% if @service_after_override -%> +[Unit] +After=<%= @service_after_override %> + +<% end -%> [Service] EnvironmentFile=-/etc/sysconfig/docker EnvironmentFile=-/etc/sysconfig/docker-storage From 226be6c1a2b6bf27a52e0a959726a0f15190cdfb Mon Sep 17 00:00:00 2001 From: esalberg Date: Fri, 8 Mar 2019 14:27:46 -0500 Subject: [PATCH 3/9] Add ability to set service_after_override to false (#448) --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index c4fa6e5e..eb48a626 100755 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -498,7 +498,7 @@ Variant[String,Boolean,Undef] $service_overrides_template = $docker::params::service_overrides_template, Variant[String,Boolean,Undef] $socket_overrides_template = $docker::params::socket_overrides_template, Optional[Boolean] $socket_override = $docker::params::socket_override, - Optional[String] $service_after_override = $docker::params::service_after_override, + Variant[String,Boolean,Undef] $service_after_override = $docker::params::service_after_override, Optional[Boolean] $service_hasstatus = $docker::params::service_hasstatus, Optional[Boolean] $service_hasrestart = $docker::params::service_hasrestart, Optional[String] $registry_mirror = $docker::params::registry_mirror, From 15ee0e43a8eeb487feb0baeabf8bbebddf09d213 Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 8 Mar 2019 20:33:04 +0100 Subject: [PATCH 4/9] Docker::Services: Add networks parameter for swarm services (#450) Allows attaching the service to one or multiple networks --- lib/puppet/parser/functions/docker_service_flags.rb | 6 ++++++ manifests/services.pp | 8 +++++++- spec/defines/services_spec.rb | 7 ++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/docker_service_flags.rb b/lib/puppet/parser/functions/docker_service_flags.rb index 3ca2713b..bd467ba2 100644 --- a/lib/puppet/parser/functions/docker_service_flags.rb +++ b/lib/puppet/parser/functions/docker_service_flags.rb @@ -36,6 +36,12 @@ module Puppet::Parser::Functions end end + if opts['networks'].is_a? Array + opts['networks'].each do |network| + flags << "--network #{network}" + end + end + if opts['publish'].is_a? Array opts['publish'].each do |port| flags << "--publish #{port}" diff --git a/manifests/services.pp b/manifests/services.pp index 937a4a1b..5ea908fe 100644 --- a/manifests/services.pp +++ b/manifests/services.pp @@ -68,7 +68,11 @@ # defaults to undef # # [*mounts*] -# Allows attacking filesystem mounts to the service (specified as an array) +# Allows attaching filesystem mounts to the service (specified as an array) +# defaults to [] +# +# [*networks*] +# Allows attaching the service to networks (specified as an array) # defaults to [] # # [*command*] @@ -94,6 +98,7 @@ Variant[String,Array,Undef] $host_socket = undef, Variant[String,Array,Undef] $registry_mirror = undef, Variant[String,Array,Undef] $mounts = undef, + Variant[Array,Undef] $networks = undef, Variant[String,Array,Undef] $command = undef, ){ @@ -138,6 +143,7 @@ host_socket => $host_socket, registry_mirror => $registry_mirror, mounts => $mounts, + networks => $networks, command => $command, }) diff --git a/spec/defines/services_spec.rb b/spec/defines/services_spec.rb index abbbb343..0e257481 100644 --- a/spec/defines/services_spec.rb +++ b/spec/defines/services_spec.rb @@ -22,12 +22,14 @@ 'env' => ['MY_ENV=1', 'MY_ENV2=2'], 'label' => ['com.example.foo="bar"', 'bar=baz'], 'mounts' => ['type=bind,src=/tmp/a,dst=/tmp/a', 'type=bind,src=/tmp/b,dst=/tmp/b,readonly'], + 'networks' => ['overlay'], } } it { is_expected.to compile.with_all_deps } it { should contain_exec('test_service docker service create').with_command(/docker service create/) } it { should contain_exec('test_service docker service create').with_command(/--env MY_ENV=1/) } it { should contain_exec('test_service docker service create').with_command(/--label bar=baz/) } it { should contain_exec('test_service docker service create').with_command(/--mount type=bind,src=\/tmp\/b,dst=\/tmp\/b,readonly/) } + it { should contain_exec('test_service docker service create').with_command(/--network overlay/) } context 'multiple services declaration' do let(:pre_condition) { @@ -42,18 +44,21 @@ it { should contain_exec('test_service_2 docker service create').with_command(/docker service create/) } end - context 'multiple publish ports' do + context 'multiple publish ports and multiple networks' do let(:pre_condition) { " docker::services { 'test_service_3': service_name => 'foo_3', image => 'foo:bar', publish => ['80:8080', '9000:9000' ], + networks => ['foo_1', 'foo_2'], } " } it { should contain_exec('test_service_3 docker service create').with_command(/--publish 80:8080/) } it { should contain_exec('test_service_3 docker service create').with_command(/--publish 9000:9000/) } + it { should contain_exec('test_service_3 docker service create').with_command(/--network foo_1/) } + it { should contain_exec('test_service_3 docker service create').with_command(/--network foo_2/) } end end From fb2d756fcb582b8aefcca29031dfb7905c952bc3 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 11 Mar 2019 12:16:16 +0100 Subject: [PATCH 5/9] Docker::Services:: fix command parameter used with an array (#452) The module previously allowed specifying the command parameter to docker::services as an array, but did not correctly parse it as such (output with square brackets and quotations marks to docker). This patch fixes this behavior. --- README.md | 3 ++- lib/puppet/parser/functions/docker_service_flags.rb | 4 +++- spec/defines/services_spec.rb | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7fe68d37..8128232a 100755 --- a/README.md +++ b/README.md @@ -801,10 +801,11 @@ docker::services {'redis': replicas => '5', mounts => ['type=bind,source=/etc/my-redis.conf,target=/etc/redis/redis.conf,readonly'], extra_params => ['--update-delay 1m', '--restart-window 30s'], + command => ['redis-server', '--appendonly', 'yes'], } ``` -To base the service off an image, include the `image` parameter and include the `publish` parameter to expose the service port (use an array to specify multiple published ports). To set the amount of containers running in the service, include the `replicas` parameter. To attach one or multiple filesystems to the service, use the `mounts` parameter. For information regarding the `extra_params` parameter, see `docker service create --help`. +To base the service off an image, include the `image` parameter and include the `publish` parameter to expose the service port (use an array to specify multiple published ports). To set the amount of containers running in the service, include the `replicas` parameter. To attach one or multiple filesystems to the service, use the `mounts` parameter. For information regarding the `extra_params` parameter, see `docker service create --help`. The `command` parameter can either be specified as an array or a string. To update the service, add the following code to the manifest file: diff --git a/lib/puppet/parser/functions/docker_service_flags.rb b/lib/puppet/parser/functions/docker_service_flags.rb index bd467ba2..e9148b5e 100644 --- a/lib/puppet/parser/functions/docker_service_flags.rb +++ b/lib/puppet/parser/functions/docker_service_flags.rb @@ -84,7 +84,9 @@ module Puppet::Parser::Functions flags << "'#{opts['image']}'" end - if opts['command'] && opts['command'].to_s != 'undef' + if opts['command'].is_a? Array + flags << opts['command'].join(' ') + elsif opts['command'] && opts['command'].to_s != 'undef' flags << opts['command'].to_s end diff --git a/spec/defines/services_spec.rb b/spec/defines/services_spec.rb index 0e257481..e35fdff3 100644 --- a/spec/defines/services_spec.rb +++ b/spec/defines/services_spec.rb @@ -23,6 +23,7 @@ 'label' => ['com.example.foo="bar"', 'bar=baz'], 'mounts' => ['type=bind,src=/tmp/a,dst=/tmp/a', 'type=bind,src=/tmp/b,dst=/tmp/b,readonly'], 'networks' => ['overlay'], + 'command' => 'echo hello world', } } it { is_expected.to compile.with_all_deps } it { should contain_exec('test_service docker service create').with_command(/docker service create/) } @@ -30,6 +31,7 @@ it { should contain_exec('test_service docker service create').with_command(/--label bar=baz/) } it { should contain_exec('test_service docker service create').with_command(/--mount type=bind,src=\/tmp\/b,dst=\/tmp\/b,readonly/) } it { should contain_exec('test_service docker service create').with_command(/--network overlay/) } + it { should contain_exec('test_service docker service create').with_command(/echo hello world/) } context 'multiple services declaration' do let(:pre_condition) { @@ -37,11 +39,13 @@ docker::services { 'test_service_2': service_name => 'foo_2', image => 'foo:bar', + command => ['echo', 'hello', 'world'], } " } it { should contain_exec('test_service docker service create').with_command(/docker service create/) } it { should contain_exec('test_service_2 docker service create').with_command(/docker service create/) } + it { should contain_exec('test_service_2 docker service create').with_command(/echo hello world/) } end context 'multiple publish ports and multiple networks' do @@ -60,6 +64,7 @@ it { should contain_exec('test_service_3 docker service create').with_command(/--network foo_1/) } it { should contain_exec('test_service_3 docker service create').with_command(/--network foo_2/) } end + end context 'with ensure => present and service update' do From 1352bb63d676d30d041d10aede106a2815922b33 Mon Sep 17 00:00:00 2001 From: davejrt <2067825+davejrt@users.noreply.github.com> Date: Mon, 11 Mar 2019 08:27:47 -0500 Subject: [PATCH 6/9] making dependency ranges more logical (#453) --- metadata.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/metadata.json b/metadata.json index 9cada146..2f1c2d8d 100755 --- a/metadata.json +++ b/metadata.json @@ -10,23 +10,23 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.24.0 <= 5.1.0" + "version_requirement": ">= 4.24.0 < 6.0.0" }, { "name": "puppetlabs/apt", - "version_requirement": ">= 4.4.1 <= 6.2.1" + "version_requirement": ">= 4.4.1 < 7.0.0" }, { "name": "puppetlabs/translate", - "version_requirement": ">= 0.0.1 <=1.2.0" + "version_requirement": ">= 0.0.1 < 2.0.0" }, { "name": "puppetlabs/powershell", - "version_requirement": ">= 2.1.4 <= 2.2.0" + "version_requirement": ">= 2.1.4 < 3.0.0" }, { "name": "puppetlabs/reboot", - "version_requirement": ">=2.0.0 <= 2.1.2" + "version_requirement": ">=2.0.0 < 3.0.0" } ], "operatingsystem_support": [ From c8b59023dacf06bbb3f5e692f09f2793cd55b829 Mon Sep 17 00:00:00 2001 From: davejrt <2067825+davejrt@users.noreply.github.com> Date: Tue, 12 Mar 2019 08:07:49 -0500 Subject: [PATCH 7/9] adding in capability to attach multiple networks to container (#451) --- README.md | 2 +- lib/puppet/parser/functions/docker_run_flags.rb | 2 +- manifests/run.pp | 16 +++++++++++----- spec/defines/run_spec.rb | 8 +++++++- templates/docker-run-start.erb | 5 +++++ 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8128232a..aa36fef6 100755 --- a/README.md +++ b/README.md @@ -379,7 +379,7 @@ docker::run { 'helloworld': ports => ['4444', '4555'], expose => ['4666', '4777'], links => ['mysql:db'], - net => 'my-user-def-net', + net => ['my-user-def-net','my-user-def-net-2], disable_network => false, volumes => ['/var/lib/couchdb', '/var/log'], volumes_from => '6446ea52fbc9', diff --git a/lib/puppet/parser/functions/docker_run_flags.rb b/lib/puppet/parser/functions/docker_run_flags.rb index d69812f9..1e457fda 100644 --- a/lib/puppet/parser/functions/docker_run_flags.rb +++ b/lib/puppet/parser/functions/docker_run_flags.rb @@ -22,7 +22,7 @@ module Puppet::Parser::Functions flags << "--restart '#{opts['restart']}'" end - if opts['net'] + if opts['net'].is_a? String flags << "--net #{opts['net']}" end diff --git a/manifests/run.pp b/manifests/run.pp index 82406f05..b5e0056e 100755 --- a/manifests/run.pp +++ b/manifests/run.pp @@ -49,18 +49,24 @@ # Default: false # # [*health_check_cmd*] -# (optional) Specifies the command to execute to check that the container is healthy using the docker health check functionality. +# (optional) Specifies the command to execute to check that the container is healthy using the docker health check functionality. # Default: undef # # [*health_check_interval*] # (optional) Specifies the interval that the health check command will execute in seconds. -# Default: undef +# Default: undef # # [*restart_on_unhealthy*] # (optional) Checks the health status of Docker container and if it is unhealthy the service will be restarted. # The health_check_cmd parameter must be set to true to use this functionality. # Default: undef # +# [*net*] +# +# The docker network to attach to a container. +# Can be a String or Array (if using multiple networks) +# Default: bridge +# # [*extra_parameters*] # An array of additional command line arguments to pass to the `docker run` # command. Useful for adding additional new or experimental options that the @@ -94,7 +100,7 @@ Optional[Boolean] $use_name = false, Optional[Boolean] $running = true, Variant[String,Array,Undef] $volumes_from = [], - Optional[String] $net = 'bridge', + Variant[String,Array] $net = 'bridge', Variant[String,Boolean] $username = false, Variant[String,Boolean] $hostname = false, Variant[String,Array,Undef] $env = [], @@ -305,7 +311,7 @@ if $running == false { exec { "stop ${title} with docker": command => "${docker_command} stop --time=${stop_wait_time} ${sanitised_title}", - unless => "${docker_command} inspect ${sanitised_title} -f \"{{ if (.State.Running) }} {{ nil }}{{ end }}\"", + unless => "${docker_command} inspect ${sanitised_title} -f \"{{ .State.Running }}\" | grep true", environment => $exec_environment, path => $exec_path, provider => $exec_provider, @@ -314,7 +320,7 @@ } else { exec { "start ${title} with docker": command => "${docker_command} start ${sanitised_title}", - onlyif => "${docker_command} inspect ${sanitised_title} -f \"{{ if (.State.Running) }} {{ nil }}{{ end }}\"", + onlyif => "${docker_command} inspect ${sanitised_title} -f \"{{ .State.Running }}\" | grep false", environment => $exec_environment, path => $exec_path, provider => $exec_provider, diff --git a/spec/defines/run_spec.rb b/spec/defines/run_spec.rb index 1d86c3ad..06119a3a 100755 --- a/spec/defines/run_spec.rb +++ b/spec/defines/run_spec.rb @@ -416,11 +416,17 @@ it { should contain_file(startscript_or_init).with_content(/-v \/var\/log/) } end - context 'when using network mode' do + context 'when using network mode with a single network' do let(:params) { {'command' => 'command', 'image' => 'nginx', 'net' => 'host'} } it { should contain_file(startscript_or_init).with_content(/--net host/) } end + context 'when using network mode with multiple networks' do + let(:params) { {'command' => 'command', 'image' => 'nginx', 'net' => ['host','foo']} } + it { should contain_file(startscript_or_init).with_content(/docker network connect host sample/) } + it { should contain_file(startscript_or_init).with_content(/docker network connect foo sample/) } + end + context 'when `pull_on_start` is true' do let(:params) { {'command' => 'command', 'image' => 'base', 'pull_on_start' => true } } it { should contain_file(startscript_or_init).with_content(/docker pull base/) } diff --git a/templates/docker-run-start.erb b/templates/docker-run-start.erb index 2c19198c..4ae99e8d 100644 --- a/templates/docker-run-start.erb +++ b/templates/docker-run-start.erb @@ -16,5 +16,10 @@ <% if @command %> <%= @command %><% end %> <% if @after_create %><%= @after_create %><% end %> +<% if @net.is_a? Array%> + <% @net.each do |n| %> +/usr/bin/<%= @docker_command %> network connect <%= n %> <%= @sanitised_title %> + <% end %> +<% end %> /usr/bin/<%= @docker_command %> start <% if ! @valid_detach %>-a<% end %> <%= @sanitised_title %> From 84e8edc3f660fe97b170ee6d6c2e3a9b7a422be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Roche?= Date: Wed, 13 Mar 2019 12:28:00 +0100 Subject: [PATCH 8/9] fix(syntax): Remove duplicate parenthesis (#454) --- manifests/plugin.pp | 2 +- manifests/run.pp | 8 ++++---- manifests/services.pp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/manifests/plugin.pp b/manifests/plugin.pp index f3b64571..0eef3636 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -65,7 +65,7 @@ $docker_command = "${docker::params::docker_command} plugin" if ($::osfamily == 'windows') { - fail(translate(('Feature not implemented on windows.'))) + fail(translate('Feature not implemented on windows.')) } if $ensure == 'present' { diff --git a/manifests/run.pp b/manifests/run.pp index b5e0056e..db87c09a 100755 --- a/manifests/run.pp +++ b/manifests/run.pp @@ -158,11 +158,11 @@ } if ($remove_volume_on_start and !$remove_container_on_start) { - fail translate(("In order to remove the volume on start for ${title} you need to also remove the container")) + fail(translate("In order to remove the volume on start for ${title} you need to also remove the container")) } if ($remove_volume_on_stop and !$remove_container_on_stop) { - fail translate(("In order to remove the volume on stop for ${title} you need to also remove the container")) + fail(translate("In order to remove the volume on stop for ${title} you need to also remove the container")) } if $use_name { @@ -352,10 +352,10 @@ } default: { if $::osfamily != 'windows' { - fail translate(('Docker needs a Debian or RedHat based system.')) + fail(translate('Docker needs a Debian or RedHat based system.')) } elsif $ensure == 'present' { - fail translate(('Restart parameter is required for Windows')) + fail(translate('Restart parameter is required for Windows')) } } } diff --git a/manifests/services.pp b/manifests/services.pp index 5ea908fe..b6ea3c3c 100644 --- a/manifests/services.pp +++ b/manifests/services.pp @@ -108,10 +108,10 @@ if $ensure == 'absent' { if $update { - fail translate(('When removing a service you can not update it.')) + fail(translate('When removing a service you can not update it.')) } if $scale { - fail translate(('When removing a service you can not update it.')) + fail(translate('When removing a service you can not update it.')) } } From e59ec60b6ff686732764d52cd51216fe3fe971eb Mon Sep 17 00:00:00 2001 From: davejrt <2067825+davejrt@users.noreply.github.com> Date: Thu, 14 Mar 2019 07:17:08 -0500 Subject: [PATCH 9/9] release 3.5.0 (#458) --- CHANGELOG.md | 12 ++++++++++++ metadata.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80f7b8ff..62ad54b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# 3.5.0 + +Changes range for dependent modules + +Use multiple networks in docker::run and docker::services + +Fixes quotes with docker::services command + +Publish multiple ports to docker::services + +A full list of issues and PRs associated with this release can be found [here](https://github.com/puppetlabs/puppetlabs-docker/milestone/7?closed=1) + # 3.4.0 Introduces docker_stack type and provider diff --git a/metadata.json b/metadata.json index 2f1c2d8d..f3904ccc 100755 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-docker", - "version": "3.4.0", + "version": "3.5.0", "author": "Puppet Labs", "summary": "Module for installing and managing docker", "license": "Apache-2.0",