puppet_metadata 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b9da6033c7aa055e1e88289211ad3356764ea737184fd594fce1c31e1e94c27
4
- data.tar.gz: 8fdfd523619505b15568769eb276424cffcc5c257c3a08377ee8a7abd8571701
3
+ metadata.gz: 9c9d6561f0093dee6ac521a50bfd507ab2695e192530bb5fdd28dd5264009af3
4
+ data.tar.gz: 688205c5b0991c110f288b2acaa54048c6866eeb2f4ced9d392b87e5ddbad535
5
5
  SHA512:
6
- metadata.gz: 574fb26918bdd3c5b7a7ccad604557cb130797f704c87102d552fe3ef5a121acd15d4be22ba67bd273ba3d0d35a4c5b44c1ed8fe48e09b019da3785f9a149a9f
7
- data.tar.gz: fcf0a1b46a59fdfbd3f6269f430495a63acbfc387c187658b25b4466fd8c0a0b5835cf221a5f6b7fcfdcd8f15208ab28141815edb8701666f9cefc47a422f99b
6
+ metadata.gz: 1dfc8d32b372c913d9a86937328f131647f487d546e22cd105547788f3af3396b36049c0c350ee4802baa19d90c00d230acf3bccd6fd8a499170eccb91ec4440
7
+ data.tar.gz: d87f9a1be70d013480f72e319f4a9c8179157eb2425bf1be6ae4acafbe5d908a5ed5aa0cfa67bfb33204087a27b3844a0d1f56d0dab408ffa183beccb45981ed
data/README.md CHANGED
@@ -1,3 +1,119 @@
1
1
  # puppet_metadata
2
2
 
