- Overview
- Requirements
- Usage
- How it works
- Configuration
- Workflow
- Migrating from modulesync to pdksync
- Contributing
Pdksync is an efficient way to run a pdk update command against the various Puppet module repositories that you manage — keeping them up-to-date with the changes made to PDK. It is a solution for converted modules that no longer run with modulesync.
Pdksync by default expects that your Puppet module repositories live on GitHub and will behave accordingly. It also supports GitLab as an alternative Git hosting platform.
- Ruby >= 2.4.4
- Bundler ~> 1.15
Note: This tool creates a 'live' pull (merge) request against the master branch of the module it is running against — defined in
managed_modules.yml. Before running this tool, ensure this file reflects the modules you wish it to run against. Additionally make sure that the Pdksync configuration file$HOME/.pdksync.ymlsets the correct namespace, Git platform and Git base URI for your modules. See section Configuration for details.
-
To use pdksync, clone the GitHub repo or install it as a gem. Set up the environment by exporting a GitHub token:
export GITHUB_TOKEN=<access_token>
If you use GitLab instead of GitHub export your GitLab access token:
export GITLAB_TOKEN=<access_token>
-
Before the script will run, you need to install the gems:
bundle install --path .bundle/gems/- Once this is complete, call the built-in rake task to run the module:
bundle exec rake pdksyncPdksync is a gem that works to clone, update, and push module repositories. Create a new git repository to store your working config. You need the following files in there:
Rakefile:
require 'pdksync/rake_tasks'Gemfile:
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
gem 'pdksync', github: 'puppetlabs/pdksync', ref: 'pdksync-externalisation-fixes'
gem 'rake'managed_modules.yml:
---
- repo1
- repo2
- repo3
- repo4pdksync.yml:
---
namespace: 'YOUR GITHUB NAME'
git_base_uri: '[email protected]'Run the following commands to check that everything is working as expected:
bundle install --path .bundle/gems/
bundle exec rake git:clone_managed_modulespdksync tool is extended with the feature to update the Gemfile. Puppet provides a lot of useful gems to access and manage their functionality between modules. This functionality will help user to perform gem testing prior to release. User is given new rake tasks to update SHA/Version/Branch/line in the Gemfile. Then the changes can be committed, PR can be created which will run the acceptance tests in the PR. If all the tests are executing successfully then the user can close the PRS and release the gem. Below given are the workflows for doing module gem testing with pdksync.
In Workflow 1 we can clone modules, update the gem file, create the commit, push the changes and create the PR using separate rake tasks.
bundle install --path .bundle/gems/
bundle exec rake git:clone_managed_modules
bundle exec rake 'pdksync:gem_file_update[]'
bundle exec rake 'git:create_commit[]'
bundle exec rake 'git:push'
bundle exec rake 'git:create_pr[]'In Workflow 2 we can clone modules, update the gem file, create the commit, push the changes and create the PR using single rake task
Using single rake job
bundle install --path .bundle/gems/
bundle exec rake 'gem_testing[]'
In Workflow 3 we can clone modules, update the gem file, run the tests locally for litmus modules without creating commit,pushing or creating the PR
Using single rake job
bundle install --path .bundle/gems/
bundle exec rake git:clone_managed_modules
bundle exec rake 'pdksync:gem_file_update[]'
bundle exec rake 'pdksync:run_tests_locally[]'
bundle exec rake 'pdksync:fetch_test_results_locally[]'
Once the verified gem is released we can use pdksync to update the the new version of gem released in the .sync.yaml file.
pdksync tool is extended with the feature to perform multi gem testing (puppet-module-gems). This functionality will identify the current version and bump the version by one. Then it will build and push the gems to gemfury account. Export the GEMFURY_TOKEN to use this rake task.
export GEMFURY_TOKEN=<access_token>Run the following commands to check that everything is working as expected:
bundle install --path .bundle/gems/
bundle exec rake -T
bundle exec rake 'git:clone_gem['gem_name']'Below given are the workflows for doing multi gem testing with pdksync.
In this workflow we can clone gems, update the version, build the gem, push the changes to gemfury and update the gem file of the required modules with the latest gem updated in the fury. Then we can create PR or run tests locally or run tests through jenkins to verify the module test results.
bundle install --path .bundle/gems/
bundle exec rake 'git:clone_gem[]'
bundle exec rake 'pdksync:multi_gem_testing[]'
bundle exec rake 'pdksync:multigem_file_update[]'The rake tasks take in a file, managed_modules.yml, stored within the local directory that lists all the repositories that need to be updated. It then clones them, one after another, so that a local copy exists. The pdk update command is ran against this local copy, with the subsequent changes being added into a commit on a unique branch. It is then pushed back to the remote master — where the local copy was originally cloned. A pull request against master is opened, and pdksync begins to clone the next repository.
By default, pdksync will supply a label to a PR (default is 'maintenance'). This can be changed by creating pdksync.yml in the local directory and setting the pdksync_label key. You must ensure that the label selected exists on the modules that you are applying pdksync to. Should you wish to disable this feature, set pdksync_label to an empty string i.e. ''. Similarly, when supplying a label using the git:create_pr rake task, the label must exist on each of the managed modules to run successfully.
The following rake tasks are available with pdksync:
pdksync:show_configDisplay the current configuration of pdksyncgit:clone_managed_modulesClone managed modules.git:create_commit[:branch_name, :commit_message]Stage commits for modules, branchname and commit message eg rake 'git:create_commit[flippity, commit messagez]'.git:pushPush staged commits eg rake 'git:push'.git:create_pr[:pr_title, :label]Create PR for modules. Label is optional eg rake 'git:create_pr[pr title goes here, optional label right here]'.git:clean[:branch_name]Clean up origin branches, (branches must include pdksync in their name) eg rake 'git:clean[pdksync_origin_branch]'.pdksync:pdk_convertRuns PDK convert against modules.pdksync:pdk_validateRuns PDK validate against modules.pdksync[:additional_title]Run full pdksync process, clone repository, pdk update, create pr. Additional information can be added to the title, which will be appended before the reference section.rake pdksyncPR title outputs aspdksync - pdksync_heads/master-0-gabccfb1rake 'pdksync[MODULES-8231]'PR title outputs aspdksync - MODULES-8231 - pdksync_heads/master-0-gabccfb1
pdksync:run_a_command[:command, :option]Run a command against modules eg rake 'pdksync:run_a_command[complex command here -f -gx, 'background']'. :option is an optional parameter which states to run command in backgroud.pdksync:gem_file_update[[:gem_to_test, :gem_line, :gem_sha_finder, :gem_sha_replacer, :gem_version_finder, :gem_version_replacer, :gem_branch_finder, :gem_branch_replacer]]Run gem_file_update against modules- eg rake to update gem line
pdksync:gem_file_update['puppet_litmus', "gem 'puppet_litmus'\, git: 'https://github.com/test/puppet_litmus.git'\, branch: 'testbranch'"]' - eg rake to update sha
pdksync:gem_file_update['puppet_litmus', '', '20ee04ba1234e9e83eb2ffb5056e23d641c7a018', '20ee04ba1234e9e83eb2ffb5056e23d641c7a31'] - eg rake to update version
pdksync:gem_file_update['puppet_litmus', '', '', '', "= 0.9.0", "<= 0.10.0", '', ''] - eg rake to update branch
pdksync:gem_file_update['puppet_litmus', '', '', '', '', '', 'testbranch', 'testbranches']
- eg rake to update gem line
rake 'gem_testing[:additional_title, :gem_to_test, :gem_line, :gem_sha_finder, :gem_sha_replacer, :gem_version_finder, :gem_version_replacer, :gem_branch_finder, :gem_branch_replacer]'Run complete Gem file testing (cloning, gemfileupdate, create commit, create PR)PR title outputs aspdksync_gemtesting - MODULES-8231 - pdksync_heads/master-0-gabccfb1- eg rake to perform gem file testing
gem_testing['MODULES-testing', 'puppet_litmus', '', '20ee04ba1234e9e83eb2ffb5056e23d641c7a018', 'testsha']
- eg rake to perform gem file testing
pdksync:run_tests_locally[:provision_type, :puppet_collection]Run litmus modules locally- eg rake 'pdksync:run_tests_locally["default"]'
pdksync:fetch_test_results_locally[]Fetch litmus modules local run results- eg rake 'pdksync:fetch_test_results_locally[]'
pdksync:run_tests_jenkins[:jenkins_server_url, :github_branch, :test_framework, :github_user]Run traditional modules on jenkins. For now this rake task works just for test_framework: jenkins.- eg rake 'pdksync:run_tests_jenkins[test_branch, '', test_user]'
pdksync:test_results_jenkins[]Fetch traditional modules jenkins run results- eg rake 'pdksync:test_results_jenkins[jenkins_server_url]'
git:clone_gem[:gem_name]Clone gem.pdksync:multi_gem_testing[:gem_name, :version_file, :build_gem, :gem_path, :gemfury_username]Build and Push new gems built to the gemfury account for testing eg rake 'pdksync:multi_gem_testing[]'pdksync:multigem_file_update[:gem_name, :gemfury_username]Update Gemfile of the modules with the new gem should be pushed to Gemfury.'
By default pdksync will use hardcoded values for configuring itself. However, if you wish to override these values, create a pdksync.yml in your working directory and use the following format:
---
namespace: 'puppetlabs'
pdksync_dir: 'modules_pdksync'
pdksync_gem_dir: 'gems_pdksync',
push_file_destination: 'origin'
create_pr_against: 'master'
managed_modules: 'managed_modules.yml'
pdksync_label: 'maintenance'
git_platform: :github
git_base_uri: 'https://github.com'
# Only used when git_platform is set to :gitlab
gitlab_api_endpoint: 'https://gitlab.com/api/v4'You may override any property. Those that are not specified in your config file will use their corresponding default value from lib/pdksync/constants.rb.
By default pdksync assumes you are hosting your Puppet modules on GitHub, and GitHub is the only platform officially supported by Puppetlabs in pdksync.
Pdksync also supports the GitLab platform, but without official support by Puppetlabs.
Github.com and Github enterprise both work with octokit which is used in pdksync. There are some settings you will need to adjust if using the on premise github enterprise edition.
api_endpoint: https://mygithub.mycompany.com/api/v3git_base_uri: [email protected]export GITHUB_TOKEN=k3939isdiasdf93i_(your token goes here)
To use GitHub.com you only need to export your GitHub access token as the
environment variable GITHUB_TOKEN and configure the namespace in which your
modules are hosted in $HOME/.pdksync.yml as described above.
To use GitLab at https://gitlab.com you need to set git_platform: :gitlab
and configure the namespace of your modules in $HOME/.pdksync.yml. You also
need to export your GitLab access token as the environment variable
GITLAB_TOKEN.
Your $HOME/.pdksync.yml then looks like this:
# ~/pdksync.yml
---
namespace: 'acme'
git_platform: :gitlabExport your GitLab access token:
export GITLAB_TOKEN=<your GitLab access token here>If you are running your own GitLab instance on premise or use a GitLab instance
other than the official one at https://gitlab.com you also need to configure
git_base_uri and api_endpoint in $HOME/.pdksync.yml so that
pdksync knows from where to clone your modules and where to access to GitLab
API to create the live merge requests:
# ~/pdksync.yml
---
namespace: 'puppetmodules'
git_platform: :gitlab
git_base_uri: 'https://gitlab.example.com'
# alternatively use SSH:
#git_base_uri: 'ssh://[email protected]:2222'
api_endpoint: 'https://gitlab.example.com/api/v4'It may be desirable to allow modules to dictate which version of the pdk-templates they should sync with.
There are a few settings you can tune to allow for this kind of flexability. These settings are in the pdksync.yml file. All of these settings are optional and have sane defaults. See rake pdksync:show_config for the settings that will be used.
- pdk_templates_prefix: 'nwops-' (example only, keep as empty string)
- pdk_templates_ref: 1.12.0
- pdk_templates_url: https://github.com/puppetlabs/pdk-templates.git
- module_is_authoritive: true
The first setting is module_is_authoritive. When this is set to true the templates and ref specified in the metadata become the authoritive source for these settings. Even if you have pdk_templates_ref and pdk_templates_url specified in pdksync.yml the metadata settings will alwasys be used.
# module/metadata.json
{
"pdk-version": "1.11.1",
"template-url": "https://github.com/puppetlabs/pdk-templates#master",
"template-ref": "heads/master-0-gb096033"
}
When module_is_authoritive is set to false the pdk_templates_ref and pdk_templates_url will override what is found in the modules's metadata.json file. This is very useful when you have to control pdk-template upgrades on modules.
The other settings dictiate where the templates are located and which branch, tag or reference you want to use.
pdk_templates_ref: 'master' and pdk_templates_url: https://github.com/puppetlabs/pdk-templates.git. These settings will only be utilized if module_is_authoritive is set to false. However, if you are performing a conversion via pdksync these settings will also be used since the metadata in the module being converted doesn't have pdk settings yet.
The last setting pdk_templates_prefix is a special use case that allows folks with internal forks of pdk-templates to keep branches of the pdk-template tags with additional custom changes. Setting this to an empty string disables this. You will most likely need to resolve conflicts with this workflow, so it is not for everyone. If you know of a better way please submmit a pull request.
This strategy works in conjunction with the pdk-template git tags and the workflow looks like:
- git fetch upstream (github.com/puppetlabs/pdk-templates)
- git checkout master && git rebase upstream/master
- git checkout -b nwops-1.0.13 nwops-1.0.12
- git rebase 1.0.13
- git push origin nwops-1.0.13
If you have multiple namespaces that you need to support you will need to create a pdksync.yml config file for each namespace. This will allow you to create a folder structure and keep a separate managed_modules.yml for that namespace too.
You can set a PDKSYNC_CONFIG_PATH environment variable that points to the specific pdksync.yml config file for use in a CI or on the CLI. This allows you to set custom names for pdksync.yml file.
example: PDKSYNC_CONFIG_PATH=pdksync_ops.yml
Or you can set a different HOME environment variable that tells pdksync where to find the pdksync.yml file. Pdksync will locate the pdksync.yml file in the HOME folder you specify. The config file name is not changable in this case.
example: HOME=ops
Pdksync uses a logger class to log all output. You can control how the logger works via a few environment variables.
To control the level set the LOG_LEVEL to one of
- info
- debug
- fatal
- error
- warn
To control where the logs are sent (defaults to stdout) set the PDKSYNC_LOG_FILENAME to a file path.
It currently runs without additional arguments. To alter how it runs, make alterations to either HOME/.pdksync.yml or managed_modules.yml.
This module runs through a pre-set array of modules, with this array set within the managed_modules.yml file. This file makes use of a simple yaml style format to set out the different module names, for example:
---
- puppetlabs-motd
- puppetlabs-stdlib
- puppetlabs-mysqlTo add a module, add it to the list. To remove a module, remove it from the list. If you wish to specify a custom managed modules file, use the managed_modules property in your configuration file to specify the path to the file.
If your modules are currently managed by modulesync, and you want to use PDK and keep your modules up-to-date, read the following.
pdk convert- A command to convert your module, for example, to make it compatible with the PDK.convert_report.txt- A report that shows the changes PDK will make to your module whenpdk convertis ran.pdk update- A command to consume any changes that have been made to the pdk-template used to convert the module.update_report.txt- A report that shows the changes PDK will make to your module whenpdk updateis ran.pdk validate- A command to run basic validation checks on your module.pdk test unit- A command to run all available unit tests on your module..sync.yml- A file that lists all of of your module customizations — and will require work before module conversion.
- Unit tests are in a good state — with no failures. Check by running
pdk test unit. - The module is in good shape. Check by running
pdk validate.
When you're confident everything is in good shape, you can start converting your module to make it compatible with PDK.
- Run
pdk convert --noop. This will output to the console a high level overview of the changes that PDK is planning to make to your files.
Note: For an in-depth diff, see the convert_report.txt that is output in the module root directory.
- Make changes to your .sync.yml. State any configuration that the custom pdk-templates plan to remove.
Useful commands via the .sync.yml:
- Add additional gem dependencies:
Gemfile:
required:
':system_tests':
- gem 'octokit'
platforms: ruby- Make changes to your travis configuration:
.travis.yml:
branches:
- release- Delete files that you don't want to exist in the repo:
.gitlab-ci.yml:
delete: true- Unmanage files that you don't want to be managed:
.gitlab-ci.yml:
unmanaged: trueNote: It is unlikely your module will work out of the box.
-
When you are finished customizing your .sync.yml file, run
pdk convert --noopand confirm the changes that PDK will make when you convert. Changes can be found in theconvert_report.txt -
Run
pdk convertto convert. You will be prompted to pass in Y/N — type Y and all your changes will be applied.
Note: If you have any concerns it is not too late — type N.
-
Run your unit tests to confirm that nothing has broken. If there are breakages, you might need to require a library or include a missing gem — address this issue before you continue.
-
Run
pdk validateto ensure there are no failures. -
Commit the changes that the
pdk converthas made and create your pull request. -
Remove your module from being managed via
modulesync, and start usingpdksyncgoing forward — no more manually creating pull requests.
For more information on keeping your module up to date with the PDK check out Helens blog post.
This tool has been developed and tested on OSX and Linux. It currently does not run on Windows.
- Fork the repo
- Create your feature branch:
git checkout -b my-new-feature- Commit your changes:
git commit -am 'Add some feature'- Push to the branch:
git push origin my-new-feature- Create a new pull request