How Code Manager works
Code Manager uses r10k and the file sync service to stage, commit, and sync your code, automatically managing your environments and modules.
First, you must create a control repository with branches for each environment that you want to create (such as production, development, or testing), and you must create a Puppetfile for each of your environments, specifying exactly which modules to install in each environment. This allows Code Manager to create directory environments, based on the branches you've set up. Your control repository lives on a Git server, and this is where you push code that you want Code Manager to deploy.
A webhook from your Git server automatically starts the code deployment when you push code to the control repo.
- Continuous Delivery for Puppet Enterprise sends a deploy request to Code Manager.
- You use
puppet-codeto manually trigger Code Manager from the command line.
Once triggered, Code Manager uses r10k to fetch code from the Git server and places it into
the staging directory (at
/etc/puppetlabs/code-staging) on the primary
server. Next, the file sync storage service on the primary server detects the change,
and the file sync clients pause the Puppet Server to avoid
conflicts during synchronization. Finally, the file sync clients synchronize the new
code to the live code directories on the primary server and compilers (usually at
/etc/puppetlabs/code). The following diagram
illustrates the code deployment process.
For more information about using environments in Puppet, see About Environments.
Understanding file sync and the staging directory
To sync your code across your primary server and compilers, and to make sure that code stays consistent, Code Manager relies on file sync and two different code directories: the staging directory and the live code directory.
Without Code Manager or file sync, Puppet code lives in the codedir, or live code directory, at
With Code Manager and file sync, the file sync client service
regularly checks for changes to staged code files in the staged code directory on the
primary server at
/etc/puppetlabs/code-staging. If it detects a change,
the file sync client service fetches the changes and syncs the files to the live codedir on
each compiler and the primary server (at
For more detailed information about how file sync works, refer to the related topic about file sync.
Environment isolation metadata and Code Manager
Both your live and staging code directories contain metadata files that are generated by file sync to provide environment isolation for your resource types.
These files, which have a
.pp extension, ensure that each environment uses the correct version of
the resource type. Do not delete or modify these files. Do not use expressions from
these files in regular manifests.
These files are generated as Code Manager deploys new code in your environments. If you are new to Code Manager, these files are generated when you first deploy your environments. If you already use Code Manager, the files are generated as you make and deploy changes to your existing environments.
For more details about these files and how they isolate resource types in multiple environments, see environment isolation.
Moving from r10k to Code Manager
Moving from r10k to Code Manager can improve the automation of your code management and deployments.
Some users might not want to upgrade from r10k to Code Manager because of the following differences:
- If you use Code Manager, you cannot deploy code
manually with r10k. If you depend on the ability to
deploy modules directly from r10k, using the
r10k deploy modulecommand, continue using r10k.
- Code Manager must deploy all control repositories to the same directory. If you are using r10k to deploy control repositories to different directories, continue using r10k.
- Code Manager supports the shellgit provider, but only for HTTPS. It does not support system .SSH configuration or other shellgit options.
- Code Manager does not support post-deploy scripts.
If you rely on any of the above configurations currently unsupported by Code Manager or if you are using a custom script to deploy code, carefully assess whether or not Code Manager meets your needs.