Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ jobs:
bundle exec bundle exec kitchen create hello
bundle exec bundle exec kitchen test helloagain
bundle exec bundle exec kitchen destroy hello
env:
# This needs to be set for all phases, including the verify phase
CHEF_LICENSE: "accept"
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ group :test do
gem "berkshelf"
gem "kitchen-inspec"
gem "rake", ">= 11.0"
gem "rspec", "~> 3.0"
end

group :development do
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ $ kitchen create
-----> Kitchen is finished. (0m21.95s)
```

The `kitchen create` phase of the kitchen run pulls (if missing) the `chef/chef` image from the Docker hub, then creates a volume container named `chef-<version>`. This makes `/opt/chef` available for mounting by other containers.
The `kitchen create` phase of the kitchen run pulls (if missing) the `cincproject/cinc` image from the Docker hub, then creates a volume container named `chef-<version>`. This makes `/opt/chef` available for mounting by other containers.

When talking to a local Docker host (over a socket), the driver creates and bind mounts a sandbox directory to `/opt/kitchen`. This prevents us from having to "upload" the test data.

Expand All @@ -107,7 +107,7 @@ Finally, the driver pulls the image specified by the suite's platform section an
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3489588d4470 6e1b03ab46-default-centos-7:latest "sh -c 'trap exit ..." About a minute ago Up About a minute 6e1b03ab46-default-centos-7
f678882b1575 chef/chef:current "true" About a minute ago Created chef-current
f678882b1575 cincproject/cinc:current "true" About a minute ago Created chef-current
```

#### List images
Expand All @@ -116,7 +116,7 @@ f678882b1575 chef/chef:current "true"
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
6e1b03ab46-default-centos-7 latest 2ea1040b9c10 About a minute ago 192 MB
chef/chef current 01ec788610e2 6 days ago 124 MB
cincproject/cinc current 01ec788610e2 6 days ago 124 MB
centos 7 67591570dd29 7 weeks ago 192 MB
```

Expand Down Expand Up @@ -174,7 +174,7 @@ $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c153dfd8e53d e9fa5d3a0d0e "sh -c 'trap exit 0 S" 9 minutes ago Up 9 minutes default-centos-7
32c42fba4a8c someara/kitchen-cache:latest "/usr/sbin/sshd -D -p" 9 minutes ago Up 9 minutes 0.0.0.0:32846->22/tcp default-centos-7-data
7e327add6bf2 chef/chef:12.5.1 "true" 17 minutes ago Created chef-12.5.1
7e327add6bf2 cincproject/cinc:12.5.1 "true" 17 minutes ago Created chef-12.5.1
```

#### List images
Expand All @@ -184,7 +184,7 @@ $ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
default-centos-7 latest ec1d208d77cd 8 minutes ago 172.3 MB
someara/kitchen-cache latest abbdb063dff1 2 weeks ago 300.8 MB
chef/chef 12.5.1 86245605bbe3 4 weeks ago 168.1 MB
cincproject/cinc 12.5.1 86245605bbe3 4 weeks ago 168.1 MB
centos 7 e9fa5d3a0d0e 6 weeks ago 172.3 MB
```

Expand Down Expand Up @@ -244,7 +244,7 @@ The `kitchen-verify` phase uses the transport to run acceptance tests, verifying
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
84def4c49ce3 6e1b03ab46-default-centos-7:latest "sh -c 'trap exit ..." 6 minutes ago Up 6 minutes 6e1b03ab46-default-centos-7
f678882b1575 chef/chef:current "true" 9 minutes ago Created chef-current
f678882b1575 cincproject/cinc:current "true" 9 minutes ago Created chef-current
```

