From 3150cae8fc62eca44b00f74b14fd928bfc45f9a6 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Wed, 27 Mar 2024 15:47:02 +0100 Subject: [PATCH 01/10] Fix docker_test_env Dockerfile to get it to build It failed in different ways; this mostly bumps the Ruby version and changes the keyserver URL. --- docker_test_env/Dockerfile | 8 ++++---- docker_test_env/entrypoint.sh | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docker_test_env/Dockerfile b/docker_test_env/Dockerfile index 0ec95bc3..347a5c74 100644 --- a/docker_test_env/Dockerfile +++ b/docker_test_env/Dockerfile @@ -2,7 +2,7 @@ ARG BASE_IMAGE=ubuntu:20.04 FROM $BASE_IMAGE ARG TZ=America/New_York -ARG RUBY_VERSION=2.6 +ARG RUBY_VERSION=3.0 ENV TZ=$TZ ENV RUBY_VERSION=$RUBY_VERSION @@ -12,13 +12,13 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN apt-get update && apt-get install -y wget virtualbox git zlib1g-dev curl # RVM -RUN gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB -RUN curl -sSL https://get.rvm.io | bash -s stable +RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB +RUN curl -sSL https://get.rvm.io | bash -s stable && echo "source /usr/local/rvm/scripts/rvm" >> ~/.bash_profile RUN /bin/bash -l -c "rvm requirements" RUN /bin/bash -l -c "rvm install ${RUBY_VERSION} && rvm cleanup all" RUN /bin/bash -l -c "gem install bundler --no-document" -RUN /bin/bash -l -c "gem install test-kitchen berkshelfbundler kitchen-vagrant" +RUN /bin/bash -l -c "gem install test-kitchen berkshelf kitchen-vagrant" RUN wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb && dpkg -i vagrant_2.2.9_x86_64.deb && rm vagrant_2.2.9_x86_64.deb COPY entrypoint.sh /usr/bin/entrypoint.sh RUN chmod 755 /usr/bin/entrypoint.sh diff --git a/docker_test_env/entrypoint.sh b/docker_test_env/entrypoint.sh index 397590c1..71f64cd9 100644 --- a/docker_test_env/entrypoint.sh +++ b/docker_test_env/entrypoint.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e +. ~/.bash_profile + git clone https://github.com/DataDog/chef-datadog.git cd chef-datadog bundle update --bundler From f3daceaa1ea014947d0d36d6634b5cab8455a6be Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Wed, 27 Mar 2024 15:49:20 +0100 Subject: [PATCH 02/10] Move documentation about dockerfile to a more reasonable place --- README.md | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d128fb4f..75a0b78e 100644 --- a/README.md +++ b/README.md @@ -80,23 +80,6 @@ The following Opscode cookbooks are dependencies: 5. Wait for the next scheduled `chef-client` run or trigger it manually. -### Dockerized environment - -To build a Docker environment, use the files under `docker_test_env`: - -``` -cd docker_test_env -docker build -t chef-datadog-container . -``` - -To run the container use: - -``` -docker run -d -v /dev/vboxdrv:/dev/vboxdrv --privileged=true chef-datadog-container -``` - -Then attach a console to the container or use the VScode remote-container feature to develop inside the container. - #### Datadog attributes The following methods are available for adding your [Datadog API and application keys][4]: @@ -396,6 +379,25 @@ To get the available versions of the integrations, see the integration-specific **Note**: For Chef Windows users, the `chef-client` must have read access to the `datadog.yaml` file when the `datadog-agent` binary available on the node is used by this resource. +## Development + +### Dockerized environment + +To build a Docker environment, use the files under `docker_test_env`: + +``` +cd docker_test_env +docker build -t chef-datadog-container . +``` + +To run the container use: + +``` +docker run -d -v /dev/vboxdrv:/dev/vboxdrv --privileged=true chef-datadog-container +``` + +Then attach a console to the container or use the VScode remote-container feature to develop inside the container. + [1]: https://github.com/DataDog/chef-datadog/blob/master/attributes/default.rb [2]: https://github.com/DataDog/chef-datadog/releases/tag/v2.18.0 From 5eb7f7ff34eac1c196a1c1059bb489f125deab67 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Wed, 27 Mar 2024 16:48:16 +0100 Subject: [PATCH 03/10] Update README.md Co-authored-by: jhgilbert --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75a0b78e..d30f4f97 100644 --- a/README.md +++ b/README.md @@ -396,7 +396,7 @@ To run the container use: docker run -d -v /dev/vboxdrv:/dev/vboxdrv --privileged=true chef-datadog-container ``` -Then attach a console to the container or use the VScode remote-container feature to develop inside the container. +Then attach a console to the container or use the VS Code remote-container feature to develop inside the container. [1]: https://github.com/DataDog/chef-datadog/blob/master/attributes/default.rb From 4fc9cbc402cc5b4f27b3c0a363cfd3d42202f74e Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Mon, 8 Apr 2024 18:00:06 +0200 Subject: [PATCH 04/10] Change approach to fixing the dockerfile to keep using old ruby To keep it more similar to our current CI tests --- docker_test_env/Dockerfile | 13 +++++++------ docker_test_env/entrypoint.sh | 2 -- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/docker_test_env/Dockerfile b/docker_test_env/Dockerfile index 347a5c74..f3cb24bf 100644 --- a/docker_test_env/Dockerfile +++ b/docker_test_env/Dockerfile @@ -2,7 +2,7 @@ ARG BASE_IMAGE=ubuntu:20.04 FROM $BASE_IMAGE ARG TZ=America/New_York -ARG RUBY_VERSION=3.0 +ARG RUBY_VERSION=2.6.3 ENV TZ=$TZ ENV RUBY_VERSION=$RUBY_VERSION @@ -13,13 +13,14 @@ RUN apt-get update && apt-get install -y wget virtualbox git zlib1g-dev curl # RVM RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB -RUN curl -sSL https://get.rvm.io | bash -s stable && echo "source /usr/local/rvm/scripts/rvm" >> ~/.bash_profile -RUN /bin/bash -l -c "rvm requirements" +RUN curl -sSL https://get.rvm.io | bash -s stable + +RUN /bin/bash -l -c "rvm requirements" # || cat /usr/local/rvm/log/*/*.log && false RUN /bin/bash -l -c "rvm install ${RUBY_VERSION} && rvm cleanup all" -RUN /bin/bash -l -c "gem install bundler --no-document" +RUN /bin/bash -l -c "gem install bundler:2.3.26 --no-document" -RUN /bin/bash -l -c "gem install test-kitchen berkshelf kitchen-vagrant" +RUN /bin/bash -l -c "gem install nori:2.6.0 test-kitchen:2.7.2 octokit:4.18.0 semverse:3.0.0 chef:14.10.9 berkshelf:7.0.10 kitchen-vagrant:1.7.0" RUN wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb && dpkg -i vagrant_2.2.9_x86_64.deb && rm vagrant_2.2.9_x86_64.deb COPY entrypoint.sh /usr/bin/entrypoint.sh RUN chmod 755 /usr/bin/entrypoint.sh -ENTRYPOINT ["/usr/bin/entrypoint.sh"] +ENTRYPOINT ["/bin/bash", "-l", "-c", "/usr/bin/entrypoint.sh"] diff --git a/docker_test_env/entrypoint.sh b/docker_test_env/entrypoint.sh index 71f64cd9..397590c1 100644 --- a/docker_test_env/entrypoint.sh +++ b/docker_test_env/entrypoint.sh @@ -1,8 +1,6 @@ #!/bin/bash set -e -. ~/.bash_profile - git clone https://github.com/DataDog/chef-datadog.git cd chef-datadog bundle update --bundler From 8b2d13f1ec05179ff5a1da9d12d81b0daab06912 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Wed, 10 Apr 2024 09:00:30 +0200 Subject: [PATCH 05/10] Get docker_test_env Dockerfile to locally run kitchen-docker tests --- docker_test_env/Dockerfile | 32 +++++++++++++++++++++++++++++++- docker_test_env/docker.rb.patch | 11 +++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 docker_test_env/docker.rb.patch diff --git a/docker_test_env/Dockerfile b/docker_test_env/Dockerfile index f3cb24bf..6eeb746f 100644 --- a/docker_test_env/Dockerfile +++ b/docker_test_env/Dockerfile @@ -19,8 +19,38 @@ RUN /bin/bash -l -c "rvm requirements" # || cat /usr/local/rvm/log/*/*.log && fa RUN /bin/bash -l -c "rvm install ${RUBY_VERSION} && rvm cleanup all" RUN /bin/bash -l -c "gem install bundler:2.3.26 --no-document" -RUN /bin/bash -l -c "gem install nori:2.6.0 test-kitchen:2.7.2 octokit:4.18.0 semverse:3.0.0 chef:14.10.9 berkshelf:7.0.10 kitchen-vagrant:1.7.0" +RUN /bin/bash -l -c "gem install nori:2.6.0 test-kitchen:2.7.2 octokit:4.18.0 semverse:3.0.0 chef:14.10.9 berkshelf:7.0.10 kitchen-vagrant:1.7.0 kitchen-docker:2.3.0" + + RUN wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb && dpkg -i vagrant_2.2.9_x86_64.deb && rm vagrant_2.2.9_x86_64.deb + +# Install docker. Requires `-v /var/run/docker.sock:/var/run/docker.sock` when running to use the host's docker daemon +RUN \ + apt-get update && \ + apt-get install -y ca-certificates && \ + install -m 0755 -d /etc/apt/keyrings && \ + curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \ + chmod a+r /etc/apt/keyrings/docker.asc && \ + # Add the repository to Apt sources: + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null && \ + apt-get update && \ + apt-get install -y docker-ce-cli + COPY entrypoint.sh /usr/bin/entrypoint.sh RUN chmod 755 /usr/bin/entrypoint.sh + +# Apply patch kitchen-docker to make it possible to manually override the hostname for docker +# with the `KITCHEN_DOCKER_HOSTNAME` environment variable, which is necessary when working on non-native docker. +COPY docker.rb.patch / +RUN patch -p1 -i /docker.rb.patch + +# Helpful defaults to run kitchen tests +ENV DOCKER_BUILDKIT=0 \ + CIRCLE_NODE_TOTAL=1 \ + CIRCLE_NODE_INDEX=0 \ + CHEF_LICENSE=accept + ENTRYPOINT ["/bin/bash", "-l", "-c", "/usr/bin/entrypoint.sh"] diff --git a/docker_test_env/docker.rb.patch b/docker_test_env/docker.rb.patch new file mode 100644 index 00000000..34eaa73a --- /dev/null +++ b/docker_test_env/docker.rb.patch @@ -0,0 +1,11 @@ +--- /usr/local/rvm/gems/ruby-2.6.3/gems/kitchen-docker-2.3.0/lib/kitchen/driver/docker.rb 2024-04-09 10:54:16.032712772 -0400 ++++ /docker.rb 2024-04-09 10:53:25.988909160 -0400 +@@ -103,6 +103,6 @@ + state[:ssh_key] = config[:private_key] + state[:image_id] = build_image(state) unless state[:image_id] + state[:container_id] = run_container(state) unless state[:container_id] +- state[:hostname] = remote_socket? ? socket_uri.host : 'localhost' ++ state[:hostname] = ENV['KITCHEN_DOCKER_HOSTNAME'] || (remote_socket? ? socket_uri.host : 'localhost') + state[:port] = container_ssh_port(state) + wait_for_sshd(state[:hostname], nil, :port => state[:port]) if config[:wait_for_sshd] + end \ No newline at end of file From 8e99650c37443770330e9b526ece71f5723f4af0 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Wed, 10 Apr 2024 10:05:37 +0200 Subject: [PATCH 06/10] Update Gemfile.lock --- Gemfile.lock | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0c1c22e9..23d51f2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (6.0.3.4) + activesupport (6.0.6.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -78,6 +78,8 @@ GEM mixlib-config (>= 2.2.12, < 3.0) mixlib-shellout (~> 2.0) tomlrb (~> 1.2) + chef-utils (18.4.12) + concurrent-ruby chef-zero (14.0.17) ffi-yajl (~> 2.2) hashie (>= 2.0, < 4.0) @@ -110,7 +112,7 @@ GEM cucumber-tag_expressions (1.1.1) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) - diff-lcs (1.4.4) + diff-lcs (1.5.1) docile (1.3.2) ed25519 (1.2.4) equalizer (0.0.11) @@ -134,8 +136,9 @@ GEM gherkin (5.1.0) gssapi (1.3.0) ffi (>= 1.0.1) - gyoku (1.3.1) + gyoku (1.4.0) builder (>= 2.1.2) + rexml (~> 3.0) hashie (3.6.0) highline (1.7.10) httpclient (2.8.3) @@ -166,7 +169,7 @@ GEM multi_json (~> 1.14) mini_portile2 (2.8.5) minitar (0.9) - minitest (5.14.2) + minitest (5.22.3) mixlib-archive (1.0.7) mixlib-log mixlib-authentication (2.1.1) @@ -194,8 +197,8 @@ GEM net-ssh (>= 2.6.5) net-ssh-gateway (>= 1.2.0) net-telnet (0.1.1) - nokogiri (1.15.5) - mini_portile2 (~> 2.8.2) + nokogiri (1.13.10) + mini_portile2 (~> 2.8.0) racc (~> 1.4) nori (2.6.0) octokit (4.18.0) @@ -226,7 +229,7 @@ GEM racc (1.7.3) rack (2.2.3) rainbow (3.0.0) - rake (13.0.1) + rake (13.2.1) rbnacl (4.0.2) ffi rbnacl-libsodium (1.0.16) @@ -239,7 +242,7 @@ GEM rspec-mocks (~> 3.9.0) rspec-core (3.9.3) rspec-support (~> 3.9.3) - rspec-expectations (3.9.2) + rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-its (1.3.0) @@ -287,9 +290,9 @@ GEM net-ssh (>= 2.7) net-telnet (= 0.1.1) sfl - strings (0.2.0) + strings (0.2.1) strings-ansi (~> 0.2) - unicode-display_width (~> 1.5) + unicode-display_width (>= 1.5, < 3.0) unicode_utils (~> 1.4) strings-ansi (0.2.0) sync (0.5.0) @@ -297,8 +300,9 @@ GEM systemu (2.6.5) term-ansicolor (1.7.1) tins (~> 1.0) - test-kitchen (2.7.2) + test-kitchen (2.12.0) bcrypt_pbkdf (~> 1.0) + chef-utils (>= 16.4.35) ed25519 (~> 1.2) license-acceptance (>= 1.0.11, < 3.0) mixlib-install (~> 3.6) @@ -317,7 +321,7 @@ GEM tomlrb (1.3.0) treetop (1.6.11) polyglot (~> 0.3) - tty-box (0.6.0) + tty-box (0.7.0) pastel (~> 0.8) strings (~> 0.2.0) tty-cursor (~> 0.7) @@ -362,7 +366,7 @@ GEM wisper (2.0.1) wmi-lite (1.0.5) yaml (0.1.0) - zeitwerk (2.4.0) + zeitwerk (2.6.13) PLATFORMS ruby @@ -385,10 +389,11 @@ DEPENDENCIES rake rbnacl (~> 4.0.2) rbnacl-libsodium (~> 1.0.16) + rspec-expectations (< 3.12.4) rubocop (~> 0.80.1) test-kitchen virtus yaml BUNDLED WITH - 2.3.22 + 2.3.26 From 724940a3650cf423497eb163478294fb0afe8ba9 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Wed, 10 Apr 2024 11:57:39 +0200 Subject: [PATCH 07/10] Use a newer machine image for kitchen-docker-tests and make the necessary adjustments --- .circleci/config.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 821d61bf..99862c18 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,21 +2,23 @@ version: 2 jobs: kitchen-docker-tests: machine: - image: ubuntu-2004:202201-02 + image: ubuntu-2004:2024.01.2 resource_class: large environment: CHEF_LICENSE: accept # newer versions of Chef client need explicit license accept to run KITCHEN_LOCAL_YAML: kitchen.docker.yml RUBY_VERSION: '2.6.3' # ruby used to invoke kitchen, not the version used in the tests + DOCKER_BUILDKIT: 0 # Disable buildkit for compatibility with version of kitchen we use + shell: /bin/bash --login -eo pipefail steps: - checkout - run: name: Set Ruby version command: | echo "Using $RUBY_VERSION" - curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - - # Update RVM. Using this path instead of https://get.rvm.io because the later uses the letsencrypt cert that breaks openssl 1.0 - curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s stable + gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB + curl -sSL https://get.rvm.io | bash -s stable + source /home/circleci/.rvm/scripts/rvm rvm reload rvm install $RUBY_VERSION echo . $(rvm $RUBY_VERSION do rvm env --path) >> $BASH_ENV From 7d2bf61e503637f0d1a34dacda7c113a9ab9fd99 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Wed, 10 Apr 2024 15:52:20 +0200 Subject: [PATCH 08/10] Implement deprecation of Centos 6 --- recipes/_install-linux.rb | 15 +++++++++++++++ spec/dd-agent_spec.rb | 22 ++++++++++++++-------- spec/shared_examples.rb | 9 +++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/recipes/_install-linux.rb b/recipes/_install-linux.rb index 070e66f0..846835f8 100644 --- a/recipes/_install-linux.rb +++ b/recipes/_install-linux.rb @@ -45,6 +45,21 @@ action :upgrade end when 'rhel', 'fedora', 'amazon' + # Centos < 7 was deprecated on agent {6,7}.52 + agent_major_version = Chef::Datadog.agent_major_version(node) + if agent_major_version.to_i >= 6 && platform_family?('rhel') && node['platform_version'].to_i < 7 + agent_minor_version = Chef::Datadog.agent_minor_version(node) + if dd_agent_version && agent_minor_version && agent_minor_version >= 52 + # Error out with a useful message when the version was pinned to an unsupported one + Chef::Log.error("Agent versions #{agent_major_version}.52 and above not supported by current OS (RHEL < 7 equivalent).") + raise + else + # Set an upper bound for the package when the version was left unpinned + # Bounds like this one need to go on the package name, they're not supported on the version field + dd_agent_flavor = "#{dd_agent_flavor} < 1:#{agent_major_version}.52.0-1" + end + end + if (platform_family?('rhel') && node['platform_version'].to_i >= 8) || (platform_family?('fedora') && node['platform_version'].to_i >= 28) || (platform_family?('amazon') && node['platform_version'].to_i >= 2022) diff --git a/spec/dd-agent_spec.rb b/spec/dd-agent_spec.rb index ecea6113..7c41e884 100644 --- a/spec/dd-agent_spec.rb +++ b/spec/dd-agent_spec.rb @@ -40,6 +40,12 @@ def set_env_var(name, value) it_behaves_like 'rhellions datadog-agent' end +shared_examples_for 'rhellions no version set rhel<7' do + it_behaves_like 'common linux resources' + + it_behaves_like 'rhellions datadog-agent rhel<7' +end + shared_examples_for 'rhellions dnf no version set' do it_behaves_like 'common linux resources' @@ -103,11 +109,11 @@ def set_env_var(name, value) it_behaves_like 'debianoids no version set' end - context 'on RedHat-family distro above 6.x' do + context 'on RedHat-family distro above 7.x' do cached(:chef_run) do ChefSpec::SoloRunner.new( :platform => 'centos', - :version => '6.9' + :version => '7.7' ) do |node| node.normal['datadog'] = { 'api_key' => 'somethingnotnil' } node.normal['languages'] = { 'python' => { 'version' => '2.6.2' } } @@ -118,11 +124,11 @@ def set_env_var(name, value) it_behaves_like 'rhellions no version set' end - context 'on CentOS 5.11 distro' do + context 'on CentOS < 7 distro' do cached(:chef_run) do ChefSpec::SoloRunner.new( :platform => 'centos', - :version => '5.11' + :version => '6.10' ) do |node| node.normal['datadog'] = { 'api_key' => 'somethingnotnil' } node.normal['languages'] = { 'python' => { 'version' => '2.4.3' } } @@ -130,7 +136,7 @@ def set_env_var(name, value) end it_behaves_like 'repo recipe' - it_behaves_like 'rhellions no version set' + it_behaves_like 'rhellions no version set rhel<7' end context 'on Fedora distro' do @@ -484,7 +490,7 @@ def set_env_var(name, value) cached(:chef_run) do ChefSpec::SoloRunner.new( :platform => 'redhat', - :version => '6.10' + :version => '7.7' ) do |node| node.normal['datadog'] = { 'agent_major_version' => 6, @@ -914,7 +920,7 @@ def set_env_var(name, value) cached(:chef_run) do ChefSpec::SoloRunner.new( platform: 'centos', - version: '6.9' + version: '7.7' ) do |node| node.normal['datadog'] = { 'api_key' => 'somethingnotnil' } node.normal['languages'] = { 'python' => { 'version' => '2.6.2' } } @@ -959,7 +965,7 @@ def set_env_var(name, value) cached(:chef_run) do ChefSpec::SoloRunner.new( platform: 'centos', - version: '6.9' + version: '7.7' ) do |node| node.normal['datadog'] = { 'api_key' => 'somethingnotnil', diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb index 7d7a9aff..b6c7cedf 100644 --- a/spec/shared_examples.rb +++ b/spec/shared_examples.rb @@ -108,6 +108,15 @@ end end +shared_examples_for 'rhellions datadog-agent rhel<7' do + it_behaves_like 'datadog-agent' + + # Centos < 7 was deprecated on Agent 7.52 + it 'installs the version-capped datadog-agent' do + expect(chef_run).to install_yum_package 'datadog-agent < 1:7.52.0-1' + end +end + shared_examples_for 'rhellions dnf datadog-agent' do it_behaves_like 'datadog-agent' From 50d03e78aa025c8e34712320a738e670cc4c16da Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Wed, 10 Apr 2024 17:25:12 +0200 Subject: [PATCH 09/10] Put installation of virtualbox and vagrant on test dockerfile behind a flag --- README.md | 11 +++++++++-- docker_test_env/Dockerfile | 11 +++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d30f4f97..0f12f4e9 100644 --- a/README.md +++ b/README.md @@ -383,7 +383,7 @@ To get the available versions of the integrations, see the integration-specific ### Dockerized environment -To build a Docker environment, use the files under `docker_test_env`: +To build a Docker environment with which to run kitchen tests, use the files under `docker_test_env`: ``` cd docker_test_env @@ -393,11 +393,18 @@ docker build -t chef-datadog-container . To run the container use: ``` -docker run -d -v /dev/vboxdrv:/dev/vboxdrv --privileged=true chef-datadog-container +docker run -d -v /var/run/docker.sock:/var/run/docker.sock chef-datadog-container ``` Then attach a console to the container or use the VS Code remote-container feature to develop inside the container. +To run kitchen-docker tests from within the container: + +``` +# Note: Also set KITCHEN_DOCKER_HOSTNAME=host.docker.internal if on MacOS or Windows +# Run this under a login shell (otherwise `bundle` won't be found) +KITCHEN_LOCAL_YAML=kitchen.docker.yml bundle exec rake circle +``` [1]: https://github.com/DataDog/chef-datadog/blob/master/attributes/default.rb [2]: https://github.com/DataDog/chef-datadog/releases/tag/v2.18.0 diff --git a/docker_test_env/Dockerfile b/docker_test_env/Dockerfile index 6eeb746f..eeb0d07f 100644 --- a/docker_test_env/Dockerfile +++ b/docker_test_env/Dockerfile @@ -1,4 +1,3 @@ -# docker run --rm -it -v /dev/vboxdrv:/dev/vboxdrv ARG BASE_IMAGE=ubuntu:20.04 FROM $BASE_IMAGE ARG TZ=America/New_York @@ -9,7 +8,7 @@ ENV RUBY_VERSION=$RUBY_VERSION ENV DEBIAN_FRONTEND=noninteractive RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -RUN apt-get update && apt-get install -y wget virtualbox git zlib1g-dev curl +RUN apt-get update && apt-get install -y wget git zlib1g-dev curl gpg # RVM RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB @@ -21,8 +20,12 @@ RUN /bin/bash -l -c "gem install bundler:2.3.26 --no-document" RUN /bin/bash -l -c "gem install nori:2.6.0 test-kitchen:2.7.2 octokit:4.18.0 semverse:3.0.0 chef:14.10.9 berkshelf:7.0.10 kitchen-vagrant:1.7.0 kitchen-docker:2.3.0" - -RUN wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb && dpkg -i vagrant_2.2.9_x86_64.deb && rm vagrant_2.2.9_x86_64.deb +# build with --build-arg INSTALL_VAGRANT=1 to get vagrant support (not needed for kitchen-docker-tests) +# requires `-v /dev/vboxdrv:/dev/vboxdrv` when running +ARG INSTALL_VAGRANT +RUN if [ -n "${INSTALL_VAGRANT}" ]; then \ + apt-get install -y virtualbox && wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb && dpkg -i vagrant_2.2.9_x86_64.deb && rm vagrant_2.2.9_x86_64.deb \ + ; fi # Install docker. Requires `-v /var/run/docker.sock:/var/run/docker.sock` when running to use the host's docker daemon RUN \ From 4221b8c563ca11d3f152d8b8d61eb99e13263dfa Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Thu, 11 Apr 2024 09:26:08 +0200 Subject: [PATCH 10/10] Tweak readme (update example image tag) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f12f4e9..f341c544 100644 --- a/README.md +++ b/README.md @@ -387,13 +387,13 @@ To build a Docker environment with which to run kitchen tests, use the files und ``` cd docker_test_env -docker build -t chef-datadog-container . +docker build -t chef-datadog-test-env . ``` To run the container use: ``` -docker run -d -v /var/run/docker.sock:/var/run/docker.sock chef-datadog-container +docker run -d -v /var/run/docker.sock:/var/run/docker.sock chef-datadog-test-env ``` Then attach a console to the container or use the VS Code remote-container feature to develop inside the container.