Giter VIP home page Giter VIP logo

pdk-templates's Introduction

PDK Templates

Code Owners ci

The pdk-templates repository contains the default templates (or blueprints) used by the Puppet Development Kit to create, convert, and update modules.

The following table shows the directories where different types of template are stored.

moduleroot Stores templates that are deployed on pdk new module, pdk convert and pdk update commands. Use the templates in this directory to enforce a common boilerplate for central files.
moduleroot_init Stores light versions of moduleroot templates. The templates in this directory create a skeleton for the files the developer will need. Deploy these templates when the target module does not yet exist.
object_templates Stores templates that are used by the various new commands. These are in charge of building classes, defined types, etc

Use this README to understand the purpose, basic usage, and common configurable values for PDK templates. For further information about PDK, refer to our documentation site.

Table of contents

How templates are used by PDK

When you use PDK to build, convert, or update a module, PDK accesses the relevant template in the pdk-templates repository to retrieve default “instructions” on how to build the module. Those instructions are applied to the local repo in which the command was run.

When configuring the module, PDK reads a set of default settings in .config_defaults.yml and merges it with the configuration settings in .sync.yml.

The result of this merge creates a hidden hash containing the final configuration of the module that PDK applies. Top-level keys of this resulting hash correspond to target files. A global configuration is merged with the configuration hash for a particular target file. This allows module developers to override or amend the configuration by adding new values through .sync.yml. For example, a knockout prefix (---) can be applied to keys in .sync.yml to remove default configuration values.

Target files are created by rendering a corresponding template which refers its configuration via the @configs hash.

You can configure PDK to make files executable if the file is executable in the template. To do this, include manage_execute_permissions: true either in the target file or globally via the common config key.

Basic Usage

By default PDK uses the templates within this repository to render files for use within a module. To use a third-party template, pass its URL using the –-template-url flag as shown in the following example:

pdk convert --template-url https://github.com/puppetlabs/pdk-templates

PDK will default to the main branch when looking at the repository. You can specify other branches by using the --template-ref, like this:

pdk convert --template-url https://github.com/puppetlabs/pdk-templates --template-ref branch_name

Note: Commands run on PDK will use the last specified template repository.

When you have specified the template repository, you can get started with creating a module, if you don't already have one. Once your module is created, you can customize PDK-templates by editing the .sync.yml to override the default configuration, and then running PDK update on the module so that the new settings are applied.

For more information on basic usage and more detailed description of PDK in action please refer to PDK documentation, where you can find detailed instructions on how to create, convert and update modules, as well as other useful commands.

Adjusting templates via .sync.yml

While we provide a basic template it is likely that it will not match what you need exactly, as such we allow it to be altered or added to through the use of the .sync.yml file.

Here we will provide some examples of how you can use .sync.yml. For a more comprehensive list of default settings, check the PDK default config values section.

Adding configuration values

Values can be added to the data passed to the templates, thus allowing you to make changes such as testing against additional operating systems or adding new rubocop rules.

To add a value to an array simply place it into the .sync.yml file as shown below, here is the structure to add an additional unit test run against Puppet 6:

.travis.yml:
  includes:
    - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
      rvm: 2.5.0

Removing default configuration values

Values can be removed from the data passed to the templates using the knockout prefix --- in .sync.yml.

To remove a value from an array, prefix the value ---. For example, to remove 2.7.8 from the ruby_versions array in .travis.yml:

.travis.yml:
  ruby_versions:
    - '---2.7.8'

To remove a key from a hash, set the value to ---. For example, to remove the ip fact from spec/default_facts.yml:

spec/default_facts.yml:
  networking:
    ip: '---'

Excluding files from default behaviour

You can also configure the system to ignore specific files when performing default configuration. For example, we can prevent all .erb files from being targeted by the .gitattributes group settings by using:

".gitattributes": 
  exclude: 
  - "*.erb"

Unmanaged and delete keys

The unmanaged and delete keys also allow you to override default configurations. The unmanaged key allows you to specify files that are to be left untouched by the conversion or update, and delete allows you to specify that a file should be excluded from the module when you convert or update the module.

In the following example, the unmanaged and delete keys are used to specify that, regardless of the default setting defined in config_defaults.yml, PDK should leave the ci.yml file unmodified and delete travis.yml.

.github/workflows/ci.yml: 
  unmanaged: true 
.travis.yml: 
  delete: true

Setting custom gems in the Gemfile

To add a custom internal puppet-lint plugin served from an internal Rubygems source, add an entry similar to the following in .sync.yml file and run pdk update.

Gemfile:
  optional:
    ':development':
      - gem: 'puppet-lint-my_awesome_custom_module'
        version: '>= 2.0'
        source: 'https://myrubygems.example.com/'

Manage Rubocop rules

To disable or enable certain Rubocop rules, use the following structure:

.rubocop.yml:
  default_configs:
    Style/Documentation:
      Enabled: false

PDK default config values

The following is a description and explanation of each of the keys within .config_defaults.yml. This will help clarify the default settings that are applied by PDK.

All the values defined below can be overriden through .sync.yml.

common

Settings common to all templates

Key Description
manage_execute_permissions Templates with execute permissions will be made executable in the module.

.gitattributes

A .gitattributes file in your repo allows you to ensure consistent git settings.

Key Description
include Defines which extensions are handled by git automatic conversions (see the gitattributes documentation). The default configuration helps to keep line endings consistent between windows and linux users.

