Skip to content

Instantly share code, notes, and snippets.

@dayne
Last active December 8, 2017 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dayne/02cb1fd8d66dc74d41f325c31aed3b2b to your computer and use it in GitHub Desktop.
Save dayne/02cb1fd8d66dc74d41f325c31aed3b2b to your computer and use it in GitHub Desktop.
habitat setup

Simple build system for packages

Uses bash scripts for the plans - check out github.com/habitat-sh/core-plans

When making habitat packages you are building packages in isolation, so they don't depend on the build system's libraries tools, and you can make them portable. They are kind of making their own OS packages available.

Any of these packages can run on any linux OS that has a modern kernel on a x86_64 architecture (no love for RPi). Lots of tutorials.

hab studio enter

  • what you will see is only what was in the directory that you entered - it will look for a .bah
  • build (path to hab dir for what you want to build)
  • hab pkg install results/.... installs into your studio
    • /hab/pkgs/(origin)/(packages)
  • Linux system with hab binary (provided via cookbook hopefully) will put packages into /hab/pkgs/(origin)/(package)
    • hab pkg can install via the local .hart file or in the public habitat depo (only if your package is public)
      • can also install core packages too: hab pkg install core/curl for example
      • hab pkg install core/which
    • Once installed to ways to execute installed packages
      • hab pkg exec core/which which - run the package w/o mucking with your system
      • hab pkg binlink core/which which - puts which into /bin/
        • in hab studio put is virtual environment /bin .. in linux you'd need to sudo that

creates a new .hab artifact for you to put up somewhere (s3, your artifactory, or such)

just a few notes from setting up habitat for the first time.

  • Get habitat - on my mac I needed docker
    • brew cask install docker
    • brew cask install hab
    • might need to refresh your path brain: hash -r
  • Logged into https://www.habitat.sh/ using my Github identity
  • Got invited to a Origin for a group
  • Setup my stuff - hab setup
    • yes - create a default origin
    • uafgina - our groups origin (already received the invite)
    • yes - create my own origin key for my box for this group
    • yes - setup default github access token
      • https://github.com/settings/tokens
      • create new token - called mine: hab-uafgina
      • give read:org and user:email scopes
      • generate token and copy the token and give to hab setup - if you lose it delete the old one and create a new one.
    • no - don't worry about analytics

upload key to origin

For example: hab origin key upload uafgina If that doesn't work you can copy it up there manually to the Upload public origin key doing a dance like;

  • cat /Users/dayne/.hab/cache/keys/uafgina-20170810185626.pub | pbcopy
  • paste into Upload public origin key section

Ready to rumble

  • hab pkg search core/nginx - see if it works (for uafgina)
  • hab studio enter

If you want to run a service from habitat there is a service to help called habitat supervisor hab sub. Hab supervisor can help manage habitate installed services. By having habitat supervisor manage your habitate installed service - it can be aware of updates to the services from the habitate depo. You can build your package with hooks that can say 'when config updates do XYZ' or 'when a new package update do ZQF'.

  • init hook - gives you setup - happens right before run
    • have a data folder you need symlinked into habitate service folder
    • for example rails code copied into app
  • run hook - launches the app
    • the puma run app that launches the app

Redis install and launch example

  • hab pkg install core/redis
  • hab sup status
  • hab sub start core/redis - launch as foreground process

Supervisor has ability to have config option that is passed into the services. See the default.toml file for a installed package. Note: do not edit that file it is added as part of the plan.

https://www.habitat.sh/docs/internals-supervisor/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment