Code Monkey home page Code Monkey logo

puppet-module-gems's Introduction

Gitpod ready-to-code

Puppet Module Gems

Table of Contents

  1. Description - What this utility does and why it is useful
  2. Setup - The basics of getting started with Puppet Module Gems
  3. Usage - Configuration options and additional functionality
  4. Reference - An under-the-hood peek at what the module is doing and how
  5. Release Process
  6. Limitations - OS compatibility, etc.
  7. Support

Description

Puppet Module Gems is a utility that generates gemspecs and builds management gems based on a YAML-based configuration. The purpose for these gems is to reduce the amount of changes required to sync shared dependencies across multiple modules’ Gemfiles.

For example, when a dependency gem publishes a new release that requires Ruby 2.3.3, this would normally break all modules that install this gem that run on a version of Ruby less than 2.3.3. To fix this previously, you would need a modulesync to pin the gem to a compatible version. With these new gem management gems, you can instead update the gem version pin in a configuration YAML. The gem management will then build and publish to rubygems, and a bundle update fixes all affected modules.

Setup

Setup Requirements

  • Requires Ruby version 2.0 or greater
  • Requires RubyGems gem version 2.0 or greater
  • Requires Bundler gem version 1.3.0 or greater

Usage

To get started using this utility, first clone this git repository:

git clone [email protected]:puppetlabs/puppet-module-gems.git

Install the development gems:

bundle install

Building the gems

To build the gems with the default configuration, execute the script bundle exec exe/build-gems.rb. The gemspec files and gems will be generated in the pkg directory. Use the push-gems.rb from the same location to push to rubygems.org, if you are a maintainer.

Customizing dependency gems

To build customized dependency gems, you simply need to modify the config yamls prior to running the script.

First modify the config/info.yml to customize the prefix for your gem names, in addition to the rest of the required information. Secondly, you will need to modify the config/dependencies.yml to customize the dependency matrix to suit your needs. After defining these customizations, you can build your gems with the directions detailed in Building the gems.

Using generated gems

To use the resulting gems, replace the sections of the Module Gemfile with the appropriate gems and conditions.

For Example:

group :development do
  gem 'puppet-lint',                        :require => false
  gem 'metadata-json-lint',                 :require => false, :platforms => 'ruby'
  gem 'puppet_facts',                       :require => false
  gem 'puppet-blacksmith', '>= 3.4.0',      :require => false, :platforms => 'ruby'
  gem 'puppetlabs_spec_helper', '>= 1.2.1', :require => false
  gem 'rspec-puppet', '>= 2.3.2',           :require => false
  gem 'rspec-puppet-facts',                 :require => false, :platforms => 'ruby'
  gem 'mocha', '< 1.2.0',                   :require => false
  gem 'simplecov',                          :require => false, :platforms => 'ruby'
  gem 'rubocop',                            :require => false
  gem 'pry',                                :require => false
  gem 'rainbow', '< 2.2.0',                 :require => false
end

group :system_tests do
  gem 'beaker-puppet_install_helper', :require => false
  gem 'beaker-module_install_helper', :require => false
  gem 'master_manipulator',           :require => false
end

The above Gemfile section would become:

# calculate the correct package names from the current ruby version
ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments
minor_version = "#{ruby_version_segments[0]}.#{ruby_version_segments[1]}"

gem "puppet-module-posix-default-r#{minor_version}"

group :development do
  gem "puppet-module-posix-dev-r#{minor_version}"
end

group :system_tests do
  gem "puppet-module-posix-system-r#{minor_version}"
end

After this update, the subsequent bundle install or bundle update would pull in the new gems and the dependencies should reflect the correct version bindings based on the Ruby version. Any future gems and version pinning that may be needed can be done via publishing updated management gems.

Reference

Configuration Files

info.yml

Reserved Keys

  • info - Details the start of the information block. Required.
  • prefix - Indicates the prefix to use for the generated gems. Required.

Required Keys

  • authors - String. The author of these gems.
  • email - String. Email address of the author.
  • homepage - String. Homepage for the gem project.
  • licenses - String. License to publish gems under.
  • summary - String. Brief description of what the gem does.
  • version - String. Version of these gems.

dependencies.yml

Reserved Keys

  • dependencies - Details the start of the dependencies block. Required.
  • shared - Details the shared dependencies amongst the keys within the same tier.
  • gem - Details the name of the gem dependency to add. Required.
  • version - Details the version bindings for the gem listed in preceding gem.

