From 09367b8bc21fb0f0d53a2c11dd71847d0a772149 Mon Sep 17 00:00:00 2001 From: grantholly Date: Mon, 3 Jul 2017 12:43:47 -0700 Subject: [PATCH 1/2] adding a fact to find if the dockerd binary exists to avoid an issue where systemd cannot start contemporary versions of docker with the docker unit file because it calls out the now deprecated `docker dameon` --- lib/facter/dockerd_binary.rb | 5 +++++ .../docker.service.d/service-overrides-debian.conf.erb | 4 ++++ .../docker.service.d/service-overrides-rhel.conf.erb | 7 +++++++ 3 files changed, 16 insertions(+) create mode 100644 lib/facter/dockerd_binary.rb diff --git a/lib/facter/dockerd_binary.rb b/lib/facter/dockerd_binary.rb new file mode 100644 index 000000000..806cfea8f --- /dev/null +++ b/lib/facter/dockerd_binary.rb @@ -0,0 +1,5 @@ +Facter.add(:dockerd_binary) do + setcode do + Facter::Core::Execution.which('dockerd') + end +end 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 e56dabd72..570058e98 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 @@ -2,5 +2,9 @@ EnvironmentFile=-/etc/default/docker EnvironmentFile=-/etc/default/docker-storage ExecStart= +<% unless @dockerd_daemon -%> ExecStart=/usr/bin/<%= @docker_command %> <%= @daemon_subcommand %> $OPTIONS \ $DOCKER_STORAGE_OPTIONS +<% end -%> +ExecStart=/usr/bin/<%= @dockerd_daemon %> $OPTIONS \ + $DOCKER_STORAGE_OPTIONS 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 3d367e9cf..02d7824c8 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 @@ -5,8 +5,15 @@ EnvironmentFile=-/etc/sysconfig/docker-network <% if @daemon_environment_files %><% @daemon_environment_files.each do |param| %>EnvironmentFile=-<%= param %> <% end %><% end -%> ExecStart= +<% unless @dockerd_daemon -%> ExecStart=/usr/bin/<%= @docker_command %> <%= @daemon_subcommand %> $OPTIONS \ $DOCKER_STORAGE_OPTIONS \ $DOCKER_NETWORK_OPTIONS \ $BLOCK_REGISTRY \ $INSECURE_REGISTRY +<% end -%> +ExecStart=<%= @dockerd_daemon %> $OPTIONS \ + $DOCKER_STORAGE_OPTIONS \ + $DOCKER_NETWORK_OPTIONS \ + $BLOCK_REGISTRY \ + $INSECURE_REGISTRY From cc77858192f90d214dbc4ab5dda4e0c1cf8751b2 Mon Sep 17 00:00:00 2001 From: grantholly Date: Wed, 5 Jul 2017 09:26:11 -0700 Subject: [PATCH 2/2] creating a unit test for the dockerd_binary fact --- .fixtures.yml | 12 +++++--- spec/spec_helper.rb | 4 +++ spec/unit/dockerd_daemon_spec.rb | 30 +++++++++++++++++++ .../service-overrides-debian.conf.erb | 4 +-- .../service-overrides-rhel.conf.erb | 4 +-- 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 spec/unit/dockerd_daemon_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml index 9090d28b9..4014e8e32 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,14 @@ fixtures: - forge_modules: - stdlib: 'puppetlabs-stdlib' - epel: 'stahnma-epel' +# forge_modules: +# - 'puppetlabs-stdlib' +# - 'stahnma-epel' repositories: apt: - repo: git://github.com/puppetlabs/puppetlabs-apt.git + repo: https://github.com/puppetlabs/puppetlabs-apt.git ref: 2.1.0 + puppetlabs-stdlib: + repo: https://github.com/puppetlabs/puppetlabs-stdlib + epel: + repo: https://github.com/stahnma/puppet-module-epel symlinks: docker: "#{source_dir}" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bf973048d..8fa3e8a0a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,9 @@ require 'puppetlabs_spec_helper/module_spec_helper' +RSpec.configure do |config| + config.mock_with :rspec +end + RSpec::Matchers.define :require_string_for do |property| match do |type_class| config = {:name => 'name'} diff --git a/spec/unit/dockerd_daemon_spec.rb b/spec/unit/dockerd_daemon_spec.rb new file mode 100644 index 000000000..1f647077f --- /dev/null +++ b/spec/unit/dockerd_daemon_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'dockerd_binary fact' do + + before :each do + Facter.clear + end + + context 'when the dockerd binary is NOT present' do + + before :each do + Facter.fact(:dockerd_binary).stubs(:value).returns(nil) + end + + it 'return nil' do + expect(Facter.fact(:dockerd_binary).value).to be_nil + end + end + + context 'when the dockerd binary is installed' do + + before :each do + Facter.fact(:dockerd_binary).stubs(:value).returns('/some/path/to/dockerd') + end + + it 'return the full path to the dockerd binary' do + expect(Facter.fact(:dockerd_binary).value).to eq('/some/path/to/dockerd') + end + end +end 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 570058e98..e79c8efab 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 @@ -2,9 +2,9 @@ EnvironmentFile=-/etc/default/docker EnvironmentFile=-/etc/default/docker-storage ExecStart= -<% unless @dockerd_daemon -%> +<% unless @dockerd_binary -%> ExecStart=/usr/bin/<%= @docker_command %> <%= @daemon_subcommand %> $OPTIONS \ $DOCKER_STORAGE_OPTIONS <% end -%> -ExecStart=/usr/bin/<%= @dockerd_daemon %> $OPTIONS \ +ExecStart=<%= @dockerd_binary %> $OPTIONS \ $DOCKER_STORAGE_OPTIONS 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 02d7824c8..56956dbed 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 @@ -5,14 +5,14 @@ EnvironmentFile=-/etc/sysconfig/docker-network <% if @daemon_environment_files %><% @daemon_environment_files.each do |param| %>EnvironmentFile=-<%= param %> <% end %><% end -%> ExecStart= -<% unless @dockerd_daemon -%> +<% unless @dockerd_binary -%> ExecStart=/usr/bin/<%= @docker_command %> <%= @daemon_subcommand %> $OPTIONS \ $DOCKER_STORAGE_OPTIONS \ $DOCKER_NETWORK_OPTIONS \ $BLOCK_REGISTRY \ $INSECURE_REGISTRY <% end -%> -ExecStart=<%= @dockerd_daemon %> $OPTIONS \ +ExecStart=<%= @dockerd_binary %> $OPTIONS \ $DOCKER_STORAGE_OPTIONS \ $DOCKER_NETWORK_OPTIONS \ $BLOCK_REGISTRY \