Natural vs. Modified Habitat Primary Headwater Habitat Streams Headwater Habitat Evaluation Index.
Containerdays Intro to Habitat
-
Upload
mandi-walls -
Category
Software
-
view
131 -
download
0
Transcript of Containerdays Intro to Habitat
Mandi Walls
Technical Community Manager for EMEA
@lnxchk
#habitatsh
http://slack.habitat.sh/
Ian Henry @Eeyun___ Habitat Community lead
EVERY business is a software business
We’re going to be a software
company with airplanes.– CIO, Alaska Airlines
How Do We Run Applications?
• On a computer
• With an OS
• And some libraries
• And some configuration
• And some way to start it and stop it
So. Habitat.
• Reduce snowflakeness
• Support microservices
• Manage container creep
https://www.bonanza.com/listings/Premier-Food-Storage-Containers-20-Piece-Set-Grey/443972348
Modern Applications Are Trending Toward
• Immutability
• Platform agnosticism
• Complexity reduction
• Scalability
https://amazingmusthaves.com/products/steel-insulated-food-containers/
Single Artifact Demo - Ponyserve
• Ruby app with HTTP interface
• It really just displays ASCII ponies
• https://bldr.habitat.sh/#/pkgs/smith/ponyserve/
• sudo HAB_PONYSERVE='message="Hello,
Container Days"' hab start smith/ponyserve
What Habitat Gets You
• Distro agnostic packaging system
• Service runtime and discovery
• Configuration exposed via API
• Packages are signed by the system
Habitat Studio
• Provides a busy box clean
room for your app
• Plus a set of tools for
manipulating and running
harts
Why the Studio?
• Declare explicit dependencies
• Ship exactly what you need
• Sign your packages and store artifacts
Habitat Plans
• Plan files are where you put together your builds
• They are bash
• Plans are versioned and can be shared on the
habitat depot
• Plans have multiple sections for your needs
What’s In A Plan?
pkg_origin=firstnamelastname
pkg_name=national-parks
pkg_description="A sample JavaEE Web app deployed in Tomcat8"
pkg_version=0.1.3
pkg_maintainer="First Last <[email protected]>"
pkg_license=('Apache-2.0')
pkg_source=https://github.com/billmeyer/national-parks/archive/v${pkg_version}.tar.gz
pkg_shasum=56a70d7fc432ad275ba256150bd010ce2581346c848e40ddc0fd0f62c5b17a54
pkg_upstream_url=https://github.com/billmeyer/national-parks
pkg_deps=(core/tomcat8 billmeyer/mongodb)
pkg_build_deps=(core/git core/maven)
pkg_expose=(8080)
pkg_svc_user="root"
pkg_svc_group="root"
Plans Have Callbacks
Shell functions executed when building
artifacts:
• do_begin()
• do_download()
• do_verify()
• do_check()
• do_clean()
• do_unpack()
• do_prepare()
• do_build()
• do_install()
• do_strip()
• do_end()
Variables
• HAB_CACHE_SRC_PATHThe default path where source archives are downloaded, extracted, & compiled.
• ${pkg_dirname}Set to ${pkg_name}-${pkg_version} by default. If a .tar file extracts to a directory that's different from the filename, then you would need to override this value to match the directory name created during extraction.
• ${pkg_filename} Set manually in the plan.sh
• ${pkg_version} Set manually in the plan.sh
Habitat Tools for Dependencies
•hab pkg path team/app
• You can have build deps and runtime deps
• Build deps get into your hab studio when you are
building
• Runtime deps come along into your hart
Keep artifacts small and under
control!
New! Scaffolding!
• Default core-built dependencies for common
runtimes
• Ruby and Node so far
Go, Python, Java on the way!pkg_name=MY_APP
pkg_origin=MY_ORIGIN
pkg_version=MY_VERSION
pkg_scaffolding=core/scaffolding-ruby
What Gets Built?
• Everything. Sort of.
• Build your own apps from source
• Decide if you want upstream binaries or source for
things like runtime
You don’t have to build Tomcat, but you can
• For COTS, use the binaries and skip steps
Habitat Hooks
• Travels with the app
• Tell the app how to start, and if there is something
that needs to be done before start
• Let’s look at a run hook file
Run Hook for Tomcat#!/bin/bash
exec 2>&1
echo "Starting Apache Tomcat"
export JAVA_HOME=$(hab pkg path core/jdk8)
export TOMCAT_HOME="$(hab pkg path core/tomcat8)/tc"
source {{pkg.svc_config_path}}/catalina-opts.conf
echo "\$CATALINA_OPTS=$CATALINA_OPTS"
cp "$(hab pkg path {{pkg.origin}}/{{pkg.name}})/{{pkg.name}}.war" "$TOMCAT_HOME/webapps/"
exec ${TOMCAT_HOME}/bin/catalina.sh run
Configuration
• Can be manipulated at runtime
• Also travels with the app
• Provides variable substitution and templating
A catalina-opts File
{{~#if bind.database}}{{~#each bind.database.members}}
export CATALINA_OPTS="-DMONGODB_SERVICE_HOST={{address}} -DMONGODB_SERVICE_PORT={{port}}"
{{~/each}}{{~/if}}
The Depot
• You can share plans with the Depot, and other hab
users share theirs
• Has team namespacing
• The core plans are those built by the Habitat team
• https://app.habitat.sh/
Caveat - Internet
• You can build your own stuff inside your own
network, sort of, when it’s all on one machine
• There will eventually be a private depot server
• For now, hab and its components need internet
access
Build Output
• By default, it’s a hart – a compressed tarball with
some metadata and a signature
• You can export to other formats, like Docker
containers
• The hart itself it runnable
Runtime
• The hab runtime includes management, service
discovery, other features
• The habs in your application create a mesh so they
can talk to each other
• You can even update your application via the mesh
without restarting every application manually
Running a Hart
sudo hab start nathenharvey/national-parks --
listen-gossip 0.0.0.0:9639 --listen-http
0.0.0.0:9632 --peer 127.0.0.1 –bind
database:mongodb.default
Demo Application: National Parks
• MongoDB running in Docker
• Java application on Tomcat running in Habitat
supervisor
• https://blog.chef.io/2016/09/07/deploy-java-web-
app-on-tomcat-8-with-habitat/
Join Us!
• On Slack!
http://slack.habitat.sh
• Online! With Tutorials!
https://www.habitat.sh/
• On Github!
https://github.com/habitat-sh
• The demo in this talk
https://github.com/lnxchk/containerdays
Try it out!
Share your story!
Get some swag!!
goo.gl/WrHQTU
Other References
• Summary on The New Stack
https://thenewstack.io/chef-habitat-addresses-issues-
moving-containers-production
• Our YouTube Channel
https://www.youtube.com/user/getchef
Running a hart
HAB_MONGODB=“[mongod.net]
bind_ip = '0.0.0.0'
[mongod.security]
cluster_auth_mode = ''” sudo -E hab start
nathenharvey/mongodb
Dependency Discovery
[[pkg.deps]]
name = "mongo-tools"
origin = "core"
release = "20161214223359"
version = "3.2.10"
[[pkg.deps]]
name = "openssl"
origin = "core"
release = "20161214012334"
version = "1.0.2j”
The supervisor process exposes
the configuration information, build
dependencies, service info over http