diff --git a/README.md b/README.md index e0a168b..3a36fa1 100644 --- a/README.md +++ b/README.md @@ -596,6 +596,20 @@ Examples: use_internal_docker_network: true ``` +### docker_platform + +Configure the CPU platform (architecture) used by docker to build the image. + +Examples: + +```yaml + docker_platform: linux/arm64 +``` + +```yaml + docker_platform: linux/amd64 +``` + ## Development * Source hosted at [GitHub][repo] diff --git a/lib/kitchen/docker/helpers/cli_helper.rb b/lib/kitchen/docker/helpers/cli_helper.rb index a3c4fc8..1da52bb 100644 --- a/lib/kitchen/docker/helpers/cli_helper.rb +++ b/lib/kitchen/docker/helpers/cli_helper.rb @@ -84,6 +84,7 @@ def build_run_command(image_id, transport_port = nil) Array(config[:cap_add]).each { |cap| cmd << " --cap-add=#{cap}"} if config[:cap_add] Array(config[:cap_drop]).each { |cap| cmd << " --cap-drop=#{cap}"} if config[:cap_drop] Array(config[:security_opt]).each { |opt| cmd << " --security-opt=#{opt}"} if config[:security_opt] + cmd << " --platform=#{config[:docker_platform]}" if config[:docker_platform] extra_run_options = config_to_options(config[:run_options]) cmd << " #{extra_run_options}" unless extra_run_options.empty? cmd << " #{image_id} #{config[:run_command]}" diff --git a/lib/kitchen/docker/helpers/image_helper.rb b/lib/kitchen/docker/helpers/image_helper.rb index 884f609..48e3418 100644 --- a/lib/kitchen/docker/helpers/image_helper.rb +++ b/lib/kitchen/docker/helpers/image_helper.rb @@ -46,6 +46,7 @@ def remove_image(state) def build_image(state, dockerfile) cmd = 'build' cmd << ' --no-cache' unless config[:use_cache] + cmd << " --platform=#{config[:docker_platform]}" if config[:docker_platform] extra_build_options = config_to_options(config[:build_options]) cmd << " #{extra_build_options}" unless extra_build_options.empty? dockerfile_contents = dockerfile