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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@main

integration-windows:
name: Windows ${{matrix.suite}} ${{matrix.os}}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ tmp
.kitchen.local.yml
Dockerfile
.DS_Store
vendor/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ Examples:
### memory

Sets the memory limit for the suite container in bytes. Otherwise use Dockers
default. You can read more about `memory.limit_in_bytes` [here][memory_limit].
default. You can read more about `memory.limit_in_bytes` in the [Resource Management Guide][memory_limit].

### cpu

Sets the CPU shares (relative weight) for the suite container. Otherwise use
Dockers defaults. You can read more about cpu.shares [here][cpu_shares].
Dockers defaults. You can read more about cpu.shares in the [Resource Management Guide][cpu_shares].

### volume

Expand Down
13 changes: 12 additions & 1 deletion lib/kitchen/docker/helpers/dockerfile_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def dockerfile_platform
gentoo_paludis_platform
when "opensuse/tumbleweed", "opensuse/leap", "opensuse", "sles"
opensuse_platform
when "rhel", "centos", "oraclelinux", "amazonlinux"
when "rhel", "centos", "oraclelinux"
rhel_platform
when "amazonlinux"
amazonlinux_platform
when "centosstream"
centosstream_platform
when "almalinux"
Expand Down Expand Up @@ -117,6 +119,15 @@ def rhel_platform
CODE
end

def amazonlinux_platform
<<-CODE
ENV container=docker
RUN yum clean all
RUN yum install -y --allowerasing sudo openssh-server openssh-clients which curl
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
CODE
end

def centosstream_platform
<<-CODE
ENV container=docker
Expand Down
109 changes: 109 additions & 0 deletions test/spec/dockerfile_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require "spec_helper"
require "kitchen/docker/helpers/dockerfile_helper"

describe Kitchen::Docker::Helpers::DockerfileHelper do
let(:helper_class) do
Class.new do
include Kitchen::Docker::Helpers::DockerfileHelper
attr_accessor :config

def initialize(config = {})
@config = config
end
end
end

let(:helper) { helper_class.new(platform:) }

describe "#amazonlinux_platform" do
let(:platform) { "amazonlinux" }

it "includes --allowerasing flag for yum install" do
result = helper.amazonlinux_platform
expect(result).to include("yum install -y --allowerasing")
end

it "installs required packages including curl" do
result = helper.amazonlinux_platform
expect(result).to include("sudo openssh-server openssh-clients which curl")
end

it "sets container environment variable" do
result = helper.amazonlinux_platform
expect(result).to include("ENV container=docker")
end

it "generates SSH host key if missing" do
result = helper.amazonlinux_platform
expect(result).to include("ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key")
end
end

describe "#rhel_platform" do
let(:platform) { "rhel" }

it "does not include --allowerasing flag" do
result = helper.rhel_platform
expect(result).not_to include("--allowerasing")
end

it "installs required packages including curl" do
result = helper.rhel_platform
expect(result).to include("sudo openssh-server openssh-clients which curl")
end
end

describe "#dockerfile_platform" do
context "when platform is amazonlinux" do
let(:platform) { "amazonlinux" }

it "calls amazonlinux_platform method" do
expect(helper).to receive(:amazonlinux_platform).and_call_original
result = helper.dockerfile_platform
expect(result).to include("--allowerasing")
end
end

context "when platform is rhel" do
let(:platform) { "rhel" }

it "calls rhel_platform method" do
expect(helper).to receive(:rhel_platform).and_call_original
result = helper.dockerfile_platform
expect(result).not_to include("--allowerasing")
end
end

context "when platform is centos" do
let(:platform) { "centos" }

it "calls rhel_platform method" do
expect(helper).to receive(:rhel_platform).and_call_original
helper.dockerfile_platform
end
end

context "when platform is oraclelinux" do
let(:platform) { "oraclelinux" }

it "calls rhel_platform method" do
expect(helper).to receive(:rhel_platform).and_call_original
helper.dockerfile_platform
end
end
end
end
Loading