Example

dependencies:
  shared:
    a:
      - gem: shared-gem
        version: '> 1.0.0'
  first:
    a:
      - gem: a-gem-one
    b:
      - gem: b-gem-one
        version: '< 2.0.0'
  second:
    b:
      - gem: b-gem-two

The above dependency matrix will generate this list of gems if the defined prefix is test-gem with version 1.0.0:

  • test-gem-first-a-1.0.0.gem
  • test-gem-first-b-1.0.0.gem
  • test-gem-second-a-1.0.0.gem
  • test-gem-second-b-1.0.0.gem

And for example, the gemspec for test-gem-first-a-1.0.0.gem will include dependencies of:

  • shared-gem, '> 1.0.0'
  • a-gem-one

Note: To add a version range to a dependency, simply put the lower and upper bindings in an array:

- gem: gem-name
  version: ['>= 1.0.0', '< 2.0.0']

Release Process

  • From a clean checkout of main, create a release prep branch.
  • Update config/info.yml with the new version.
  • Update CHANGELOG.md.
  • PR the release prep.
  • Once PR is merged, checkout a clean copy of main.
  • Run bundle exec exe/build-gems.rb to build the gems into the pkg directory.
  • Validate that the gems have build correctly. The next step requires that you have Ownership permissions for these gems on rubygems.org, also requires access to internal Puppet network.
  • Run bundle exec exe/push-gems.rb to update owners and publish to rubygems.org.
  • Tag the version and push tags to github.
    • e.g. git tag -a 0.1.2 -m "0.1.2"
    • e.g. git push upstream --tags

Testing Changes

  • Check out a clean copy from main.
  • Clean out the contents of the pkg directory.
  • Run bundle exec exe/build-gems.rb to build the gems into the pkg directory.
  • Confirm pkg directory contains a variety of .gem and .gemspec files.
  • Locate a module that is making use of puppet-module-gems.
  • Edit the Gemfile and point the gems to the local copy of your gems, using the :path directive.

Example

group :development do
  gem "puppet-module-posix-default-r#{minor_version}",    require: false, platforms: "ruby", path: '/Users/paula/workspace/puppet-module-gems/pkg/'
  gem "puppet-module-win-default-r#{minor_version}",      require: false, platforms: ["mswin", "mingw", "x64_mingw"], path:  '/Users/paula/workspace/puppet-module-gems/pkg/'
  gem "puppet-module-posix-dev-r#{minor_version}",        require: false, platforms: "ruby", :path => '/Users/paula/workspace/puppet-module-gems/pkg/'
  gem "puppet-module-win-dev-r#{minor_version}", '0.0.7', require: false, platforms: ["mswin", "mingw", "x64_mingw"], :path => '/Users/paula/workspace/puppet-module-gems/pkg/'
  gem "json_pure", '<= 2.0.1',                            require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
  gem "fast_gettext", '1.1.0',                            require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0')
  gem "fast_gettext",                                     require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
end
  • Ensure the Gemfile.lock is generated as expected by running bundle install.
  • Compare the installed gems vs earlier versions by saving and comparing Gemfile.lock files from different incantations.

Testing changes on a bigger scale

To test potentially harmful changes with modules on travis, appveyor, or another build systems. You can use a third party gem repository. We recommend using the cloudsmith offering, as it provides native integration into the ruby tool set. Sign up there with your github account and create a open source repository pointing back to this github repo.

  • copy your API key (from Account -> Settings -> API Settings -> API key) into ~/.gem/credentials as :cloudsmith: "Token _the_api_key_here_"
  • bump your version of config.info to something higher than the current release (e.g. '0.4.4' -> '0.4.5'; note that bundler doesn't deal with pre-release versions)
  • make your changes in puppet-module-gems
  • build your packages as described above
  • Upload all the gems by running
    for i in pkg/puppet-module-*.gem; do gem push $i --host https://ruby.cloudsmith.io/david-schmitt/pmg-test --key cloudsmith & done; wait
    
    or similar in your shell
  • Update the module and edit its Gemfile to retrieve the puppet-module-gems from source: 'https://dl.cloudsmith.io/public/david-schmitt/pmg-test/ruby/':
gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby], source: 'https://dl.cloudsmith.io/public/david-schmitt/pmg-test/ruby/'

NB remember to use your actual token and repo URL and unset the

  • test locally, then create your pr for the module.
  • check travis / appveyor / build system for your pass / fails.

Limitations

