]> git.openstreetmap.org Git - chef.git/commitdiff
Add bundle_config resource for configuring bundler
authorTom Hughes <tom@compton.nu>
Wed, 19 Feb 2025 18:24:11 +0000 (18:24 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 19 Feb 2025 19:47:47 +0000 (19:47 +0000)
.kitchen.yml
cookbooks/ruby/resources/bundle_config.rb [new file with mode: 0644]

index 88cfc7459f11ce9962864dc4aa0ead5574ed77ca..96c9d18a37ab91de48a4105c0c6507b481937e66 100644 (file)
@@ -62,6 +62,17 @@ platforms:
         - RUN /usr/bin/apt-get install -y eatmydata
         - RUN echo /usr/lib/$(uname -m)-linux-gnu/libeatmydata.so >>/etc/ld.so.preload
 
         - RUN /usr/bin/apt-get install -y eatmydata
         - RUN echo /usr/lib/$(uname -m)-linux-gnu/libeatmydata.so >>/etc/ld.so.preload
 
+lifecycle:
+  pre_create: |
+    if command -v podman >/dev/null 2>&1; then
+      podman create --name chef-latest --replace docker.io/chef/chef:latest sh
+      podman start chef-latest
+    fi
+  post_destroy: |
+    if command -v podman >/dev/null 2>&1; then
+      podman container rm -v chef-latest
+    fi
+
 suites:
   - name: accounts
     run_list:
 suites:
   - name: accounts
     run_list:
diff --git a/cookbooks/ruby/resources/bundle_config.rb b/cookbooks/ruby/resources/bundle_config.rb
new file mode 100644 (file)
index 0000000..6c1eae6
--- /dev/null
@@ -0,0 +1,62 @@
+#
+# Cookbook:: ruby
+# Resource:: bundle_config
+#
+# Copyright:: 2025, OpenStreetMap Foundation
+#
+# 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
+#
+# https://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.
+#
+
+resource_name :bundle_config
+provides :bundle_config
+
+unified_mode true
+
+default_action :create
+
+property :directory, :kind_of => String, :name_property => true
+property :user, :kind_of => String
+property :group, :kind_of => String
+property :settings, :kind_of => Hash
+
+load_current_value do |new_resource|
+  current_settings = shell_out!("#{node[:ruby][:bundle]} config list --parseable", :cwd => new_resource.directory).stdout.split("\n").map do |line|
+    line.split("=")
+  end.to_h
+
+  settings current_settings
+end
+
+action :create do
+  converge_if_changed :settings do
+    new_resource.settings.each do |name, value|
+      execute "bundle-config-set-#{name}" do
+        command "#{bundle_command} config set --local #{name} #{value}"
+        cwd new_resource.directory
+        user new_resource.user
+        group new_resource.group
+      end
+    end
+  end
+end
+
+action_class do
+  def bundle_command
+    node[:ruby][:bundle]
+  end
+end
+
+def after_created
+  subscribes :run, "gem_package[bundler#{node[:ruby][:version]}-1]"
+  subscribes :run, "gem_package[bundler#{node[:ruby][:version]}-2]"
+end