The following is a best practice guide to how to write a production quality plan. These best practices are reflected in the requirements for a user to contribute a plan to the Chef Habitat Core Plans.
If you haven’t already, a good first step is to read the Writing Plans documentation.
Each package plan should contain a value adhering to the guidelines for each of the following elements:
pkg_descriptionpkg_license (in SPDX format)pkg_maintainer in the format of “The Chef Habitat Maintainers [email protected]”pkg_name see the section of this document on “Package Name Conventions”pkg_origin must be set to core
pkg_sourcepkg_upstream_urlpkg_version must be the complete version number of the softwareEach package is identified by a unique string containing four sub-strings separated by a forward slash (/) called a PackageIdent.
`origin`/`name`/`version`/`release`
The origin, name, and version values of this identifier are user defined by setting their corresponding variable in your plan.sh or plan.ps1 file while the value of release is generated at build-time.
The value of name should exactly match the name of the project it represents and the plan file should be located within a directory of the same name in this repository.
Example: The plan for the bison project project contains setting
pkg_name=bisonand resides in$root/bison/plan.sh.
There is one exception to this rule: Additional plans may be defined for projects for their past major versions by appending the major version number to its name. The plan file for this new package should be located within a directory of the same name.
Example: the bison project maintains the 2.x line along with their current major version (at time of writing: 3.x). A second plan is created as
bison2and placed within a directory of the same name in this repository.
Packages meeting this exception will always have their latest major version found in the package sharing the exact name of their project. A new package will be created for the previous major version following these conventions.
Example: the bison project releases the 4.x line and is continuing to support Bison 3.x. The
bisonpackage is copied tobison3and thebisonpackage is updated to build Bison 4.x.
You can read more about basic plan settings here. The minimum requirements for a core plan are:
You can read more about callbacks here. The minimum requirement for a core plan are:
do_prepare() (Invoke-Prepare in a plan.ps1) is a good place to set environment variables and set the table to build the software. Think of it as a good place to do patches.do_verify() to return 0 in a plan.sh or if you are authoring a plan.ps1 then override Invoke-Verify with an empty implementation.exit within a build phase. In a plan.sh, you should instead return an exit code such as return 1 for failure, and return 0 for success. In a plan.ps1 you should call Write-Exception or throw an exception upon failure.pkg_source unless you are downloading something as a third party.hab from inside of a callback. If you think you want to, you should use a utility function instead._dont_call_this_function(). Those are internal for internal builder functions and are not supported for external use. They will break your plan if you call them.The Supervisor dynamically invokes hooks at run-time, triggered by an application lifecycle event. You can read more about hooks here.
stderr to stdout (e.g. with exec 2>&1 at the start of the hook)exec <command> <options> rather than running the command directly in a Linux targeted hook. This ensures the command is executed in the same process and that the service will restart correctly on configuration changes./var/, /static/, and /data/ directories. Access these with your runtime configuration setting variable.hab or sleep in a hook that is not the run hook. You can only block the thread in a hook if it is in the run hook.hab from within a hook. If you think you want to, you should use a runtime configuration setting instead. If none of those will solve your problem, open an issue and tell the core team why.exec if you’re running something with a pipe. It won’t work.root user or try to sudo hab pkg install./hab/ directly./hab/ directly.All plans need a README.md. Items to strongly consider including:
The best practice is to place all plan files within a habitat parent directory, which allows for a clean separation between your application source code and habitat specific files. However, if you maintain a separate repository solely for the purpose of storing habitat plans, then the use of a habitat folder may not be necessary.
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/habitat/plan_contents/