Skip to content

Commit

Permalink
Run chefstlye over the codebase (#408)
Browse files Browse the repository at this point in the history
- Run chefstyle
- Move development dependencies into the Gemfile
- Remove tailor and cane which are no longer maintained

Signed-off-by: Dan Webb <dan.webb@damacus.io>
  • Loading branch information
damacus authored Nov 25, 2023
1 parent d4b08cd commit a9995e7
Show file tree
Hide file tree
Showing 23 changed files with 297 additions and 323 deletions.
Empty file removed .cane
Empty file.
4 changes: 0 additions & 4 deletions .tailor

This file was deleted.

19 changes: 19 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
source 'https://rubygems.org'

gemspec

group :development do
gem 'bundler'
gem 'rake'
# Style checker gems.
gem 'countloc'

# Unit testing gems.
gem 'rspec', '~> 3.2'
gem 'rspec-its', '~> 1.2'
gem 'fuubar', '~> 2.0'
# gem 'simplecov', '~> 0.9'
gem 'codecov', '~> 0.0', '>= 0.0.2'
gem 'chefstyle', '~> 2.2', '>= 2.2.3'

# Integration testing gems.
gem 'kitchen-inspec', '~> 2.0'
gem 'train', '>= 2.1', '< 4.0' # validate 4.x when it's released
end
34 changes: 9 additions & 25 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
require "bundler/gem_tasks"
require 'cane/rake_task'
require 'tailor/rake_task'

desc "Run cane to check quality metrics"
Cane::RakeTask.new do |cane|
cane.canefile = './.cane'
end

Tailor::RakeTask.new

desc "Display LOC stats"
task :stats do
Expand All @@ -16,27 +7,20 @@ task :stats do
end

desc "Run all quality tasks"
task :quality => [:cane, :tailor, :stats]

task :default => [:quality]
task quality: [:stats]

# begin
# require 'kitchen/rake_tasks'
# Kitchen::RakeTasks.new
# rescue LoadError
# puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
# end
task default: [:quality]

# Create the spec task.
require 'rspec/core/rake_task'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec, :tag) do |t, args|
t.rspec_opts = [].tap do |a|
a << '--color'
a << "--format #{ENV['CI'] ? 'documentation' : 'Fuubar'}"
a << '--backtrace' if ENV['VERBOSE'] || ENV['DEBUG']
a << "--seed #{ENV['SEED']}" if ENV['SEED']
a << "--color"
a << "--format #{ENV["CI"] ? "documentation" : "Fuubar"}"
a << "--backtrace" if ENV["VERBOSE"] || ENV["DEBUG"]
a << "--seed #{ENV["SEED"]}" if ENV["SEED"]
a << "--tag #{args[:tag]}" if args[:tag]
a << "--default-path test"
a << '-I test/spec'
end.join(' ')
a << "-I test/spec"
end.join(" ")
end
38 changes: 9 additions & 29 deletions kitchen-docker.gemspec
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'kitchen/docker/docker_version'
require "kitchen/docker/docker_version"

Gem::Specification.new do |spec|
spec.name = 'kitchen-docker'
spec.name = "kitchen-docker"
spec.version = Kitchen::Docker::DOCKER_VERSION
spec.authors = ['Sean Porter']
spec.email = ['portertech@gmail.com']
spec.authors = ["Sean Porter"]
spec.email = ["portertech@gmail.com"]
spec.description = %q{A Docker Driver for Test Kitchen}
spec.summary = spec.description
spec.homepage = 'https://github.com/test-kitchen/kitchen-docker'
spec.license = 'Apache 2.0'
spec.homepage = "https://github.com/test-kitchen/kitchen-docker"
spec.license = "Apache 2.0"

spec.files = `git ls-files`.split($/)
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.add_dependency 'test-kitchen', '>= 1.0.0'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'

# Style checker gems.
spec.add_development_dependency 'cane'
spec.add_development_dependency 'tailor'
spec.add_development_dependency 'countloc'

