diff --git a/lib/kitchen/driver/dokken.rb b/lib/kitchen/driver/dokken.rb index 0c57bef..1ad2c2d 100644 --- a/lib/kitchen/driver/dokken.rb +++ b/lib/kitchen/driver/dokken.rb @@ -58,6 +58,7 @@ class Dokken < Kitchen::Driver::Base default_config :memory_limit, 0 default_config :network_mode, "dokken" default_config :pid_one_command, 'sh -c "trap exit 0 SIGTERM; while :; do sleep 1; done"' + default_config :platform, "" default_config :ports, nil default_config :privileged, false default_config :pull_chef_image, true @@ -136,9 +137,9 @@ def docker_connection end def delete_work_image - return unless ::Docker::Image.exist?(work_image, {}, docker_connection) + return unless ::Docker::Image.exist?(work_image, { "platform" => config[:platform] }, docker_connection) - with_retries { @work_image = ::Docker::Image.get(work_image, {}, docker_connection) } + with_retries { @work_image = ::Docker::Image.get(work_image, { "platform" => config[:platform] }, docker_connection) } with_retries do @@ -151,13 +152,14 @@ def delete_work_image def build_work_image(state) info("Building work image..") - return if ::Docker::Image.exist?(work_image, {}, docker_connection) + return if ::Docker::Image.exist?(work_image, { "platform" => config[:platform] }, docker_connection) begin @intermediate_image = ::Docker::Image.build( work_image_dockerfile, { "t" => work_image, + "platform" => config[:platform], }, docker_connection ) @@ -479,7 +481,7 @@ def pull_chef_image end def delete_image(name) - with_retries { @image = ::Docker::Image.get(name, {}, docker_connection) } + with_retries { @image = ::Docker::Image.get(name, { "platform" => config[:platform] }, docker_connection) } with_retries { @image.remove(force: true) } rescue ::Docker::Error puts "Image #{name} not found. Nothing to delete." @@ -551,6 +553,7 @@ def create_container(args) args["Env"] = [] if args["Env"].nil? args["Env"] << "TEST_KITCHEN=1" args["Env"] << "CI=#{ENV["CI"]}" if ENV.include? "CI" + args["Platform"] = config[:platform] info "Creating container #{args["name"]}" debug "driver - create_container args #{args}" with_retries do @@ -612,7 +615,7 @@ def wait_running_state(name, v) end def chef_container_name - "chef-#{chef_version}" + config[:platform] != "" ? "chef-#{chef_version}-" + config[:platform].sub("/", "-") : "chef-#{chef_version}" end def chef_image @@ -643,7 +646,7 @@ def platform_image_from_name end def pull_if_missing(image) - return if ::Docker::Image.exist?(registry_image_path(image), {}, docker_connection) + return if ::Docker::Image.exist?(registry_image_path(image), { "platform" => config[:platform] }, docker_connection) pull_image image end @@ -656,11 +659,11 @@ def parse_registry_host(val) def pull_image(image) path = registry_image_path(image) with_retries do - if Docker::Image.exist?(path, {}, docker_connection) - original_image = Docker::Image.get(path, {}, docker_connection) + if Docker::Image.exist?(path, { "platform" => config[:platform] }, docker_connection) + original_image = Docker::Image.get(path, { "platform" => config[:platform] }, docker_connection) end - new_image = Docker::Image.create({ "fromImage" => path }, docker_creds_for_image(image), docker_connection) + new_image = Docker::Image.create({ "fromImage" => path, "platform" => config[:platform] }, docker_creds, docker_connection) !(original_image && original_image.id.start_with?(new_image.id)) end