3
+ [![License](https://img.shields.io/github/license/voxpupuli/puppet_metadata.svg)](https://github.com/voxpupuli/puppet_metadata/blob/master/LICENSE)
4
+ [![Test](https://github.com/voxpupuli/puppet_metadata/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/puppet_metadata/actions/workflows/test.yml)
5
+ [![codecov](https://codecov.io/gh/voxpupuli/puppet_metadata/branch/master/graph/badge.svg?token=Mypkl78hvK)](https://codecov.io/gh/voxpupuli/puppet_metadata)
6
+ [![Release](https://github.com/voxpupuli/puppet_metadata/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/puppet_metadata/actions/workflows/release.yml)
7
+ [![RubyGem Version](https://img.shields.io/gem/v/puppet_metadata.svg)](https://rubygems.org/gems/puppet_metadata)
8
+ [![RubyGem Downloads](https://img.shields.io/gem/dt/puppet_metadata.svg)](https://rubygems.org/gems/puppet_metadata)
9
+ [![Donated by Ewoud Kohl van Wijngaarden](https://img.shields.io/badge/donated%20by-Ewoud%20Kohl%20van%20Wijngaarden-fb7047.svg)](#copyright)
10
+
3
11
  The gem intends to provide an abstraction over Puppet's metadata.json file. Its API allow easy iteration over its illogical data structures.
12
+
13
+ ## Generating Github Actions outputs
14
+
15
+ To get outputs [usable in Github Actions](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions), there is the `metadata2gha` command available. This generates based on metadata.json, such as [Beaker](https://github.com/voxpupuli/beaker) setfiles, Puppet major versions and a Puppet unit test matrix.
16
+
17
+ ```console
18
+ $ metadata2gha-beaker
19
+ ::set-output name=beaker_setfiles::[{"name":"CentOS 7","value":"centos7-64"},{"name":"CentOS 8","value":"centos8-64"},{"name":"Debian 10","value":"debian10-64"},{"name":"Ubuntu 18.04","value":"ubuntu1804-64"}]
20
+ ::set-output name=puppet_major_versions::[{"name":"Puppet 6","value":6,"collection":"puppet6"},{"name":"Puppet 5","value":5,"collection":"puppet5"}]
21
+ ::set-output name=puppet_unit_test_matrix::[{"puppet":6,"ruby":"2.5"},{"puppet":5,"ruby":"2.4"}]
22
+ ```
23
+
24
+ Beaker setfiles formatted for readability:
25
+ ```json
26
+ [
27
+ {
28
+ "name": "CentOS 7",
29
+ "value": "centos7-64"
30
+ },
31
+ {
32
+ "name": "CentOS 8",
33
+ "value": "centos8-64"
34
+ },
35
+ {
36
+ "name": "Debian 10",
37
+ "value": "debian10-64"
38
+ },
39
+ {
40
+ "name": "Ubuntu 18.04",
41
+ "value": "ubuntu1804-64"
42
+ }
43
+ ]
44
+ ```
45
+
46
+ Puppet major versions formatted for readability:
47
+ ```json
48
+ [
49
+ {
50
+ "name": "Puppet 6",
51
+ "value": 6,
52
+ "collection": "puppet6"
53
+ },
54
+ {
55
+ "name": "Puppet 5",
56
+ "value": 5,
57
+ "collection": "puppet5"
58
+ }
59
+ ]
60
+ ```
61
+
62
+ Puppet unit test matrix formatted for readability:
63
+ ```json
64
+ [
65
+ {
66
+ "puppet": 6,
67
+ "ruby": "2.5"
68
+ },
69
+ {
70
+ "puppet": 5,
71
+ "ruby": "2.4"
72
+ }
73
+ ]
74
+ ```
75
+
76
+ It is also possible to specify the path to metadata.json and customize the setfiles. For example, to ensure the setfiles use FQDNs and apply the [systemd PIDFile workaround under docker](https://github.com/docker/for-linux/issues/835). This either means either using an older image (CentOS 7, Ubuntu 16.04) or skipping (CentOS 8).
77
+
78
+ ```console
79
+ $ metadata2gha --use-fqdn --pidfile-workaround true /path/to/metadata.json
80
+ ```
81
+
82
+ This results in the following JSON data
83
+ ```json
84
+ [
85
+ {
86
+ "name": "CentOS 7",
87
+ "value": "centos7-64{hostname=centos7-64.example.com,image=centos:7.6.1810}"
88
+ },
89
+ {
90
+ "name": "Debian 10",
91
+ "value": "debian10-64{hostname=debian10-64.example.com}"
92
+ },
93
+ {
94
+ "name": "Ubuntu 18.04",
95
+ "value": "ubuntu1804-64{hostname=ubuntu1804-64.example.com}"
96
+ }
97
+ ]
98
+ ```
99
+
100
+ It is also possible to specify a comma separated list of operating systems as used in `metadata.json` (`CentOS,Ubuntu`).
101
+
102
+ ## Transfer Notice
103
+
104
+ This plugin was originally authored by [Ewoud Kohl van Wijngaarden](https://github.com/ekohl).
105
+ The maintainer preferred that [Vox Pupuli](https://voxpupuli.org/) take ownership of the module for future improvement and maintenance.
106
+ Existing pull requests and issues were transferred, please fork and continue to contribute [here](https://github.com/voxpupuli/puppet_metadata).
107
+
108
+ ## License
109
+
110
+ This gem is licensed under the Apache-2 license.
111
+
112
+ ## Release information
113
+
114
+ To make a new release, please do:
115
+ * Update the version in the puppet_metadata.gemspec file
116
+ * Install gems with `bundle install --with release --path .vendor`
117
+ * generate the changelog with `bundle exec rake changelog`
118
+ * Create a PR with it
119
+ * After it got merged, push a tag. A github workflow will do the actual release
data/bin/metadata2gha ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'json'
4
+ require 'puppet_metadata'
5
+
6
+ PidfileWorkaround = Object.new
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.accept(PidfileWorkaround) do |value|
11
+ case value
12
+ when 'true'
13
+ true
14
+ when 'false'
15
+ false
16
+ else
17
+ value.split(',')
18
+ end
19
+ end
20
+
21
+ opts.banner = "Usage: #{$0} [options] metadata"
22
+
23
+ opts.on("--[no-]use-fqdn", "Generate beaker setfiles with a FQDN")
24
+ opts.on("--pidfile-workaround VALUE", "Generate the systemd PIDFile workaround to work around a docker bug", PidfileWorkaround)
25
+ end.parse!(into: options)
26
+
27
+ filename = ARGV[0]
28
+ if filename.nil? || filename.empty?
29
+ filename = 'metadata.json'
30
+ end
31
+
32
+ begin
33
+ metadata = PuppetMetadata.read(filename)
34
+ rescue StandardError => e
35
+ STDERR.puts "Failed to read #{filename}: #{e}"
36
+ exit 2
37
+ end
38
+
39
+ metadata.github_actions.outputs(beaker_use_fqdn: options[:'use-fqdn'], beaker_pidfile_workaround: options[:'pidfile-workaround']).each do |name, value|
40
+ puts "::set-output name=#{name}::#{value.to_json}"
41
+ end
@@ -1,6 +1,8 @@
1
1
  # A module that provides abstractions around Puppet's metadata format.
2
2
  module PuppetMetadata
3
+ autoload :AIO, 'puppet_metadata/aio'
3
4
  autoload :Beaker, 'puppet_metadata/beaker'
5
+ autoload :GithubActions, 'puppet_metadata/github_actions'
4
6
  autoload :Metadata, 'puppet_metadata/metadata'
5
7
  autoload :OperatingSystem, 'puppet_metadata/operatingsystem'
6
8
 
@@ -0,0 +1,58 @@
1
+ module PuppetMetadata
2
+ class AIO
3
+ COMPATIBLE = {
4
+ 'AlmaLinux' => 'RedHat',
5
+ 'Amazon' => 'RedHat',
6
+ 'CentOS' => 'RedHat',
7
+ 'OracleLinux' => 'RedHat',
8
+ 'Rocky' => 'RedHat',
9
+ 'Scientific' => 'RedHat',
10
+ }
11
+
12
+ BUILDS = {
13
+ # RPM-based
14
+ 'RedHat' => {
15
+ '5' => 5..7,
16
+ '6' => 5..7,
17
+ '7' => 5..7,
18
+ '8' => 5..7,
19
+ },
20
+ 'Fedora' => {
21
+ '26' => [5],
22
+ '27' => 5..6,
23
+ '28' => 5..6,
24
+ '29' => 5..6,
25
+ '30' => 5..7,
26
+ '31' => 5..7,
27
+ '32' => 6..7,
28
+ '34' => 6..7,
29
+ },
30
+ 'SLES' => {
31
+ '11' => [7],
32
+ '12' => [7],
33
+ '15' => [7],
34
+ },
35
+ # deb-based
36
+ 'Debian' => {
37
+ '7' => [5],
38
+ '8' => 5..7,
39
+ '9' => 5..7,
40
+ '10' => 5..7,
41
+ },
42
+ 'Ubuntu' => {
43
+ '14.04' => 5..6,
44
+ '16.04' => 5..7,
45
+ '18.04' => 5..7,
46
+ '20.04' => 6..7,
47
+ },
48
+ }
49
+
50
+ def self.find_base_os(os)
51
+ COMPATIBLE.fetch(os, os)
52
+ end
53
+
54
+ def self.has_aio_build?(os, release, puppet_version)
55
+ BUILDS.dig(find_base_os(os), release)&.include?(puppet_version)
56
+ end
57
+ end
58
+ end
@@ -12,13 +12,16 @@ module PuppetMetadata
12
12
  # @param [String] release The OS release
13
13
  # @param [Boolean] use_fqdn
14
14
  # Whether or not to use a FQDN, ensuring a domain
15
- # @param [Boolean] pidfile_workaround
15
+ # @param [Boolean, Array[String]] pidfile_workaround
16
16
  # Whether or not to apply the systemd PIDFile workaround. This is only
17
17
  # needed when the daemon uses PIDFile in its service file and using
18
18
  # Docker as a Beaker hypervisor. This is to work around Docker's
19
19
  # limitations.
20
+ # When a boolean, it's applied on applicable operating systems. On arrays
21
+ # it's applied only when os is included in the provided array.
20
22
  #
21
- # @return [String] The beaker setfile description or nil
23
+ # @return [nil] If no setfile is available
24
+ # @return [Array<(String, String)>] The beaker setfile description with a readable name
22
25
  def self.os_release_to_setfile(os, release, use_fqdn: false, pidfile_workaround: false)
23
26
  return unless os_supported?(os)
24
27
 
@@ -26,12 +29,20 @@ module PuppetMetadata
26
29
 
27
30
  options = {}
28
31
  options[:hostname] = "#{name}.example.com" if use_fqdn
32
+
29
33
  # Docker messes up cgroups and modern systemd can't deal with that when
30
34
  # PIDFile is used.
31
- if pidfile_workaround
35
+ if pidfile_workaround && (!pidfile_workaround.is_a?(Array) || pidfile_workaround.include?(os))
32
36
  case os
33
37
  when 'CentOS'
34
- options[:image] = 'centos:7.6.1810' if release == '7'
38
+ case release
39
+ when '7'
40
+ options[:image] = 'centos:7.6.1810'
41
+ when '8'
42
+ # There is no CentOS 8 image that works with PIDFile in systemd
43
+ # unit files
44
+ return
45
+ end
35
46
  when 'Ubuntu'
36
47
  options[:image] = 'ubuntu:xenial-20191212' if release == '16.04'
37
48
  end
@@ -39,7 +50,10 @@ module PuppetMetadata
39
50
 
40
51
  setfile = name
41
52
  setfile += "{#{options.map { |key, value| "#{key}=#{value}" }.join(',')}}" if options.any?
42
- setfile
53
+
54
+ human_name = "#{os} #{release}"
55
+
56
+ [setfile, human_name]
43
57
  end
44
58
 
45
59
  # Return whether a Beaker setfile can be generated for the given OS
@@ -0,0 +1,94 @@
1
+ module PuppetMetadata
2
+ class GithubActions
3
+ attr_reader :metadata
4
+
5
+ # @param [PuppetMetadata::Metadata] metadata
6
+ def initialize(metadata)
7
+ @metadata = metadata
8
+ end
9
+
10
+ # @return [Hash[Symbol, Any]] The outputs for Github Actions
11
+ def outputs(beaker_use_fqdn: false, beaker_pidfile_workaround: false)
12
+ {
13
+ beaker_setfiles: beaker_setfiles(beaker_use_fqdn, beaker_pidfile_workaround),
14
+ puppet_major_versions: puppet_major_versions,
15
+ puppet_unit_test_matrix: puppet_unit_test_matrix,
16
+ github_action_test_matrix: github_action_test_matrix,
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def beaker_setfiles(use_fqdn, pidfile_workaround)
23
+ setfiles = []
24
+ metadata.beaker_setfiles(use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround) do |setfile, name|
25
+ setfiles << {
26
+ name: name,
27
+ value: setfile,
28
+ }
29
+ end
30
+ setfiles
31
+ end
32
+
33
+ def puppet_major_versions
34
+ metadata.puppet_major_versions.sort.reverse.map do |version|
35
+ {
36
+ name: "Puppet #{version}",
37
+ value: version,
38
+ collection: "puppet#{version}",
39
+ }
40
+ end
41
+ end
42
+
43
+ def puppet_unit_test_matrix
44
+ metadata.puppet_major_versions.sort.reverse.map do |puppet|
45
+ ruby = puppet_ruby_version(puppet)
46
+ next unless ruby
47
+
48
+ {
49
+ puppet: puppet,
50
+ ruby: ruby,
51
+ }
52
+ end.compact
53
+ end
54
+
55
+ def puppet_ruby_version(puppet_version)
56
+ case puppet_version
57
+ when 4
58
+ '2.1'
59
+ when 5
60
+ '2.4'
61
+ when 6
62
+ '2.5'
63
+ when 7
64
+ '2.7'
65
+ end
66
+ end
67
+
68
+
69
+ def github_action_test_matrix(use_fqdn: false, pidfile_workaround: false)
70
+ matrix_include = []
71
+
72
+ metadata.operatingsystems.each do |os, releases|
73
+ releases&.each do |release|
74
+ puppet_major_versions.each do |puppet_version|
75
+ next unless AIO.has_aio_build?(os, release, puppet_version[:value])
76
+
77
+ setfile = PuppetMetadata::Beaker.os_release_to_setfile(os, release, use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround)
78
+ next unless setfile
79
+
80
+ matrix_include << {
81
+ setfile: {
82
+ name: setfile[1],
83
+ value: setfile[0],
84
+ },
85
+ puppet: puppet_version
86
+ }
87
+ end
88
+ end
89
+ end
90
+
91
+ matrix_include
92
+ end
93
+ end
94
+ end
@@ -135,6 +135,21 @@ module PuppetMetadata
135
135
  matches?(requirements[name], version)
136
136
  end
137
137
 
138
+ # @return [Array[Integer]] Supported major Puppet versions
139
+ # @see #requirements
140
+ def puppet_major_versions
141
+ requirement = requirements['puppet']
142
+ raise Exception, 'No Puppet requirement found' unless requirement
143
+
144
+ # Current latest major is 7. It is highly recommended that modules
145
+ # actually specify exact bounds, but this prevents an infinite loop.
146
+ end_major = requirement.end == SemanticPuppet::Version::MAX ? 7 : requirement.end.major
147
+
148
+ (requirement.begin.major..end_major).select do |major|
149
+ requirement.include?(SemanticPuppet::Version.new(major, 0, 0)) || requirement.include?(SemanticPuppet::Version.new(major, 99, 99))
150
+ end
151
+ end
152
+
138
153
  # A hash representation of the dependencies
139
154
  #
140
155
  # Every element in the original array is converted. The name is used as a
@@ -167,6 +182,11 @@ module PuppetMetadata
167
182
  matches?(dependencies[name], version)
168
183
  end
169
184
 
185
+ # @return [PuppetMetadata::GithubActions] A GithubActions instance
186
+ def github_actions
187
+ PuppetMetadata::GithubActions.new(self)
188
+ end
189
+
170
190
  # @param [Boolean] use_fqdn
171
191
  # Whether to set the hostname to a fully qualified domain name
172
192
  # @param [Boolean] pidfile_workaround
metadata CHANGED
@@ -1,30 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  - Ewoud Kohl van Wijngaarden
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-18 00:00:00.000000000 Z
12
+ date: 2021-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: metadata-json-lint
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '2.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '4'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: '2.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: semantic_puppet
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -112,21 +118,25 @@ dependencies:
112
118
  description: A package that provides abstractions for the Puppet Metadata
113
119
  email:
114
120
  - voxpupuli@groups.io
115
- executables: []
121
+ executables:
122
+ - metadata2gha
116
123
  extensions: []
117
124
  extra_rdoc_files:
118
125
  - README.md
119
126
  files:
120
127
  - README.md
128
+ - bin/metadata2gha
121
129
  - lib/puppet_metadata.rb
130
+ - lib/puppet_metadata/aio.rb
122
131
  - lib/puppet_metadata/beaker.rb
132
+ - lib/puppet_metadata/github_actions.rb
123
133
  - lib/puppet_metadata/metadata.rb
124
134
  - lib/puppet_metadata/operatingsystem.rb
125
135
  homepage: http://github.com/voxpupuli/puppet_metadata
126
136
  licenses:
127
137
  - Apache-2.0
128
138
  metadata: {}
129
- post_install_message:
139
+ post_install_message:
130
140
  rdoc_options:
131
141
  - "--main"
132
142
  - README.md
@@ -143,8 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
153
  - !ruby/object:Gem::Version
144
154
  version: '0'
145
155
  requirements: []
146
- rubygems_version: 3.1.2
147
- signing_key:
156
+ rubygems_version: 3.2.22
157
+ signing_key:
148
158
  specification_version: 4
149
159
  summary: Data structures for the Puppet Metadata
150
160
  test_files: []