From 0b819246bc3b10d52e8b3f3991212cf3ac875be7 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Sun, 9 Nov 2025 21:49:34 +0000 Subject: [PATCH 1/3] fix: resolve gemspec load path and refactor proxy config method - Change File.expand_path to use __dir__ instead of __FILE__ in gemspec to properly resolve the lib directory path - Extract repetitive proxy environment variable logic into separate proxy_env_vars helper method - Reduce dockerfile_proxy_config ABC size from 24.21 to below threshold - Reduce method length from 14 lines to 4 lines to meet style guidelines Signed-off-by: Dan Webb --- .rubocop.yml | 3 ++- Gemfile | 4 +-- kitchen-docker.gemspec | 2 +- lib/kitchen/docker/container.rb | 2 +- .../docker/helpers/container_helper.rb | 25 +++++++------------ lib/kitchen/docker/helpers/image_helper.rb | 4 +-- lib/kitchen/driver/docker.rb | 2 +- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 46802c5..ea9207d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ +--- require: - - chefstyle + - cookstyle/chefstyle AllCops: TargetRubyVersion: 3.1 diff --git a/Gemfile b/Gemfile index 6e83677..23d7d04 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,6 @@ group :test do gem 'rspec-its', '~> 2.0' end -group :chefstyle do - gem 'chefstyle', '~> 2.2', '>= 2.2.3' +group :cookstyle do + gem "cookstyle" end diff --git a/kitchen-docker.gemspec b/kitchen-docker.gemspec index 7c813c2..86e7e39 100644 --- a/kitchen-docker.gemspec +++ b/kitchen-docker.gemspec @@ -1,4 +1,4 @@ -lib = File.expand_path("lib", __FILE__) +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "kitchen/docker/docker_version" diff --git a/lib/kitchen/docker/container.rb b/lib/kitchen/docker/container.rb index af78ba3..26a9955 100644 --- a/lib/kitchen/docker/container.rb +++ b/lib/kitchen/docker/container.rb @@ -32,7 +32,7 @@ def create(state) if container_exists?(state) info("Container ID #{state[:container_id]} already exists.") elsif !container_exists?(state) && state[:container_id] - raise ActionFailed, "Container ID #{state[:container_id]} was found in the kitchen state data, "\ + raise ActionFailed, "Container ID #{state[:container_id]} was found in the kitchen state data, " \ "but the container does not exist." end diff --git a/lib/kitchen/docker/helpers/container_helper.rb b/lib/kitchen/docker/helpers/container_helper.rb index d5309d7..a4196a1 100644 --- a/lib/kitchen/docker/helpers/container_helper.rb +++ b/lib/kitchen/docker/helpers/container_helper.rb @@ -74,7 +74,7 @@ def create_dir_on_container(state, path) cmd = "mkdir -p #{path}" if state[:platform].include?("windows") - psh = "-Command if(-not (Test-Path \'#{path}\')) { New-Item -Path \'#{path}\' -Force }" + psh = "-Command if(-not (Test-Path '#{path}')) { New-Item -Path '#{path}' -Force }" cmd = build_powershell_command(psh) end @@ -151,23 +151,16 @@ def remove_container(state) end def dockerfile_proxy_config - env_variables = "" - if config[:http_proxy] - env_variables << "ENV http_proxy=#{config[:http_proxy]}\n" - env_variables << "ENV HTTP_PROXY=#{config[:http_proxy]}\n" - end - - if config[:https_proxy] - env_variables << "ENV https_proxy=#{config[:https_proxy]}\n" - env_variables << "ENV HTTPS_PROXY=#{config[:https_proxy]}\n" - end + %i{http_proxy https_proxy no_proxy}.map do |proxy_type| + proxy_env_vars(proxy_type) + end.join + end - if config[:no_proxy] - env_variables << "ENV no_proxy=#{config[:no_proxy]}\n" - env_variables << "ENV NO_PROXY=#{config[:no_proxy]}\n" - end + def proxy_env_vars(proxy_type) + return "" unless config[proxy_type] - env_variables + value = config[proxy_type] + "ENV #{proxy_type}=#{value}\nENV #{proxy_type.upcase}=#{value}\n" end end # rubocop:enable Metrics/ModuleLength, Style/Documentation diff --git a/lib/kitchen/docker/helpers/image_helper.rb b/lib/kitchen/docker/helpers/image_helper.rb index ffa0167..95b0d41 100644 --- a/lib/kitchen/docker/helpers/image_helper.rb +++ b/lib/kitchen/docker/helpers/image_helper.rb @@ -72,8 +72,8 @@ def build_image(state, dockerfile) file.write(dockerfile) file.close docker_command("#{cmd} #{build_context}", - input: dockerfile_contents, - environment: { BUILDKIT_PROGRESS: "plain" }) + input: dockerfile_contents, + environment: { BUILDKIT_PROGRESS: "plain" }) ensure file.close unless file.closed? file.unlink diff --git a/lib/kitchen/driver/docker.rb b/lib/kitchen/driver/docker.rb index 84a3941..3741920 100644 --- a/lib/kitchen/driver/docker.rb +++ b/lib/kitchen/driver/docker.rb @@ -90,7 +90,7 @@ class Docker < Kitchen::Driver::Base "ping -t localhost" end else - "/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes "\ + "/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes " \ "-o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid" end end From 8f548579d28a2995a3a42677761c81b0be30786d Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Sun, 9 Nov 2025 21:51:30 +0000 Subject: [PATCH 2/3] Update workflow Signed-off-by: Dan Webb --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e8cb27..a857b75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ name: Lint & Unit jobs: lint-unit: - uses: test-kitchen/.github/.github/workflows/lint-unit.yml@v0.1.2 + uses: test-kitchen/.github/.github/workflows/lint-unit.yml@v0.2.3 integration-windows: name: Windows ${{matrix.suite}} ${{matrix.os}} From ee7211a0da073ac8f12d17f7aca4aa06193b9210 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Sun, 9 Nov 2025 21:54:56 +0000 Subject: [PATCH 3/3] SQUASHME Signed-off-by: Dan Webb --- Gemfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 23d7d04..dd70e12 100644 --- a/Gemfile +++ b/Gemfile @@ -1,19 +1,19 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec group :development do - gem 'kitchen-inspec', '~> 2.0' - gem 'train', '>= 2.1', '< 4.0' # validate 4.x when it's released + gem "kitchen-inspec", "~> 2.0" + gem "train", ">= 2.1", "< 4.0" # validate 4.x when it's released end group :test do - gem 'bundler' - gem 'rake' - gem 'rspec', '~> 3.2' - gem 'rspec-its', '~> 2.0' + gem "bundler" + gem "rake" + gem "rspec", "~> 3.2" + gem "rspec-its", "~> 2.0" end -group :cookstyle do +group :chefstyle do gem "cookstyle" end