.gitignore

A .gitignore file in your repo allows you to specify intentionally untracked files to ignore.

Key Description
required The default list of files or paths for git to ignore or untrack that are commonly specified in a module project.
paths Defines any additional files or paths for git to ignore or untrack. (see the gitignore documentation).

Github Workflows

These workflows are depending on puppet-internal resources and are currently not suited for public consumption. Feel free to take them as inspiration how to run some tests on Github Actions. Please let us know at [email protected] what you come up with!

.github/workflows/release_prep.yml

The release_prep workflow prepares a module release PR. By default the workflow can be triggered manually when a release preparation PR needs to be created, however it allows setting a cron based trigger that can run automatically. To set up the automated release cron you can add a configuration to your .sync.yml file that matches the following example:

release_schedule:
   cron: '0 3 * * 6'

In this example the automated release prep workflow is triggered every Saturday at 3 am.

.pdkignore

A .pdkignore file in your repo allows you to specify files to ignore when building a module package with pdk build.

Key Description
required The default list of files or paths for PDK to ignore when building a module package.
paths Defines additional files or paths for PDK to ignore when building a module package.

.yardopts

YARD is a documentation generation tool for the Ruby programming language. It enables the user to generate consistent, usable documentation that can be exported to a number of formats very easily, and also supports extending for custom Ruby constructs such as custom class level definitions.

Key Description
markup Specifies the markup formatting of your documentation. Default is markdown.
optional Define any additional arguments you want to pass through to the yardoc command.

Rakefile

Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax within the Rakefile, present in the root directory of the code repository. Within modules context Rake tasks are used quite frequently, from ensuring the integrity of a module, running validation and tests, to tasks for releasing modules.

