Skip to content

Commit

Permalink
Allow a user to specify a specific platform/architecture to use (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrocco authored Dec 22, 2022
1 parent d485440 commit 20ff613
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/kitchen/driver/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
)
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 20ff613

Please sign in to comment.