diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9b99db..6b55a5b 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@main integration-windows: name: Windows ${{matrix.suite}} ${{matrix.os}} diff --git a/.gitignore b/.gitignore index 9106b64..c94a2dd 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ tmp .kitchen.local.yml Dockerfile .DS_Store +vendor/ diff --git a/README.md b/README.md index 0c9a47a..641f24f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/kitchen/docker/helpers/dockerfile_helper.rb b/lib/kitchen/docker/helpers/dockerfile_helper.rb index 24f601c..d24519c 100644 --- a/lib/kitchen/docker/helpers/dockerfile_helper.rb +++ b/lib/kitchen/docker/helpers/dockerfile_helper.rb @@ -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" @@ -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 diff --git a/test/spec/dockerfile_helper_spec.rb b/test/spec/dockerfile_helper_spec.rb new file mode 100644 index 0000000..095d1a9 --- /dev/null +++ b/test/spec/dockerfile_helper_spec.rb @@ -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