The Power of Buildpacks in PaaSThe Platform for the Agile EnterpriseJohn WetherillTechnology Evangelist
Ho Ming LiCloud Engineer
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Recent Events
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Recent Events
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
What is Stackato?
A secure, stable, and commercially supported Platform-as-a-Service (PaaS) built with open source components such as Cloud Foundry and Docker
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Buildpacks Defined
“Cloud Foundry uses buildpacks to transform user-provided artifacts into runnable applications”
Buildpacks can be used to:
• examine user-provided artifacts• download dependencies• configure application properties• specify the application entry point and runtime options
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Anatomy of a Buildpack
bin/detect
bin/release
bin/compile
• a buildpack is a network-accessible git repository• repo must contain a bin directory with three scripts
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
detect script
• determine whether to apply a buildpack• single parameter: BUILD_DIR• script examines this directoryIf buildpack can service this app: • print framework name to stdout • exit 0
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
sample detect script
#!/bin/sh
if [-f $1/*.js]; then# looks like a node application echo “nodejs” exit 0else exit 1fi
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
compile script
• perform the buildpack transformation• three parameters: BUILD_DIR CACHE_DIR ENV_DIR
• anything goes here: download dependencies, configure environment, tweak files
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
sample compile script
#!/bin/shif [ ! -s $1/hello.txt ]; then echo "hello.txt was empty" exit 1fi
cat $1/hello.txt | sed -e "s/[Hh]ello/Goodbye/g" > $1/goodbye.txt
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
sample compile script
#!/bin/sh
wget something
apt-get install something-else
echo “some: config” > config-file.yml
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
release script
• release script must output yaml
• specify “addons” • specify Procfile entries (app entrypoint)
(config_vars from Heroku deprecated - use shell-script in app instead)
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
sample release script
#!/usr/bin/env bash
cat <<EOF---web: java $JAVA_OPT jetty-runner --port $PORTaddons: mysql:devEOF
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Procfile
• Not part of buildpack• Specifies app entrypoint• Procfile must be present in app build dir
Sample procfile for Java app:
web: java $JAVA_OPTS jetty-runner --port $PORT
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
CloudFoundry / Stackato built-in buildpacks
• https://github.com/cloudfoundry/java-buildpack
• https://github.com/cloudfoundry/heroku-buildpack-ruby
• https://github.com/cloudfoundry/heroku-buildpack-nodejs
For Java, Ruby, NodeJS
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
CloudFoundry Community Buildpacks
https://github.com/cloudfoundry-community/cf-docs-contrib/wiki/Buildpacks
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Summary
Procfile
Application source
Buildpack
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Minimal buildpack
https://github.com/heroku/heroku-buildpack-hello
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Buildpacks and stackato.yml
stackato.yml is used in conjunction with buildpack to:
• specify buildpack location• configure environment• specify staging and runtime hooks• request services• request resources• specify app properties
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Specifying Buildpacks
• Buildpack can be selected in stackato.yml:
buildpack: https://github.com/user/mybuildpack.git
• Or as option to stackato command:
stackato push --buildpack ssh://git/buildpack.git
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Legacy Buildpack
• special bundled buildpack for “legacy” Stackato apps• provides all frameworks from pre 3.0 Stackato• specify framework and runtime in stackato.yml
name: bottle-py3framework: type: python runtime: python32
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Buildpack Catalog
http://buildpack-catalog.stacka.to/buildpacks/
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Customizing a buildpack
Why customize?
• alternate versions of runtimes, frameworks, services
• new (or old) runtimes (FORTRAN anyone?)
• complete control of app provisioning process
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Customizing a buildpack
Three simple steps:
1. fork an existing buildpack
2. tweak the scripts in bin, add assets
3. specify location of new buildpack in stackato.yml or as parameter to “stackato push --buildpack https://…”
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Buildpacks and Licenses
EULAsSoftware license stringsAPI keysCommercial Software
Example:
https://github.com/cloudfoundry/ibm-websphere-liberty-buildpack.git
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Buildpack Futures
Better Asset Caching
More services and frameworks
Docker Integration?
activestate.com/stackato | @activestate | #stackato | activestate.com/blog | Copyright 2014
Why Enterprises Use Stackato
Faster Time to MarketWith Stackato, developers can get apps to the cloud in minutes, not weeks.
Greater SecurityStackato has been extended and hardened to provide enterprises with tighter security, better compliance, and more control over secure, sensitive data.
Agility and ScalabilityAs usage grows, Stackato scales applications to deliver performance for end-users demand.
Productivity and InnovationStackato automates the configuration, deployment, and management of applications.
FlexibilityStackato gives developers and IT managers the freedom they need. The polyglot nature of Stackato means you can give your developers the flexibility to work with the best choice of language for any task.
Download your own Stackato micro cloud at: http://www.activestate.com/stackato