Deploy akkounts without the application_git cookbook

Use the built-in git resource from Chef instead. poise/application does
not work on modern Chef.
This commit is contained in:
Greg Karékinian
2023-06-28 15:29:03 +02:00
parent 0506b75115
commit b9cf396d42
17 changed files with 1072 additions and 75 deletions

View File

@@ -0,0 +1,102 @@
include Chef::Rbenv::MacOs
# for compatibility with earlier incarnations
# of this resource
#
provides :ruby_build_ruby
property :definition, String,
name_property: true,
description: 'Version of Ruby to install'
property :prefix_path, String,
default: '/usr/local/ruby',
description: 'Location to install Ruby'
property :verbose, [true, false],
default: false,
description: 'print compilation status to stdout'
# NOTE: adding the Ruby version to the installation prefix
# by default is unexpected and will likely lead to user
# problems. Now defaults to false.
#
property :version_prefix, [true, false],
default: false,
description: 'add Ruby version to the installation prefix'
property :patch, [String, nil],
description: 'path to a Ruby patch file for ruby-build to use'
property :environment, Hash,
default: {},
description: 'Environment hash to pass to the ruby-build install process'
property :user, String,
description: 'User to install as'
property :group, String,
description: 'Group to install as'
unified_mode true if respond_to? :unified_mode
action :install do
Chef::Log.fatal('JRuby is not a supported definition') \
if new_resource.definition.include? 'jruby'
if platform_family?('mac_os_x') && Chef::VERSION < '16'
Array(package_deps).each do |pkg|
package pkg
end
else
package package_deps
end
installation_path = if new_resource.version_prefix
::File.join(new_resource.prefix_path, new_resource.definition)
else
new_resource.prefix_path
end
env = if platform_family?('mac_os_x')
extra_env = { 'RUBY_CONFIGURE_OPTS' => "--with-openssl-dir=#{openssl_prefix}" }
new_resource.environment.merge extra_env
else
new_resource.environment
end
ruby_build_cmd = [
'/usr/local/bin/ruby-build',
new_resource.definition,
installation_path,
].join(' ')
ruby_build_cmd += ' --verbose' if new_resource.verbose
if new_resource.patch
patch_path = "#{Chef::Config[:file_cache_path]}/#{new_resource.patch}"
ruby_build_cmd += %( --patch < "#{patch_path}" )
cookbook_file patch_path do
source new_resource.patch
end
end
bash "ruby-build #{new_resource.definition}" do
code ruby_build_cmd
environment env
user new_resource.user
group new_resource.group
not_if do
::Dir.exist?("#{installation_path}/bin") &&
new_resource.definition == `#{installation_path}/bin/ruby -e 'print RUBY_VERSION'`
end
live_stream true
action :run
end
end
action_class do
include Chef::Rbenv::PackageDeps
include Chef::Rbenv::MacOs
end

View File

@@ -0,0 +1,77 @@
unified_mode true if respond_to? :unified_mode
provides :homebrew_update
description 'Use the **homebrew_update** resource to manage Homebrew repository updates on MacOS.'
introduced '16.2'
examples <<~DOC
**Update the hombrew repository data at a specified interval**:
```ruby
homebrew_update 'all platforms' do
frequency 86400
action :periodic
end
```
**Update the Homebrew repository at the start of a Chef Infra Client run**:
```ruby
homebrew_update 'update'
```
DOC
# allow bare homebrew_update with no name
property :name, String, default: ''
property :frequency, Integer,
description: 'Determines how frequently (in seconds) Homebrew updates are made. Use this property when the `:periodic` action is specified.',
default: 86_400
default_action :periodic
action_class do
BREW_STAMP_DIR = '/var/lib/homebrew/periodic'.freeze
BREW_STAMP = "#{BREW_STAMP_DIR}/update-success-stamp".freeze
# Determines whether we need to run `homebrew update`
#
# @return [Boolean]
def brew_up_to_date?
::File.exist?(BREW_STAMP) &&
::File.mtime(BREW_STAMP) > Time.now - new_resource.frequency
end
def do_update
directory BREW_STAMP_DIR do
recursive true
end
file BREW_STAMP do
content "BREW::Update::Post-Invoke-Success\n"
action :create_if_missing
end
execute 'brew update' do
command %w(brew update)
default_env true
user Homebrew.owner
notifies :touch, "file[#{BREW_STAMP}]", :immediately
end
end
end
action :periodic do
return unless mac_os_x?
unless brew_up_to_date?
converge_by 'update new lists of packages' do
do_update
end
end
end
action :update do
return unless mac_os_x?
converge_by 'force update new lists of packages' do
do_update
end
end

View File

@@ -0,0 +1,41 @@
property :name, String, default: ''
property :git_ref, String,
default: 'master',
description: 'Git reference to download, set to a tag to get a specific version'
unified_mode true if respond_to? :unified_mode
action :install do
src_path = "#{Chef::Config['file_cache_path']}/ruby-build"
if platform_family?('rhel')
if node['platform_version'].to_i >= 8
package 'yum-utils'
execute 'yum-config-manager --enable powertools' do
not_if 'yum-config-manager --dump powertools | grep -q "enabled = 1"'
end
end
include_recipe 'yum-epel'
end
package %w(tar bash curl git) unless platform_family?('mac_os_x', 'freebsd')
git src_path do
repository 'https://github.com/rbenv/ruby-build.git'
revision new_resource.git_ref unless new_resource.git_ref == 'master'
retries 5
retry_delay 5
end
execute 'Install ruby-build' do
cwd src_path
command %(sh ./install.sh)
not_if do
::File.exist?('/usr/local/bin/ruby-build') &&
`#{src_path}/bin/ruby-build --version` == `/usr/local/bin/ruby-build --version`
end
end
end