I’ve started putting together a ‘hello world’ habitat package to get the feel for it. One thing that immediately jumped out as unsettling was that habitat (or at least the docs) seems to discourage keeping your plan.sh with your app code.
For example - I would expect to see the plan.sh sitting in the root of my project’s repository. Now build, dependency, and runtime configuration is all sitting right there with the code.
However, because of how the source is downloaded and checksummed, it looks like you get a chicken-and-egg problem where your plan.sh needs to contain the checksum for the tarball containing it.
Looking at how Chef itself handles the core packages, it looks like all the plan.sh files are kept in their own separate repository. Is this considered the best practice going forward?
You can definitely keep a plan with it’s source.
Our core components  keep all their own plans next to the source in a
habitat subdirectory. For example, the
hab command  keeps it’s plan right here .
You can change the behavior of how plans download and checksum packages to by overriding the
do_unpack callbacks to
If your plan is in your project in a habitat/ directory, you can get to your project’s files at
$PLAN_CONTEXT/.. in your plan.
See https://github.com/habitat-sh/dcob/blob/571cecf0463aaa15b22cd3344aea11cb02ba6f52/habitat/plan.sh for an example.
I see - so it looks to me like the pkg_source and pkg_shasum variables are intended to be used for externally maintained packages that you just want to wrap in Habitat. Is that a fair assessment?
Thanks for your advise!
Yes that is a fair assessment. The exact way this works may change in the future and we figure out better patterns to make it easier to write plans, but this is how it currently works.
The script that builds the plans is here, if you care to take a closer look: https://github.com/habitat-sh/habitat/blob/1ef4878bba5aa5d9c30022c4db4d8d1d809b0b1a/components/plan-build/bin/hab-plan-build.sh