From e261b6f728d5bfceb9a98d5e35b29915afd49035 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 14 Jul 2022 11:38:22 +0000 Subject: [PATCH] Get docker working in the test-kitchen environment --- cookbooks/docker/recipes/default.rb | 8 +++++++- cookbooks/docker/templates/default/daemon.json.erb | 2 +- test/integration/docker/serverspec/docker_spec.rb | 13 +++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/integration/docker/serverspec/docker_spec.rb diff --git a/cookbooks/docker/recipes/default.rb b/cookbooks/docker/recipes/default.rb index 80fd15b3f..bfdc88a09 100644 --- a/cookbooks/docker/recipes/default.rb +++ b/cookbooks/docker/recipes/default.rb @@ -31,15 +31,21 @@ directory "/etc/docker" do mode "755" end +storage_driver = if kitchen? + "vfs" + else + "overlay2" + end + template "/etc/docker/daemon.json" do source "daemon.json.erb" owner "root" group "root" mode "644" + variables :storage_driver => storage_driver end service "docker" do action [:enable, :start] subscribes :restart, "template[/etc/docker/daemon.json]" - not_if { kitchen? } end diff --git a/cookbooks/docker/templates/default/daemon.json.erb b/cookbooks/docker/templates/default/daemon.json.erb index 5d18abccd..15f9d2eb2 100644 --- a/cookbooks/docker/templates/default/daemon.json.erb +++ b/cookbooks/docker/templates/default/daemon.json.erb @@ -4,5 +4,5 @@ "log-opts": { "max-size": "100m" }, - "storage-driver": "overlay2" + "storage-driver": "<%= @storage_driver %>" } diff --git a/test/integration/docker/serverspec/docker_spec.rb b/test/integration/docker/serverspec/docker_spec.rb new file mode 100644 index 000000000..de7c426d2 --- /dev/null +++ b/test/integration/docker/serverspec/docker_spec.rb @@ -0,0 +1,13 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("docker-ce") do + it { should be_installed } +end + +describe service("docker") do + it { should be_enabled } + it { should be_running } +end -- 2.39.5