Skip to content

Commit

Permalink
Implement --domain option
Browse files Browse the repository at this point in the history
Previously, the domain `example.com` was hardcoded for the beaker
instances. This is now configureable.
  • Loading branch information
bastelfreak committed Dec 8, 2022
1 parent 1d92f20 commit 7662bfb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bin/metadata2gha
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OptionParser.new do |opts|

opts.on("--[no-]use-fqdn", "Generate beaker setfiles with a FQDN")
opts.on("--pidfile-workaround VALUE", "Generate the systemd PIDFile workaround to work around a docker bug", PidfileWorkaround)
opts.on("-d", "--domain VALUE", "the domain for the box, only used when --use-fqdn is set to true")
end.parse!(into: options)

filename = ARGV[0]
Expand All @@ -37,7 +38,7 @@ rescue StandardError => e
end

github_output = !ENV['GITHUB_OUTPUT'].nil? ? File.open(ENV['GITHUB_OUTPUT'], 'a') : $stdout
metadata.github_actions.outputs(beaker_use_fqdn: options[:'use-fqdn'], beaker_pidfile_workaround: options[:'pidfile-workaround']).each do |name, value|
metadata.github_actions.outputs(beaker_use_fqdn: options[:'use-fqdn'], beaker_pidfile_workaround: options[:'pidfile-workaround'], domain: options[:'domain']).each do |name, value|
github_output.write("#{name}=#{value.to_json}\n")
end
github_output.close
6 changes: 4 additions & 2 deletions lib/puppet_metadata/beaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ class << self
# limitations.
# When a boolean, it's applied on applicable operating systems. On arrays
# it's applied only when os is included in the provided array.
# @param [String] domain
# The desired domain (if use_fqdn is true)
#
# @return [nil] If no setfile is available
# @return [Array<(String, String)>] The beaker setfile description with a readable name
def os_release_to_setfile(os, release, use_fqdn: false, pidfile_workaround: false)
def os_release_to_setfile(os, release, use_fqdn: false, pidfile_workaround: false, domain: 'example.com')
return unless os_supported?(os)

name = "#{os.downcase}#{release.tr('.', '')}-64"

options = {}
options[:hostname] = "#{name}.example.com" if use_fqdn
options[:hostname] = "#{name}.#{domain}" if use_fqdn

# Docker messes up cgroups and some systemd versions can't deal with
# that when PIDFile is used.
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet_metadata/github_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def initialize(metadata)
end

# @return [Hash[Symbol, Any]] The outputs for Github Actions
def outputs(beaker_use_fqdn: false, beaker_pidfile_workaround: false)
def outputs(beaker_use_fqdn: false, beaker_pidfile_workaround: false, domain: 'example.com')
{
beaker_setfiles: beaker_setfiles(beaker_use_fqdn, beaker_pidfile_workaround),
beaker_setfiles: beaker_setfiles(beaker_use_fqdn, beaker_pidfile_workaround, domain),
puppet_major_versions: puppet_major_versions,
puppet_unit_test_matrix: puppet_unit_test_matrix,
github_action_test_matrix: github_action_test_matrix(use_fqdn: beaker_use_fqdn, pidfile_workaround: beaker_pidfile_workaround),
Expand All @@ -19,9 +19,9 @@ def outputs(beaker_use_fqdn: false, beaker_pidfile_workaround: false)

private

def beaker_setfiles(use_fqdn, pidfile_workaround)
def beaker_setfiles(use_fqdn, pidfile_workaround, domain)
setfiles = []
metadata.beaker_setfiles(use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround) do |setfile, name|
metadata.beaker_setfiles(use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround, domain: 'example.com') do |setfile, name|
setfiles << {
name: name,
value: setfile,
Expand Down
6 changes: 4 additions & 2 deletions lib/puppet_metadata/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,16 @@ def github_actions
# Whether to set the hostname to a fully qualified domain name
# @param [Boolean] pidfile_workaround
# Whether to apply the Docker pidfile workaround
# @param [String] domain
# The used domain (if use_fqdn is true)
# @yieldparam [String] setfile
# The supported setfile configurations
# @see PuppetMetadata::Beaker#os_release_to_setfile
def beaker_setfiles(use_fqdn: false, pidfile_workaround: false)
def beaker_setfiles(use_fqdn: false, pidfile_workaround: false, domain: 'example.com')
operatingsystems.each do |os, releases|
next unless PuppetMetadata::Beaker.os_supported?(os)
releases&.each do |release|
setfile = PuppetMetadata::Beaker.os_release_to_setfile(os, release, use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround)
setfile = PuppetMetadata::Beaker.os_release_to_setfile(os, release, use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround, domain: 'example.com')
yield setfile if setfile
end
end
Expand Down

0 comments on commit 7662bfb

Please sign in to comment.