Use of this utility has only been tested on Linux and OS-X platforms.

Support

These scripts and gems are maintained by the IAC team. Please file an issue for support. Contributions are also welcomed!

puppet-module-gems's People

Contributors

bmjen avatar cdenneen avatar chelnak avatar da-ar avatar daianamezdrea avatar david22swan avatar davids avatar eimlav avatar ekohl avatar eputnam avatar ferventcoder avatar garethr avatar glennsarti avatar hunner avatar jpogran avatar lavinia-dan avatar lionce avatar logicminds avatar michaeltlombardi avatar mikaelsmith avatar pmcmaw avatar ramesh7 avatar rodjek avatar sanfrancrisko avatar sarameisburger avatar scotje avatar sheenaajay avatar tphoney avatar treydock avatar wmuizelaar avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-module-gems's Issues

updated gems broke ruby 2.1.9

Describe the Bug

Gem::InstallError: i18n requires Ruby version >= 2.3.0.
An error occurred while installing i18n (1.6.0), and Bundler cannot continue.
Make sure that `gem install i18n -v '1.6.0' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  puppet-module-posix-dev-r2.1 was resolved to 0.4.2, which depends on
    activesupport was resolved to 5.2.3, which depends on
      i18n


Gem::InstallError: public_suffix requires Ruby version >= 2.3.
An error occurred while installing public_suffix (4.0.1), and Bundler cannot continue.
Make sure that `gem install public_suffix -v '4.0.1' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  puppet-module-posix-dev-r2.1 was resolved to 0.4.2, which depends on
    metadata-json-lint was resolved to 2.2.0, which depends on
      json-schema was resolved to 2.8.1, which depends on
        addressable was resolved to 2.7.0, which depends on
          public_suffix


Gem::InstallError: parallel requires Ruby version >= 2.2.
An error occurred while installing parallel (1.17.0), and Bundler cannot continue.
Make sure that `gem install parallel -v '1.17.0' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  puppet-module-posix-dev-r2.1 was resolved to 0.4.2, which depends on
    dependency_checker was resolved to 0.2.0, which depends on
      parallel


Gem::InstallError: net-ssh requires Ruby version >= 2.2.6.
An error occurred while installing net-ssh (5.2.0), and Bundler cannot continue.
Make sure that `gem install net-ssh -v '5.2.0' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  puppet-module-posix-dev-r2.1 was resolved to 0.4.2, which depends on
    serverspec was resolved to 2.41.5, which depends on
      specinfra was resolved to 2.77.1, which depends on
        net-scp was resolved to 2.0.0, which depends on
          net-ssh


pdk (FATAL): Unable to install missing Gemfile dependencies.

Expected Behavior

should have resolved the dependencies

Steps to Reproduce

Must be using ruby 2.1.9
Must be using pdk as the gem

docker run -ti --rm ruby:2.1.9 /bin/bash
gem install addressable -v 2.6.0 -N
gem install pdk -N
pdk new module

Environment

  • Version [0.4.2]
  • Platform [{"name"=>"Debian", "family"=>"Debian", "release"=>{"major"=>"8", "minor"=>"5", "full"=>"8.5"}}]

Ruby 3 support

I realized there's no puppet-module-posix-default-r3.0 package on rubygems.

Is Ruby 3 not supported?

update rubocop to a current version

dev:
  shared:
    gem: rubocop
    version: '~> 0.49.0'

0.49.0 has been out for almost 2 years now. version 0.74.0 has been out for over a month

the old version plays havoc with new gems like solargraph which require at least 0.54 to work correctly

Codecov yanked older versions, including the one used as a dependency

Describe the Bug

Dependency for this gem include

gem: codecov
          version: '~> 0.1.10'

However all 1.x codecov versions were removed from Rubygems, as explained in this deprecation notice: codecov/codecov-ruby#87.

As a consequence, trying to download puppet-module-posix-dev-* results in:

Bundler could not find compatible versions for gem "codecov":
  In Gemfile:
puppet-module-posix-dev-r2.4 (~> 0.4) was resolved to 0.5.0, which depends
on
      codecov (~> 0.1.10)
Could not find gem 'codecov (~> 0.1.10)', which is required by gem
'puppet-module-posix-dev-r2.4 (~> 0.4)', in any of the sources.

Expected Behavior

I expected the gem to be installed successfully

Steps to Reproduce

  • Create a Gemfile including puppet-module-posix-dev-*
  • Run bundle install

Dependency on specinfra

