cloud foundry meetup twin citiesfiles.meetup.com/15560032/tccfmeetup_20161201.pdf · • detect...
TRANSCRIPT
background image: 960x540 pixels - send to back of slide and set to 80% transparency
Twin Cities Cloud Foundry MeetupDecember 1, 2016
Image credit - http://www.rmeoc.org/wp-content/uploads/2016/07/foundry.jpg
Agenda
● Local Meetup Business● Buildpacks
3
Some Meetup Business
Looking For Meetup Co Organizers
Role changes for Dave and I have me seeking folks to replace Dave and assist me
Image credit - http://www.casfm.org/help_wanted/help_wanted1.jpg
Input on Next Year
● Days of week● Timing in month● Duration● Location
But First A little about me• Andrew Ripka
• @rippmn
• State transition negotiator
7
Tonight’s Presentation
background image: 960x540 pixels - send to back of slide and set to 80% transparency
Structure and Opinions - BuildpacksAndrew Ripka@rippmn
Image credit - http://www.rmeoc.org/wp-content/uploads/2016/07/foundry.jpg
Topics
● Structure and Opinions● Buildpack Basics● Developing Buildpacks● Example Buildpacks
References
Material Sourced from https://docs.cloudfoundry.org/buildpacks/https://docs.pivotal.io/pivotalcf/1-8/buildpacks https://github.com/cloudfoundry/buildpack-packager
Structure and Opinions
Structured
Opinionated
Structured
OpinionatedLogs
Lumber
Treehouse
Stronger Guarantees
More Defaults
Structured
OpinionatedLogs
Lumber
TreehouseKit
DIY Treehouse
Cloud Foundry Structure and Opinions
● Cloud Foundry is a “Foundry”○ workshop or factory for casting metal.
● Structure - coherent form or organization ● Framework - a basic structure underlying a system, concept, or
text.● Opinions - Specific Implementation of Something● Cloud Foundry really a framework for expressing opinions
17
Buildpacks
Buildpacks
• The thing that makes it possible to take the developer provided app source or binary and run on Cloud Foundry
• combines the application with the frameworks and runtimes necessary to deploy
• Usually written as Ruby scripts (can also be written as Shell)• Installed into a Cloud Foundry instance or loaded from an external
location
Build API - (The Structure)
• detect validate if buildpack should be applied by examining user provided artifacts or code– Executed for multiple buildpacks based upon configured order
• compile - assemble container file by combining application code and defined runtime components
• release describe how app container can be deployed and run on an assigned container host
• System Buildpacks• Community Buildpacks• Custom Buildpacks - write your own
Buildpack Implementations (The Opinions)
• Cloud Foundry Provided buildpacks for commonly used languages– Binary– Go– Java– Node.js– .Net Core– PHP– Python– Ruby– Staticfile
System Buildpacks
Community and Heroku Buildpacks
● Community Created Buildpacks can be found at○ https://github.com/cloudfoundry-community/cf-docs-contrib/wi
ki/Buildpacks#community-created● Heroku Buildpacks
○ https://devcenter.heroku.com/articles/buildpacks#officially-supported-buildpacks
● Heroku 3rd Party Buildpacks○ https://devcenter.heroku.com/articles/third-party-buildpacks
Your Own Opinions
● You can extend existing system buildpacks (or a community one)○ Fork Github repo
● Write your own (More on this later)○ https://docs.cloudfoundry.org/buildpacks/developing-bui
ldpacks.html
● ROADMAP - Extend through build pack chain
Buildpack ControlOpinions for Admins/Operators
● Available Buildpacks and details controlled by Admin● Disable Custom Buildpacks
○ Developers pushing apps are restricted to those installed by operators ● Install new custom buildpacks
cf create-buildpack BUILDPACK PATH POSITION [--enable|--disable]
● Delete unusedcf delete-buildpack BUILDPACK [-f]
● Update existing buildpack (change order, new version etc)cf update-buildpack BUILDPACK [-p PATH] [-i POSITION] [--enable|--disable] [--lock|--unlock]
Using Buildpacks
● Push artifacts matching the detection criteria of the buildpack○ Simplest way, and best way to ensure conformance with operators
desires○ Con here is staging app might take longer
● Specify buildpack during application push
○ Provide Name of buildpack or Git URL ○ Using push command flag (-b)
cf push z-load-port -b https://github.com/aripka-pivotal/cf-buildpack-jmeter
○ Using Manifest entryapplications:- name: workshop memory: 512M instances: 1 path: ./target/cf-spring-mvc-boot-0.0.1-SNAPSHOT.jar buildpack: java_buildpack_offline
Custom Start Commands
26
● Certain Buildpacks allow (or require) you to provide a start command○ Binary buildpack and python
● At push time this can be specified in manifest or with push flag “-c”● Can also be configured via a text file named “Procfile”
○ Specify process type and command○ Example Binary Buildpack
web: ./app
http://docs.pivotal.io/pivotalcf/1-8/buildpacks/prod-server.htmlhttp://docs.pivotal.io/pivotalcf/1-6/buildpacks/binary/
How Buildpacks are usedThe Staging Process
● Run as Tasks ● Task downloads
buildpack(s) and if present, the app’s buildpack cache.
● Executes detect on available buildpacks exiting on match (Skipped if specified)
● Detected Buildpack used to build the droplet
● Droplet stored in CC Blobstore so it can be started as Long Running Process
28
Developing Custom Buildpack
The Basics
29
● 3 Scripts○ bin/detect○ bin/compile○ bin/release
● Put in git repo
Advanced
30
● For environments with custom buildpacks disabled○ Need to package so can be installed by Admin/Operator
● Cloud Foundry installation limited connectivity or disconnected○ Can define a proxy in application manifest○ Use Buildpack Packager to create buildpack for installation
with dependencies cached■ https://github.com/cloudfoundry/buildpack-packager/blob/master/doc/disconnected_en
vironments.md
bin/detect
31
● Determines whether or not to apply the buildpack to an app. ● Called with one argument, build directory containing the app files
uploaded by cf push.● Returns 0 if buildpack compatible with app
○ system buildpacks also print the buildpack name, version, and other helpful information to STDOUT.
Example bin/detect
32
● Ruby script that checks for a Ruby app based on the existence of a Gemfile:#!/usr/bin/env ruby
gemfile_path = File.join ARGV[0], "Gemfile"
if File.exist?(gemfile_path) puts "Ruby" exit 0else exit 1end
bin/compile
33
● Builds a droplet by packaging the app dependencies necessary to run App.
● Script is run with two arguments: ○ build directory containing the app files uploaded by cf push○ cache directory the buildpack can use to store assets during
the build process for future executions on same staging cell
Example bin/compile
34
● Ruby script that downloads and installs ruby (detail not shown)#!/usr/bin/env ruby#sync output$stdout.sync = truebuild_path = ARGV[0]cache_path = ARGV[1]
install_ruby
private def install_ruby puts "Installing Ruby" # !!! build tasks go here !!! # download ruby # install rubyend
bin/release
35
● Provides metadata to Cloud Foundry indicating how the app should be executed.
● Called with one argument, build directory containing the app files uploaded by cf push and operated on by detect and compile.
● The script return the contents of YAML file in the following format:
default_process_types: web: start_command.filetype
● Custom variables will be added if .profile.d file supplied in root directory of app (also supported in some buildpacks)
http://docs.pivotal.io/pivotalcf/1-8/buildpacks/custom.html
Example bin/release
36
● Bash returns the yml text to start process#!/usr/bin/env bash
# bin/release <build-dir>
echo -e "---\ndefault_process_types:\n web: sh boot.sh"
37
Custom Buildpack Examples
Simple Example Walkthrough
Mule Buildpackhttps://github.com/aripka-pivotal/cf-buildpack-mule (note currently not working as asset downloads no longer exist)
Test withhttps://docs.mulesoft.com/mule-user-guide/v/3.3/bookstore-example
Jmeter Buildpackhttps://github.com/aripka-pivotal/cf-buildpack-jmeter/tree/master/bin