# Unit testing gems.
spec.add_development_dependency 'rspec', '~> 3.2'
spec.add_development_dependency 'rspec-its', '~> 1.2'
spec.add_development_dependency 'fuubar', '~> 2.0'
spec.add_development_dependency 'simplecov', '~> 0.9'
spec.add_development_dependency 'codecov', '~> 0.0', '>= 0.0.2'
spec.add_development_dependency 'chefstyle'

# Integration testing gems.
spec.add_development_dependency 'kitchen-inspec', '~> 2.0'
spec.add_development_dependency 'train', '>= 2.1', '< 4.0' # validate 4.x when it's released
spec.add_dependency "test-kitchen", ">= 1.0.0", "< 4.0"
end
6 changes: 3 additions & 3 deletions lib/docker/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# limitations under the License.

begin
require 'docker'
require "docker"

# Override API_VERSION constant in docker-api gem to use version 1.24 of the Docker API
# This override is for the docker-api gem to communicate to the Docker engine on Windows
module Docker
VERSION = '0.0.0'
API_VERSION = '1.24'
VERSION = "0.0.0".freeze
API_VERSION = "1.24".freeze
end
rescue LoadError => e
logger.debug("[Docker] docker-api gem not found for InSpec verifier. #{e}")
Expand Down
12 changes: 6 additions & 6 deletions lib/kitchen/docker/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative 'helpers/cli_helper'
require_relative 'helpers/container_helper'
require_relative 'helpers/file_helper'
require_relative 'helpers/image_helper'
require_relative "helpers/cli_helper"
require_relative "helpers/container_helper"
require_relative "helpers/file_helper"
require_relative "helpers/image_helper"