#### List images
Expand All @@ -253,7 +253,7 @@ f678882b1575 chef/chef:current "true"
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
6e1b03ab46-default-centos-7 latest fec1a50470ed 6 minutes ago 192 MB
chef/chef current 01ec788610e2 6 days ago 124 MB
cincproject/cinc current 01ec788610e2 6 days ago 124 MB
centos 7 67591570dd29 7 weeks ago 192 MB
```

Expand All @@ -275,15 +275,15 @@ $ kitchen destroy
```shell
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f678882b1575 chef/chef:current "true" 10 minutes ago Created chef-current
f678882b1575 cincproject/cinc:current "true" 10 minutes ago Created chef-current
```

#### List images

```shell
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chef/chef current 01ec788610e2 6 days ago 124 MB
cincproject/cinc current 01ec788610e2 6 days ago 124 MB
centos 7 67591570dd29 7 weeks ago 192 MB
```

Expand Down Expand Up @@ -493,17 +493,17 @@ verifier:

### Install Chef Infra Client from current channel

Chef publishes all functioning builds to the [Docker Hub](https://hub.docker.com/r/chef/chef/tags),
including those from the "current" channel. If you wish to use pre-release versions of Chef, set your `chef_version` value to "current". If you need to test older versions of `chef-client` that are not available on docker hub as `chef/chef`, you can overwrite `chef_image` under the [driver context](https://github.com/test-kitchen/kitchen-dokken/blob/2.5.1/lib/kitchen/driver/dokken.rb#L40) to a custom image name such as `someara/chef`.
Cinc publishes all functioning builds to the [Docker Hub](https://hub.docker.com/r/cincproject/cinc/tags),
including those from the "current" channel. If you wish to use pre-release versions of Cinc, set your `chef_version` value to "current". If you need to test older versions of `chef-client` that are not available on docker hub as `cincproject/cinc`, you can overwrite `chef_image` under the [driver context](https://github.com/test-kitchen/kitchen-dokken/blob/2.5.1/lib/kitchen/driver/dokken.rb#L40) to a custom image name such as `chef/chef`.

### Chef Infra Client options
### Cinc/Chef Infra Client options

It is possible to pass several extra configs to configure the chef binary and options, for example
to use older versions that do not have the "-z" switch or to get some debug logging.

```yaml
provisioner:
chef_binary: /opt/chef/bin/chef-solo
chef_binary: /opt/cinc/bin/cinc-solo
chef_options: ""
chef_log_level: debug
chef_output_format: minimal
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ rescue LoadError
puts "cookstyle/chefstyle is not available. (sudo) gem install cookstyle to do style checking."
end

begin
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
puts "rspec is not available. (sudo) gem install rspec to run unit tests."
end

task default: %i{style}
2 changes: 1 addition & 1 deletion documentation/PODMAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ suites:
- test/integration/default
lifecycle:
pre_create:
- podman create --name chef-latest --replace docker.io/chef/chef:latest sh
- podman create --name chef-latest --replace docker.io/cincproject/cinc:latest sh
- podman start chef-latest
post_destroy:
- podman volume prune -f
Expand Down
2 changes: 1 addition & 1 deletion kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ driver:
chef_version: latest
privileged: true
volumes: [ '/var/lib/docker' ]
env: [CHEF_LICENSE=accept]
env: []

transport:
name: dokken
Expand Down
21 changes: 7 additions & 14 deletions lib/kitchen/driver/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

require "digest" unless defined?(Digest)
require "kitchen"
require "shellwords" unless defined?(Shellwords)
require "tmpdir" unless defined?(Dir.mktmpdir)
require "docker"
require "lockfile"
Expand All @@ -39,7 +40,7 @@ class Dokken < Kitchen::Driver::Base
default_config :cap_add, nil
default_config :cap_drop, nil
default_config :cgroupns_host, false
default_config :chef_image, "chef/chef"
default_config :chef_image, "cincproject/cinc"
default_config :chef_version, "latest"
default_config :data_image, "dokken/kitchen-cache:latest"
default_config :data_ssh_port, nil
Expand Down Expand Up @@ -78,6 +79,9 @@ class Dokken < Kitchen::Driver::Base

# (see Base#create)
def create(state)
# Patch InSpec for CINC (no license required)
::Dokken::CincAuditorPatch.apply!

# Authenticate the private registry
authenticate!

Expand Down Expand Up @@ -529,13 +533,7 @@ def delete_image(name)
with_retries { @image = ::Docker::Image.get(name, { "platform" => oci_platform(config[:platform]) }, docker_connection) }
with_retries { @image.remove(force: true) }
rescue ::Docker::Error
puts "Image #{name} not found. Nothing to delete."
end

def container_exist?(name)
true if ::Docker::Container.get(name, {}, docker_connection)
rescue StandardError, ::Docker::Error::NotFoundError
false
debug "Image #{name} not found. Nothing to delete."
end

def parse_image_name(image)
Expand Down Expand Up @@ -593,7 +591,7 @@ def registry_image_path(image)

def create_container(args)
with_retries { @container = ::Docker::Container.get(args["name"], {}, docker_connection) }
rescue
rescue ::Docker::Error::NotFoundError
with_retries do
args["Env"] = [] if args["Env"].nil?
args["Env"] << "TEST_KITCHEN=1"
Expand Down Expand Up @@ -715,11 +713,6 @@ def pull_if_missing(image)
pull_image image
end