Key Description
requires A list of hashes with the library to 'require', and an optional 'conditional'.
changelog_user Sets the github user for the change_log_generator rake task. Optional, if not set it will read the author from the metadata.json file.
changelog_project Sets the github project name for the change_log_generator rake task. Optional, if not set it will parse the source from the metadata.json file
changelog_since_tag Sets the github since_tag for the change_log_generator rake task. Required for the changelog rake task.
changelog_max_issues Sets the github max_issues for the change_log_generator rake task. Optional to limit max issues.
changelog_version_tag_pattern Template how the version tag is to be generated. Defaults to 'v%s' which eventually align with tag_pattern property of puppet-blacksmith, thus changelog is referring to the correct version tags and compare URLs.
github_site Override built-in default for public GitHub. Useful for GitHub Enterprise and other. (Example: github_site = https://git.domain.tld)
github_endpoint Override built-in default for public GitHub. Useful for GitHub Enterprise and other. (Example: github_endpoint = https://git.domain.tld/api/v4)
default_disabled_lint_checks Defines any checks that are to be disabled by default when running lint checks. As default we disable the --relative lint check, which compares the module layout relative to the module root. Does affect .puppet-lint.rc.
extra_disabled_lint_checks Defines any checks that are to be disabled as extras when running lint checks. No defaults are defined for this configuration. Does affect .puppet-lint.rc.
extras An array of extra lines to add into your Rakefile. As an alternative you can add a directory named rakelib to your module and files in that directory that end in .rake would be loaded by the Rakefile. Example, to add syntax check exclusion paths for plan directories:

Rakefile:
extras:
- 'PuppetSyntax.exclude_paths = ["plans/**/*.pp","central/modules/deployments/plans/**/*.pp"]'
linter_options An array of options to be passed into linter config. Does affect .puppet-lint.rc.
linter_fail_on_warnings A boolean indicating if the linter should exit non-zero on warnings as well as failures. Does affect .puppet-lint.rc.
linter_exclusions An array of paths that the linter should exclude from running against.

.rubocop.yml

RuboCop is a Ruby static code analyzer. We use Rubocop to enforce a level of quality and consistency within Ruby code. Rubocop can be configured within .rubocop.yml which is located in the root directory of the code repository. Rubocop works by defining a sanitized list of cops that'll cleanup a code base without much effort, all of which support autocorrect and that are fairly uncontroversial across wide segments of the Community.

Key Description
include_todos Allows you to use rubocop's "TODOs" to temporarily skip checks by setting this to true. See rubocop's --auto-gen-config option for details. Defaults to false.
selected_profile Allows you to define which profile is used by default, which is set to strict, which is fully defined within the profiles section.
default_configs Allows you to define the default configuration of which cops will run. Includes the full name of the cop followed by a description of it and an enforced style. Can also make use of the key excludes to exclude any files from that specific cop.
cleanup_cops Defines a set of cleanup cops to then be included within a rubocop profile. Cops are defined by their full name, and further configuration can be done by specifying secondary keys. By default we specify a large amount of cleanup cops using their default configuration.
profiles Defines the profiles that can be enabled and used within rubocop through the selected_profile option. By default we have set up three profiles: cleanups_only, strict, hardcore and off.

Gemfile

A Gemfile is a file we create which is used for describing gem dependencies for Ruby programs. All modules should have an associated Gemfile for installing the relevant gems. As development and testing is somewhat consistant between modules we have used the template to define a set of gems relevant to these processes.

Key Description
required Allows you to specify gems that are required within the Gemfile. Gems can be defined here within groups, for example we use the :development gem group to add in several gems that are relevant to the development of any module and the :system_tests gem group for gems relevant only to acceptance testing.
optional Allows you to specify additional gems that are required within the Gemfile. This key can be used to further configure the Gemfile through assignment of a value in the .sync.yml file.
overrides Allows you to specify an array of gems that should override template default gems of the same name. This is an advanced option which may result in unresolved dependencies or other unexpected interactions.

Within each Gem group defined using the options above one or more gem item definitions may be listed in an array. Each item in that array must be a gem item hash.

Gem Item Hash Keys Description
gem Required option specifying the gem name.
version Required option to specify version or range of versions required using RubyGem version syntax.
platforms Defines an array of platforms for which the Gem should be included. See the Gemfile platform guide for a list of valid platforms.
git If required, specify a specific Git repository in which this Gem is located. See the Bundler docs for details.
branch Optionally specify a branch to use if using the git option. Defaults to main.
ref Optionally specify an arbitrary valid Git reference to use for the module version.
source Specify an alternate Rubygems repository to load the gem from.
from_env Specifies an environment variable containing either a Rubygem version specification indicating the version to use OR a URL indicating the location from which to load the gem.
condition An optional string containing a Ruby-code conditional controlling if this gem will be processed in the Gemfile.

spec/default_facts.yml

The spec/default_facts.yml file contains a list of facts to be used by default when running rspec tests

Key Description
ip Overrides the [networking][ip] fact's value in the base template. Defaults to "172.16.254.254".
ip6 Overrides the [networking][ip6] fact's value in the base template. Defaults to "FE80:0000:0000:0000:AAAA:AAAA:AAAA".
mac Overrides the [networking][mac] fact's value in the base template. Defaults to "AA:AA:AA:AA:AA:AA".
is_pe Overrides the is_pe fact's value in the base template. Defaults to false.
extra_facts List of extra facts to be added to the default_facts.yml file. They are in the form: "name of fact: value of fact"
---
networking:
  ip: "172.16.254.254"
  ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA"
  mac: "AA:AA:AA:AA:AA:AA"
is_pe: false

spec/spec_helper.rb

The spec/spec_helper.rb file contains setup for rspec tests

Key Description
default_facter_version Sets the default_facter_version rspec-puppet-facts parameter.
facter_implementation Sets the facter_implementation rspec-puppet parameter. Current available options are rspec and facter, with facter being the default. The rspec implementation offers a significant performance improvement and results in faster unit tests.
hiera_config Sets the hiera_config rspec-puppet parameter.
hiera_config_ruby Sets the hiera_config rspec-puppet parameter. A ruby expression returning the path to your hiera.yaml file. hiera_config takes precedence if both values hiera_config and hiera_config_ruby are specified.
mock_with Defaults to ':rspec'. If you need the previous default of "some mocha and some rspec-mocks", set mock_with: ~ (tilde symbol, the YAML null value).
spec_overrides An array of extra lines to add into your spec_helper.rb. Can be used as an alternative to spec_helper_local
strict_level Defines the Puppet Strict configuration parameter. Defaults to :warning. Other values are: :error and :off. :error provides strictest level checking and is encouraged.
strict_variables Defines the Puppet Strict Variables configuration parameter. Defaults to true however due to puppetlabs_spec_helper forced override (https://github.com/puppetlabs/puppetlabs_spec_helper/blob/070ecb79a63cb8fa10f46532c413c055e2697682/lib/puppetlabs_spec_helper/module_spec_helper.rb#L71). Set to false to align with true default or with STRICT_VARIABLES=no environment setting.
coverage_report Enable rspec-puppet coverage reports. Defaults to false
minimum_code_coverage_percentage The desired code coverage percentage required for tests to pass. Defaults to 0

Further Notes

Please note that the early version of this template contained only a 'moduleroot' directory, and did not have a 'moduleroot_init'. The PDK 'pdk new module' command will still work with templates that only have 'moduleroot', however the 'pdk convert' command will fail if the template does not have a 'moduleroot_init' directory present. To remedy this please use the up to date version of the template.

Security Considerations on Github Actions

As explained in Use GitHub actions at your own risk, when running github actions from outside the organisation, there is a risk that symbolic references get taken over by malicious actors. Similar things happened before in other ecosystems and other packaging registries. The blog post goes on to suggest pinning to specific SHAs and provides some tooling to do so. The downsides for us are that the tooling doesn't work well with our ERB templating, and the additional cost of updating the SHAs across all modules. Instead we fork at-risk actions into the puppetlabs namespace and use them from there. This allows us to consume updates at our pace and deploy changes across all modules without delay, while avoiding actions that surreptitiously change while we're not looking.

Since this still has some overhead, we exclude some "big-name" action maintainers:

Updating actions guidelines

To keep efforts low when updating actions, we list all forked actions here. To keep confusion to a minimum, the version we use is always on a pdk-templates-v1 branch. This way we can update (git fetch/git push) forked repositories with no prejudice, test out the changes, and only then update the pdk-templates-v1 branch. That said, the branches used in pdk-templates should only contain upstream code and changes already in an upstream PR to minimize the diff we're carrying. If we later need to support multiple versions of an action as we roll out changes, we can increment the -v1 part in the branch name to manage multiple versions.

The repos have restricted access only to @modules team members.

pdk-templates's People

Contributors

adrianiurca avatar bastelfreak avatar bmjen avatar cdenneen avatar chelnak avatar da-ar avatar david22swan avatar davids avatar dhollinger avatar gavindidrichsen avatar ghoneycutt avatar glennsarti avatar gspatton avatar jeffbyrnes avatar jordanbreen28 avatar lukasaud avatar michaeltlombardi avatar npwalker avatar pmcmaw avatar ramesh7 avatar rodjek avatar rtib avatar sanfrancrisko avatar scotje avatar seanmil avatar sheenaajay avatar silug avatar skoef avatar tphoney avatar turbodog avatar

Stargazers

 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

Watchers

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

pdk-templates's Issues

How do you specify a git branch with the template URL ?

I'm doing development on this repo and would like to test my branches before sending a pull requests. Tried changing the template-url key in the metadata.json of a test module and not having any luck.

snippet from metadata.json

  "template-url": "https://github.com/ghoneycutt/pdk-templates#gh205_hiera_defaults",

Is there a way to do this? If not, how else are people testing their changes to pdk-templates?

.yardopts sets output location to docs/, /doc/ in .gitignore

In .yardopts, the output directory is set to docs/, as seen in --output-dir docs/

However, in config_defaults.yml, /doc/ is included and /docs/ is omitted. When documentation is generated using puppet strings in a pdk-generated module, git attempts to version the compiled documentation unless .gitignore is modified to include this new directory.

NameError: uninitialized constant Bundler

After updating the template, I got this error when running pdk build:

pdk (ERROR): The spec_clean rake task failed with the following error(s):

Ignoring ffi-1.9.25 because its extensions are not built. Try: gem pristine ffi --version 1.9.25
Ignoring hitimes-1.2.6 because its extensions are not built. Try: gem pristine hitimes --version 1.2.6
Ignoring nokogiri-1.8.2 because its extensions are not built. Try: gem pristine nokogiri --version 1.8.2
Ignoring rainbow-2.2.2 because its extensions are not built. Try: gem pristine rainbow --version 2.2.2
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5
WARN: Unresolved specs during Gem::Specification.reset:
      puppet-lint (~> 2.0)
      public_suffix (< 4.0, >= 2.0.2)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Ignoring ffi-1.9.25 because its extensions are not built. Try: gem pristine ffi --version 1.9.25
Ignoring hitimes-1.2.6 because its extensions are not built. Try: gem pristine hitimes --version 1.2.6
Ignoring nokogiri-1.8.2 because its extensions are not built. Try: gem pristine nokogiri --version 1.8.2
Ignoring rainbow-2.2.2 because its extensions are not built. Try: gem pristine rainbow --version 2.2.2
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5
rake aborted!
NameError: uninitialized constant Bundler
/home/developer/Documents/Stash/Puppet/profile_linux/Rakefile:3:in `<top (required)>'
/opt/puppetlabs/pdk/share/cache/ruby/2.4.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)

pdk (FATAL): Failed to clean up after running unit tests

After some seaching, setting require 'bundler' at the top of Rakefile solved the problem. But now comes the question, is this a issue (many more with this problem)? or just a error from my machine environment?

Can't customize .travis.yml notifications

While looking at converting a module via pdk convert I noticed that there was no way to define my on notification rules via .sync.yml. The PDK forces email to false with no way to override that and also does not provide any way to add other notification methods. In my case, I need to add in a section for Slack.

appveyor: enable adding commands before the actual test command

To run commands before the default bundle exec rake..., add a before_test key to the template that fills in the corresponding section in the appveyor.yml file.

e.g.
.sync.yml

appveyor.yml:
  before_test:
  - pwsh -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable
  - powershell -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable

generates the following appveyor.yml snippet

before_test:
  - pwsh -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable
  - powershell -NoProfile -NoLogo -NonInteractive -Command $PSVersionTable

Running code coverage in .travis.yml

We are using code coverage in our unit tests, is there any plans or a preference for enabling this.
Basically we override script

script:
  - 'COVERAGE=yes bundle exec rake $CHECK'

Would you prefer this to be a binary off / on.
Or
to have the whole script line being configurable ?
Or
should this be a separate spec line, similar to rubocop ?

Remove legacy version checks from Gemfiles

The new modules generated by pdk 1.3 creates a Gemfile which includes version tests for old 3.x versions of Puppet.

That not only adds a number of lines to the file, it's also slightly confusing reading it when the PDK documentation says it only supports Puppet 4 onwards.

I see there was a PR in the old repo to try and remove some of these lines.

Is this change going to be applied here to the current template?

Cannot sync `puppet-lint --code_on_top_scope` option in PDK 1.9

code_on_top_scopecheck is disabled by default in puppet-lint
.puppet-lint.rc.erb only disables checks, so it does not appear possible to keep .puppet-lint.rc in sync with PDK 1.9 using .sync.yaml and pdk update if you want to add the --code_on_top_scope-check option

Add a source marker to all created files

From a slack conversation with @GeoffWilliams:

Add a PDK marker to all templates.

For _init files and object templates, it should read # initially generated with PDK <%= @configs['pdk_version'] %> from <%= @configs['template_source_path'] %>, for files that get updated on pdk update, it should read # maintained by PDK, from <%= @configs['template_source_path'] %>. This makes it clear which files can be touched directly, and which will be updated, while at the same time avoiding churn (for "maintained" files, the metadata.json entry shows when it was last updated).

This will need additional changes in the PDK to provide the pdk_version, and template_source_path values.

provider template missing decorator (gettext/decoratestring)

As per PR #232 The provider template is causing my build to fail due to missing string decorator:

convention: rubocop: lib/puppet/type/testprovider.rb:5:9: GetText/DecorateString: decorator is missing around sentence
convention: rubocop: lib/puppet/type/testprovider.rb:12:16: GetText/DecorateString: decorator is missing around sentence
convention: rubocop: lib/puppet/type/testprovider.rb:17:18: GetText/DecorateString: decorator is missing around sentence

Changelog generator uses the wrong project name

The changelog_project function in the Rakefile looks for the project name, and assumes that is the name of the repo when crafting the URL. If they do not match, the changelog task generates an error. For example, in rnelson0/domain_join, the name is rnelson0-domain_join but the repo name is puppet-domain_join:

$ pdk bundle exec rake changelog
pdk (INFO): Using Ruby 2.5.1
pdk (INFO): Using Puppet 6.0.2
GitHubChangelogGenerator user:rnelson0
GitHubChangelogGenerator project:rnelson0-domain_join
GitHubChangelogGenerator future_release:v1.0.0
Fetching tags...
rake aborted!
Octokit::NotFound: GET https://api.github.com/repos/rnelson0/rnelson0-domain_join/tags?per_page=100: 404 - Not Found // See: https://developer.github.com/v3/repos/#list-tags

This is often a safe assumption (VP uses the namespace puppet and prefaces all module repo names with puppet-; likewise the company Puppet uses the namespace puppetlabs and preface puppetlabs-), but ultimately, the project name is already included in the source attribute of metadata.json. That should be used as well.

Make CI configuration easy to understand (and memorize)

(I'm not sure whether I interpret the content of this repo correctly and reporting here is fine. I apologize if this is plain wrong.)

Migrating a project over to PDK we've noticed that the CI configuration generated by PDK (aka "proposed by Puppet Labs") is somewhat verbose. And not based on commands provided by PDK. Examples:

I believe one of the strong points of PDK is that it finally provides developers with easy-to-memorize one-shot commands that "do it all", e.g.

  • perform linting: pdk validate
  • run (unit) tests: pdk test unit

Hence, it should be obvious that this simplicity can reflect positively on all any CI configuration related to Puppet. It could look like this:

- install:
  - apt-get install pdk

- script:
  - pdk validate
  - pdk test unit

... or, in a more elaborate setup, using stages (e.g. in Travis):

- stage: validate
  script: pdk validate

- stage: test
  script: pdk test unit

This is a setup you don't need to look up in documentation to get it explained. It's something you can explain to a colleague even as a complete newbie to CI, Travis & friends.

Can someone explain why the current templates still look, I apologize, confusing and use plain bundle, gem, rake commands?

GetText/DecorateString warning

Running RuboCop...
Warning: unrecognized cop GetText/DecorateString found in /Users/thomas.franklin/puppet/puppetlabs-panos/.rubocop.yml
Inspecting 85 files

Appveyor template builds branches + PR's producing a double build

Currently, i have my puppet module setup to build on both appveyor & travis-ci. When i create a PR .2 builds for appveyor kick off. 1 for the branch and 1 for the merged PR. Travis doesn't do this because it has already been configured to handle this and only perform one build. Below is the PR that shows this double build happenings

TraGicCode/tragiccode-azure_key_vault#25

image

NOTE: This double build only happens when you own the public github repo and cannot create a fork

Windows FILE resource fails unit testing on Linux

Creating a basic FILE resource such as below results in 2 errors when spec testing. the catalogue will successfully apply in windows hosts however:

  1. Parameter path failed on File[test_file]: File paths must be fully qualified
  2. got a relative path in SELinux find_fs:

I have tried stubs however cannot seem to overcome this error. Other windows resources and forge modules (registry, hosts, secpol etc) work fine and do not require stubbing. I have also tried forward slashes, single back slashes, double back slashes, singe and double quotes all to no avail.

class testing {

  file { 'make_z':
    ensure => directory,
    path   => 'c:\\z'
  }
  file { 'test_file':
    ensure  => 'file',
    path    => "c:\\z\\test.txt",
    content => 'I like milk',
    require => File['make_z'],
  }
}

Problems generating a correct spec_helper.rb with customisations from .sync.yml

I wanted to try the simplest possible approach for adding coverage reports to my unit tests. I thought that a rather inelegant but effective approach could be adding some lines to my .sync.yml file and let PDK do the rest:

---
.gitlab-ci.yml:
  ovverride: true
  custom:
    ruby_versions:
      '2.4.4':
        puppet_version: "~> 5.5.1"

appveyor.yml:
  delete: true

spec/spec_helper.rb:
  hiera_config: spec/fixtures/hiera/hiera.yaml
  spec_overrides:
    - RSpec.configure do |c|
    -   c.after(:suite) do
    -     RSpec::Puppet::Coverage.report!
    -   end
    - end
    -

After running:

$ pdk convert --template-url <my-pdk-templates-repository-url>

The resulting spec/spec_helper.rb file contains the content I wanted, but it is missing the "end" statement. You can notice that I inserted and extra empty line: I wanted to see if pdk was just skipping the last entry in the spec_overrides, but it turns out that the last "end" is missing anyway:

...

# 'spec_overrides' from sync.yml will appear below this line
RSpec.configure do |c|
c.after(:suite) do
RSpec::Puppet::Coverage.report!
end

rubocop directory is not documented

The other directories off of the root of the repo are documented at the top of the README, though rubocop is missing. Please document how this is meant to be used.

rubocop complains about default cops

Warning: unrecognized cop GetText/DecorateString found in /Users/gh/git/puppet-module-rpcbind/.rubocop.yml

Using PDK 1.9.1. You can reproduce with

pdk bundle exec rake rubocop

which is what happens by default with the TravisCI configs

If you ran pdk validate you would not see the warning. Even running with --debug this information is not displayed. This is a bug from a UX standpoint as you will see warnings in TravisCI and then not be able to reproduce using the standard tooling ala pdk validate instead of resorting to pdk bundle exec.

Update Grammar in README.md

In the paragraph 'The PDK also absorbs the config_defaults.yml...' on line 9 of the PDK README.md file, the last sentence states 'The data for a target file also use delete: true and unmanaged: true to remove, or ignore the particular file.' This sentence is not grammatically correct and doesn't necessarily make sense. Please define 'data for a target file' and change 'use' to 'uses' as this sentence is not very easily understood or clear.

remove ruby2.1.9 from .gitlab-ci

Ruby 2.1.9 is EOL and many gems require ruby 2.2+ now. As a result of this the gitlab ci that ships with the templates does not work because of gem installation failure due to 2.1.9 ruby version. Consider changing to 2.4.4 or 2.5.1.

puppet, facter and hiera gems should be configurable

In

puppet_version = ENV['PUPPET_GEM_VERSION']
facter_version = ENV['FACTER_GEM_VERSION']
hiera_version = ENV['HIERA_GEM_VERSION']
gems = {}
gems['puppet'] = location_for(puppet_version)
# If facter or hiera versions have been specified via the environment
# variables
gems['facter'] = location_for(facter_version) if facter_version
gems['hiera'] = location_for(hiera_version) if hiera_version
we hardcode a bunch of gems that should be configurable through config_defaults.yaml instead to allow folks to override with local defaults if necessary.

Default facts uses concat_basedir

Default facts uses concat_basedir which is a deprecated fact as part of the concat module. Also it uses a linux only path.

Why is this included in the default facts for all modules created by the PDK?

Overriding Appveyor matrix cells instead adds more

I needed to override the default appveyor matrix cells as my module does not support parallel_spec testing, only regular spec

My .sync.yml has the following snippet:

appveyor.yml:
  appveyor_bundle_install: "bundle install --jobs 4 --retry 2 --without system_tests build"
  matrix:
    - RUBY_VERSION: 24-x64
      CHECK: "syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop"
    - PUPPET_GEM_VERSION: ~> 4.0
      RUBY_VERSION: 21
      CHECK: spec
    - PUPPET_GEM_VERSION: ~> 4.0
      RUBY_VERSION: 21-x64
      CHECK: spec
    - PUPPET_GEM_VERSION: ~> 5.0
      RUBY_VERSION: 24
      CHECK: spec
    - PUPPET_GEM_VERSION: ~> 5.0
      RUBY_VERSION: 24-x64
      CHECK: spec

and pdk convert generates the following;

environment:
  matrix:
    -
      RUBY_VERSION: 24-x64
      CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
    -
      PUPPET_GEM_VERSION: ~> 4.0
      RUBY_VERSION: 21
      CHECK: parallel_spec
    -
      PUPPET_GEM_VERSION: ~> 4.0
      RUBY_VERSION: 21-x64
      CHECK: parallel_spec
    -
      PUPPET_GEM_VERSION: ~> 5.0
      RUBY_VERSION: 24
      CHECK: parallel_spec
    -
      PUPPET_GEM_VERSION: ~> 5.0
      RUBY_VERSION: 24-x64
      CHECK: parallel_spec
    -
      PUPPET_GEM_VERSION: ~> 4.0
      RUBY_VERSION: 21
      CHECK: spec
    -
      PUPPET_GEM_VERSION: ~> 4.0
      RUBY_VERSION: 21-x64
      CHECK: spec
    -
      PUPPET_GEM_VERSION: ~> 5.0
      RUBY_VERSION: 24
      CHECK: spec
    -
      PUPPET_GEM_VERSION: ~> 5.0
      RUBY_VERSION: 24-x64
      CHECK: spec

PDK Template didn't properly see that the override.

Ref: https://github.com/puppetlabs/puppetlabs-dsc

  "pdk-version": "1.6.0",
  "template-url": "file://C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/pdk-templates.git",
  "template-ref": "1.6.0-0-gf5564c0"

.sync.yml not working for .gitlab-ci.yml

Looks like that the instruction provided in the README.md file for changing the content of .gitlab-ci.yml are not correct, or there is a bug. Currently I'm using this content for my .sync.yml:

---
.gitlab-ci.yml:
  override: true
  custom:
    ruby_versions:
      '2.4.4':
        'puppet_version': '~> 5.5'

appveyor.yml:
  delete: true

The resulting .gitlab-ci.yml:

---
stages:
  - test_2.4.1
  - test_2.1.9

before_script:
  - bundle -v
  - rm Gemfile.lock || true
  - gem update --system
  - gem update bundler
  - gem --version
  - bundle -v
  - bundle install --without system_tests

rubocop-2.4.1:
  stage: test_2.4.1
  image: ruby:2.4.1
  script:
    - bundle exec rake rubocop

syntax-2.4.1:
  stage: test_2.4.1
  image: ruby:2.4.1
  script:
    - bundle exec rake syntax lint

metadata-2.4.1:
  stage: test_2.4.1
  image: ruby:2.4.1
  script:
    - bundle exec rake metadata_lint

rspec-puppet-2.4.1:
  stage: test_2.4.1
  image: ruby:2.4.1
  variables:
    PUPPET_GEM_VERSION: ~> 4.0
    CHECK: spec
  script:
    - bundle update
    - bundle exec rake $CHECK

rubocop-2.1.9:
  stage: test_2.1.9
  image: ruby:2.1.9
  script:
    - bundle exec rake rubocop

syntax-2.1.9:
  stage: test_2.1.9
  image: ruby:2.1.9
  script:
    - bundle exec rake syntax lint

metadata-2.1.9:
  stage: test_2.1.9
  image: ruby:2.1.9
  script:
    - bundle exec rake metadata_lint

rspec-puppet-2.1.9:
  stage: test_2.1.9
  image: ruby:2.1.9
  variables:
    PUPPET_GEM_VERSION: ~> 4.0
    CHECK: spec
  script:
    - bundle update
    - bundle exec rake $CHECK

Moving "ruby_versions" outside "custom", changes something:

---
.gitlab-ci.yml:
  override: true
  ruby_versions:
    '2.4.4':
      puppet_version: "~> 5.5.1"

appveyor.yml:
  delete: true

Result:

---
stages:
  - test_["2.4.4", {"puppet_version"=>"~> 5.5.1"}]

before_script:
  - bundle -v
  - rm Gemfile.lock || true
  - gem update --system
  - gem update bundler
  - gem --version
  - bundle -v
  - bundle install --without system_tests

rubocop-["2.4.4", {"puppet_version"=>"~> 5.5.1"}]:
  stage: test_["2.4.4", {"puppet_version"=>"~> 5.5.1"}]
  image: ruby:["2.4.4", {"puppet_version"=>"~> 5.5.1"}]
  script:
    - bundle exec rake rubocop

syntax-["2.4.4", {"puppet_version"=>"~> 5.5.1"}]:
  stage: test_["2.4.4", {"puppet_version"=>"~> 5.5.1"}]
  image: ruby:["2.4.4", {"puppet_version"=>"~> 5.5.1"}]
  script:
    - bundle exec rake syntax lint

metadata-["2.4.4", {"puppet_version"=>"~> 5.5.1"}]:
  stage: test_["2.4.4", {"puppet_version"=>"~> 5.5.1"}]
  image: ruby:["2.4.4", {"puppet_version"=>"~> 5.5.1"}]
  script:
    - bundle exec rake metadata_lint

rspec-puppet-["2.4.4", {"puppet_version"=>"~> 5.5.1"}]:
  stage: test_["2.4.4", {"puppet_version"=>"~> 5.5.1"}]
  image: ruby:["2.4.4", {"puppet_version"=>"~> 5.5.1"}]
  variables:
    PUPPET_GEM_VERSION: ~> 4.0
    CHECK: spec
  script:
    - bundle update
    - bundle exec rake $CHECK

Something better is achievable removing the "puppet_version" parameter and using an array instead of a hash for "ruby_versions".

---
.gitlab-ci.yml:
  override: true
  ruby_versions:
    - '2.4.4'

appveyor.yml:
  delete: true

Still, I would expect to have only the test_2.4.4 stage, while PDK generates everything also for 2.1.9 and 2.4.1:

---
stages:
  - test_2.4.1
  - test_2.1.9
  - test_2.4.4

before_script:
  - bundle -v
  - rm Gemfile.lock || true
  - gem update --system
  - gem update bundler
  - gem --version
  - bundle -v
  - bundle install --without system_tests

rubocop-2.4.1:
  stage: test_2.4.1
  image: ruby:2.4.1
  script:
    - bundle exec rake rubocop

syntax-2.4.1:
  stage: test_2.4.1
  image: ruby:2.4.1
  script:
    - bundle exec rake syntax lint

metadata-2.4.1:
  stage: test_2.4.1
  image: ruby:2.4.1
  script:
    - bundle exec rake metadata_lint

rspec-puppet-2.4.1:
  stage: test_2.4.1
  image: ruby:2.4.1
  variables:
    PUPPET_GEM_VERSION: ~> 4.0
    CHECK: spec
  script:
    - bundle update
    - bundle exec rake $CHECK

rubocop-2.1.9:
  stage: test_2.1.9
  image: ruby:2.1.9
  script:
    - bundle exec rake rubocop

syntax-2.1.9:
  stage: test_2.1.9
  image: ruby:2.1.9
  script:
    - bundle exec rake syntax lint

metadata-2.1.9:
  stage: test_2.1.9
  image: ruby:2.1.9
  script:
    - bundle exec rake metadata_lint

rspec-puppet-2.1.9:
  stage: test_2.1.9
  image: ruby:2.1.9
  variables:
    PUPPET_GEM_VERSION: ~> 4.0
    CHECK: spec
  script:
    - bundle update
    - bundle exec rake $CHECK

rubocop-2.4.4:
  stage: test_2.4.4
  image: ruby:2.4.4
  script:
    - bundle exec rake rubocop

syntax-2.4.4:
  stage: test_2.4.4
  image: ruby:2.4.4
  script:
    - bundle exec rake syntax lint

metadata-2.4.4:
  stage: test_2.4.4
  image: ruby:2.4.4
  script:
    - bundle exec rake metadata_lint

rspec-puppet-2.4.4:
  stage: test_2.4.4
  image: ruby:2.4.4
  variables:
    PUPPET_GEM_VERSION: ~> 4.0
    CHECK: spec
  script:
    - bundle update
    - bundle exec rake $CHECK

.travis.yml automatically adds deploy section with incorrect user

The README does not explain how to specify a deploy user/password. This further compounds the issue that pdk-templates adds the deploy section by default as it is not clear how to override the user and specify a password.

Suggest that the deploy section is not automatically added by removing deploy: true from config_defaults.yml. The branches attribute should be left in there. Documentation is needed to show how to add your username/password along with a link to the TravisCI documentation on how to create and encode the password.

gitlab-ci beaker

@dhollinger @npwalker

Few things:

  • there is no rake task of acceptance anymore... needs to be beaker
  • the bundle install for acceptance job needs to be bundle install --with system_tests otherwise the bundle install does nothing but uses whats in cache and beaker never gets installed.
  • image should allow for registry in .sync or config_defaults and if set prepend with the registry_host/
  • beaker variables (and probably any other variables needs to convert boolean to string)
---
.gitlab-ci.yml:
  custom:
    beaker:
      variables:
        BEAKER_debug: 'true'

converts to BEAKER_debug: true and then fails ci lint as it needs to be BEAKER_debug: 'true'

  • beaker acceptance job missing default image and/or gitlab-ci.yml doesn't have a default set so falls back to runners configured default image which in the case of gitlab.com is ruby:2.5 but in my local hosted gitlab there is no default so it fails:
Running with gitlab-runner 10.8.0 (079aad9e)
  on gitlab-ci-runner-1 e1b7b7f8
ERROR: Preparation failed: no image specified and no default set in config
Will be retried in 3s ...
ERROR: Preparation failed: no image specified and no default set in config
Will be retried in 3s ...
ERROR: Preparation failed: no image specified and no default set in config
Will be retried in 3s ...
ERROR: Job failed (system failure): no image specified and no default set in config
  • outside the scope of this in general but gem install nokogiri even cached will recompile during acceptance job I believe because that needs to be installed with --prune flag or something if I recall reading that somewhere.
  • currently by having 2 spec and lint jobs running in same stage there is absolutely NO benefit to caching in gitlab-ci. In order for caching to make sense is the use of multiple stages. (technically right now the last syntax stage job is the one winning in the "cache.zip" upload... since they are overwriting each other.) I thought we originally discussed needing a "quick" job as the first stage like linting which could create the cache and speed up the spec/acceptance jobs downstream? Also if your going to fail linting, validate, maybe even rubocop it's probably not worth installing all fixtures and full spec testing suite since some of those can be massive and fail early in previous stage? Maybe even consider a "prep" job that just does the bundle install --with development and creates the cache (seems like waste for container so still recommend moving the linting to first stage)? It's possibly the lint was supposed to be first then at that point the ERB is just a typo and the spec ones should be unit stages
  • setting override removes syntax and unit from the stages but not the jobs. I believe if there are jobs calling a stage that is no longer defined this will break ci linting. So maybe if override the jobs get removed as well as the stages?

Missing functional testing

We should be able to functionality test that with given data inputs that the templates create expected outputs. This would also give the ability to run validations and linting against the templates.

travis-ci: unable to deploy to the puppet forge

Due to dpl-puppet_forge requiring the very last version of Ruby (wtf, seriously), it is not possible to push to the forge with the default generated travis-ci configuration:

ERROR:  Error installing dpl-puppet_forge:
	The last version of puppet (>= 0) to support your Ruby & RubyGems was 5.5.6. Try installing it with `gem install puppet -v 5.5.6` and then running the current command again
	puppet requires Ruby version >= 2.3.0. The current ruby version is 2.2.0.
/home/travis/.rvm/rubies/ruby-2.2.7/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- dpl/provider/puppet_forge (LoadError)
	from /home/travis/.rvm/rubies/ruby-2.2.7/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:59:in `require'
	from /home/travis/.rvm/gems/ruby-2.2.7/gems/dpl-1.10.0/lib/dpl/provider.rb:94:in `rescue in block in new'
	from /home/travis/.rvm/gems/ruby-2.2.7/gems/dpl-1.10.0/lib/dpl/provider.rb:69:in `block in new'
	from /home/travis/.rvm/gems/ruby-2.2.7/gems/dpl-1.10.0/lib/dpl/cli.rb:41:in `fold'
	from /home/travis/.rvm/gems/ruby-2.2.7/gems/dpl-1.10.0/lib/dpl/provider.rb:68:in `new'
	from /home/travis/.rvm/gems/ruby-2.2.7/gems/dpl-1.10.0/lib/dpl/cli.rb:31:in `run'
	from /home/travis/.rvm/gems/ruby-2.2.7/gems/dpl-1.10.0/lib/dpl/cli.rb:7:in `run'
	from /home/travis/.rvm/gems/ruby-2.2.7/gems/dpl-1.10.0/bin/dpl:5:in `<top (required)>'
	from /home/travis/.rvm/gems/ruby-2.2.7/bin/dpl:23:in `load'
	from /home/travis/.rvm/gems/ruby-2.2.7/bin/dpl:23:in `<main>'
failed to deploy

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.