module Kitchen
module Docker
Expand All @@ -33,7 +33,7 @@ def create(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, "\
'but the container does not exist.'
"but the container does not exist."
end

state[:username] = @config[:username]
Expand All @@ -49,7 +49,7 @@ def destroy(state)
end

def hostname(state)
hostname = 'localhost'
hostname = "localhost"

if remote_socket?
hostname = socket_uri.host
Expand Down
34 changes: 17 additions & 17 deletions lib/kitchen/docker/container/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'base64'
require 'openssl'
require 'securerandom'
require 'shellwords'
require "base64" unless defined?(Base64)
require "openssl" unless defined?(OpenSSL)
require "securerandom" unless defined?(SecureRandom)
require "shellwords" unless defined?(Shellwords)

require_relative '../container'
require_relative '../helpers/dockerfile_helper'
require_relative "../container"
require_relative "../helpers/dockerfile_helper"

module Kitchen
module Docker
Expand All @@ -34,7 +34,7 @@ def initialize(config)
def create(state)
super

debug('Creating Linux container')
debug("Creating Linux container")
generate_keys

state[:ssh_key] = @config[:private_key]
Expand All @@ -58,7 +58,7 @@ def execute(command)
debug("Uploading temp file #{temp_file} to #{remote_path} on container")
upload(temp_file, remote_path)

debug('Deleting temp file from local filesystem')
debug("Deleting temp file from local filesystem")
::File.delete(temp_file)

# Replace any environment variables used in the path and execute script file
Expand All @@ -76,13 +76,13 @@ def generate_keys
MUTEX_FOR_SSH_KEYS.synchronize do
if !File.exist?(@config[:public_key]) || !File.exist?(@config[:private_key])
private_key = OpenSSL::PKey::RSA.new(2048)
blobbed_key = Base64.encode64(private_key.to_blob).gsub("\n", '')
blobbed_key = Base64.encode64(private_key.to_blob).gsub("\n", "")
public_key = "ssh-rsa #{blobbed_key} kitchen_docker_key"
File.open(@config[:private_key], 'w') do |file|
File.open(@config[:private_key], "w") do |file|
file.write(private_key)
file.chmod(0600)
end
File.open(@config[:public_key], 'w') do |file|
File.open(@config[:public_key], "w") do |file|
file.write(public_key)
file.chmod(0600)
end
Expand All @@ -91,7 +91,7 @@ def generate_keys
end

def parse_container_ssh_port(output)
_host, port = output.split(':')
_host, port = output.split(":")
port.to_i
rescue => e
raise ActionFailed, "Could not parse Docker port output for container SSH port. #{e}"
Expand All @@ -113,21 +113,21 @@ def dockerfile
platform = dockerfile_platform
username = @config[:username]
public_key = IO.read(@config[:public_key]).strip
homedir = username == 'root' ? '/root' : "/home/#{username}"
homedir = username == "root" ? "/root" : "/home/#{username}"
base = dockerfile_base_linux(username, homedir)

custom = ''
custom = ""
Array(@config[:provision_command]).each do |cmd|
custom << "RUN #{cmd}\n"
end

ssh_key = "RUN echo #{Shellwords.escape(public_key)} >> #{homedir}/.ssh/authorized_keys"

# Empty string to ensure the file ends with a newline.
output = [from, dockerfile_proxy_config, platform, base, custom, ssh_key, ''].join("\n")
debug('--- Start Dockerfile ---')
output = [from, dockerfile_proxy_config, platform, base, custom, ssh_key, ""].join("\n")
debug("--- Start Dockerfile ---")
debug(output.strip)
debug('--- End Dockerfile ---')
debug("--- End Dockerfile ---")
output
end
end
Expand Down
22 changes: 11 additions & 11 deletions lib/kitchen/docker/container/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'securerandom'
require "securerandom" unless defined?(SecureRandom)

require_relative '../container'
require_relative "../container"

module Kitchen
module Docker
Expand All @@ -26,7 +26,7 @@ def initialize(config)
def create(state)
super

debug('Creating Windows container')
debug("Creating Windows container")
state[:username] = @config[:username]
state[:image_id] = build_image(state, dockerfile) unless state[:image_id]
state[:container_id] = run_container(state) unless state[:container_id]
Expand All @@ -35,19 +35,19 @@ def create(state)

def execute(command)
# Create temp script file and upload files to container
debug('Executing command on Windows container')
debug("Executing command on Windows container")
filename = "docker-#{::SecureRandom.uuid}.ps1"
temp_file = ".\\.kitchen\\temp\\#{filename}"
create_temp_file(temp_file, command)

remote_path = @config[:temp_dir].tr('/', '\\')
remote_path = @config[:temp_dir].tr("/", "\\")
debug("Creating directory #{remote_path} on container")
create_dir_on_container(@config, remote_path)

debug("Uploading temp file #{temp_file} to #{remote_path} on container")
upload(temp_file, remote_path)

debug('Deleting temp file from local filesystem')
debug("Deleting temp file from local filesystem")
::File.delete(temp_file)

# Replace any environment variables used in the path and execute script file
Expand All @@ -63,20 +63,20 @@ def execute(command)
protected

def dockerfile
raise ActionFailed, "Unknown platform '#{@config[:platform]}'" unless @config[:platform] == 'windows'
raise ActionFailed, "Unknown platform '#{@config[:platform]}'" unless @config[:platform] == "windows"
return dockerfile_template if @config[:dockerfile]

from = "FROM #{@config[:image]}"

custom = ''
custom = ""
Array(@config[:provision_command]).each do |cmd|
custom << "RUN #{cmd}\n"
end

output = [from, dockerfile_proxy_config, custom, ''].join("\n")
debug('--- Start Dockerfile ---')
output = [from, dockerfile_proxy_config, custom, ""].join("\n")
debug("--- Start Dockerfile ---")
debug(output.strip)
debug('--- End Dockerfile ---')
debug("--- End Dockerfile ---")
output
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/docker/docker_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
module Kitchen
module Docker
# Version string for Docker Kitchen driver
DOCKER_VERSION = "3.0.0"
DOCKER_VERSION = "3.0.0".freeze
end
end
6 changes: 3 additions & 3 deletions lib/kitchen/docker/erb_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'erb'
require "erb" unless defined?(Erb)

module Kitchen
module Docker
class ERBContext
def initialize(config={})
def initialize(config = {})
config.each do |key, value|
instance_variable_set('@' + key.to_s, value)
instance_variable_set("@" + key.to_s, value)
end
end

Expand Down
Loading

0 comments on commit a9995e7

Please sign in to comment.