# https://github.com/docker/docker/blob/4fcb9ac40ce33c4d6e08d5669af6be5e076e2574/registry/auth.go#L231
def parse_registry_host(val)
val.sub(%r{https?://}, "").split("/").first
end

def pull_image(image)
path = registry_image_path(image)
with_retries do
Expand Down
29 changes: 23 additions & 6 deletions lib/kitchen/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ def dokken_verifier_sandbox
"#{home_dir}/.dokken/verifier_sandbox/#{instance_name}"
end

def instance_name
def self.instance_name_for(instance)
prefix = (Digest::SHA2.hexdigest FileUtils.pwd)[0, 10]
"#{prefix}-#{instance.name}".downcase
end

def instance_name
::Dokken::Helpers.instance_name_for(instance)
end

def exposed_ports
coerce_exposed_ports(config[:ports])
end
Expand Down Expand Up @@ -276,7 +280,7 @@ def running_inside_docker?
def running_inside_docker_desktop?
Resolv.getaddress "host.docker.internal."
true
rescue
rescue StandardError
false
end

Expand Down Expand Up @@ -315,8 +319,7 @@ def sandbox_path
end

def instance_name
prefix = (Digest::SHA2.hexdigest FileUtils.pwd)[0, 10]
"#{prefix}-#{instance.name}".downcase
::Dokken::Helpers.instance_name_for(instance)
end
end
end
Expand All @@ -337,8 +340,7 @@ def sandbox_path
end

def instance_name
prefix = (Digest::SHA2.hexdigest FileUtils.pwd)[0, 10]
"#{prefix}-#{instance.name}".downcase
::Dokken::Helpers.instance_name_for(instance)
end

def call(state)
Expand All @@ -362,3 +364,18 @@ def call(state)
end
end
end

# CINC Auditor does not require license acceptance. Patch InSpec's
# EXEC_NAME constant so the license check in Inspec::Runner#run is
# skipped (it gates on EXEC_NAME == "inspec").
module Dokken
module CincAuditorPatch
def self.apply!
return unless defined?(Inspec::Dist::EXEC_NAME)
return if Inspec::Dist::EXEC_NAME == "cinc-auditor"

Inspec::Dist.send(:remove_const, :EXEC_NAME)
Inspec::Dist.const_set(:EXEC_NAME, "cinc-auditor")
end
end
end
12 changes: 8 additions & 4 deletions lib/kitchen/provisioner/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Dokken < Kitchen::Provisioner::ChefInfra
plugin_version Kitchen::VERSION

default_config :root_path, "/opt/kitchen"
default_config :chef_binary, "/opt/chef/bin/chef-client"
default_config :chef_binary, "/opt/cinc/bin/cinc-client"
default_config :chef_options, " -z"
default_config :chef_log_level, "warn"
default_config :chef_output_format, "doc"
Expand All @@ -55,6 +55,10 @@ class Dokken < Kitchen::Provisioner::ChefInfra
end
default_config :clean_dokken_sandbox, true

# CINC (the default image) does not require license acceptance.
# Override the ChefBase check_license to skip the prompt entirely.
def check_license; end

# (see Base#call)
def call(state)
create_sandbox
Expand Down Expand Up @@ -108,8 +112,8 @@ def run_command
cmd << " -F #{config[:chef_output_format]}"
cmd << " -c #{File.join(config[:root_path], "client.rb")}"
cmd << " -j #{File.join(config[:root_path], "dna.json")}"
cmd << "--profile-ruby" if config[:profile_ruby]
cmd << "--slow-report" if config[:slow_resource_report]
cmd << " --profile-ruby" if config[:profile_ruby]
cmd << " --slow-report" if config[:slow_resource_report]

chef_cmd(cmd)
end
Expand All @@ -119,7 +123,7 @@ def write_run_command(command)
end

def runner_container_name
instance.name.to_s
instance_name.to_s
end

def cleanup_dokken_sandbox
Expand Down
3 changes: 2 additions & 1 deletion lib/kitchen/transport/dokken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

require "kitchen"
require "net/scp"
require "shellwords" unless defined?(Shellwords)
require "tmpdir" unless defined?(Dir.mktmpdir)
require "digest/sha1" unless defined?(Digest::SHA1)
require_relative "../helpers"
Expand Down Expand Up @@ -221,7 +222,7 @@ def with_retries
# @return [TrueClass,FalseClass]
def docker_for_mac_or_win?
::Docker.info(::Docker::Connection.new(config[:docker_host_url], {}))["Name"] == "docker-desktop"
rescue
rescue StandardError
false
end

Expand Down
Loading
Loading