Current dependency on specinfra is causing failures in windows spec testing. V2.67.3 requires net-ssh < 5.0, but >=5.0 is needed to start windows spec testing as it maintains a patch to the error referenced below. Below is a screen shot of the current error being caused. I have manually changed specinfra's dependencies in the gemfile.lock in my local testing and it then runs correctly, but as soon as I run bundle update it reverts back to a prior version of net-ssh due to this dependency.
screen shot 2018-08-24 at 9 20 27 am

Release version 1.1.1 of Puppet Module Gems

This ticket encompasses:

  • Releasing version 1.1.1 of PMG
  • Creating a new script for adding / removing gem owners
  • Updating the gem owners list to be relevant to the current state of Puppet employees

v0.5.3 has a broken dependency chain in PDK docker image

Describe the Bug

We're having issues running pdk tests in puppet/pdk container with the following gem definition in the Gemfile of our module:

group :development do
  gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4',     require: false, platforms: [:ruby]
end

This results in:

13:08:46  An error occurred while installing http-parser (1.2.2), and Bundler cannot
13:08:46  continue.
13:08:46  Make sure that `gem install http-parser -v '1.2.2' --source
13:08:46  'https://rubygems.org/'` succeeds before bundling.
13:08:46  
13:08:46  In Gemfile:
13:08:46    puppet-module-posix-dev-r2.5 was resolved to 0.5.3, which depends on
13:08:46      puppet_litmus was resolved to 0.18.4, which depends on
13:08:46        rspec_honeycomb_formatter was resolved to 0.2.1, which depends on
13:08:46          honeycomb-beeline was resolved to 2.3.0, which depends on
13:08:46            libhoney was resolved to 1.15.0, which depends on
13:08:46              http was resolved to 4.4.1, which depends on
13:08:46                http-parser

I am guessing that it's a problem with the dependencies or the image itself.

Earliest working gem version that passes this point is puppet-module-posix-dev-r2.5 v0.5.0

Expected Behavior

No problems running tests

Steps to Reproduce

Steps to reproduce the behavior:

Easy reproduction:

  1. Clone our project: https://github.com/cyberark/conjur-puppet
  2. You must have a clean checkout of this repo - problem is cache related
  3. Run ./scripts/test.sh

Minimal reproduction

  • Gemfile
source 'https://rubygems.org'

group :development do
  gem "puppet-module-posix-dev-r2.5", '0.5.3',      require: false, platforms: [:ruby]
end
  • metadata.json
{
  "name": "cyberark-conjur",
  "version": "3.1.0",
  "dependencies": [
    {
      "name": "puppetlabs/registry",
      "version_requirement": ">= 3.1.0 < 4.0.0"
    }
  ],
  "operatingsystem_support": [
    {
      "operatingsystem": "Ubuntu",
      "operatingsystemrelease": [
        "20.04"
      ]
    }
  ],
  "requirements": [
    {
      "name": "puppet",
      "version_requirement": ">= 6.0.0 < 7.0.0"
    }
  ],
  "pdk-version": "1.18.1",
  "template-url": "pdk-default#1.18.1",
  "template-ref": "tags/1.18.1-0-g3d2e75c"
}
  • Run docker run --rm -it -w /root -v $(pwd)/Gemfile:/root/Gemfile -v $(pwd)/metadata.json:/root/metadata.json puppet/pdk test unit

Environment

pdk (INFO): Using Ruby 2.5.8
pdk (INFO): Using Puppet 6.17.0
  • Version v0.5.3
  • Platform: puppet/pdk DockerHub container

Additional Context

Add any other context about the problem here.

Missing ruby 2.1 pins

I've found I've also had to pin public_suffix to 3.1.1 and parallel to 1.13.0.
Should I add them here, or am I missing something?

Please publish gems for Ruby 2.7

Use Case

Hi people, since this project started some time ago, I'm unable to execute the puppetlabs test suite locally every spring :( Ruby 2.7 is stable since months, but you don't publish gems for that. Cold you please update it?

Describe the Solution You Would Like

I want that a simple bundle install within any of the official Puppet Inc. modules work and pulls in Ruby 2.7 specifc gems.

Describe Alternatives You've Considered

Patching the Gemfile to pull in the older 2.6 gems works, but that's annoying and currently one of the blockers for rolling out pdk to Vox Pupuli modules.

Additional Context

There is a regular release schedule for Ruby with a big release every year around christmas. I would like to see a process to build new gems for those versions early / automated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.