cloud foundry meetup twin citiesfiles.meetup.com/15560032/tccfmeetup_20161201.pdf · • detect...

38
Twin Cities Cloud Foundry Meetup December 1, 2016 Image credit - http://www.rmeoc.org/wp-content/uploads/2016/07/foundry.jpg

Upload: others

Post on 19-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 2: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

Agenda

● Local Meetup Business● Buildpacks

Page 3: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

3

Some Meetup Business

Page 4: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 5: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

Input on Next Year

● Days of week● Timing in month● Duration● Location

Page 6: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

But First A little about me• Andrew Ripka

• @rippmn

• State transition negotiator

Page 7: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

7

Tonight’s Presentation

Page 8: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 9: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

Topics

● Structure and Opinions● Buildpack Basics● Developing Buildpacks● Example Buildpacks

Page 10: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

References

Material Sourced from https://docs.cloudfoundry.org/buildpacks/https://docs.pivotal.io/pivotalcf/1-8/buildpacks https://github.com/cloudfoundry/buildpack-packager

Page 11: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

Structure and Opinions

Page 12: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

Structured

Opinionated

Page 13: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

Structured

OpinionatedLogs

Lumber

Treehouse

Page 14: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

Stronger Guarantees

More Defaults

Page 15: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

Structured

OpinionatedLogs

Lumber

TreehouseKit

DIY Treehouse

Page 16: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 17: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

17

Buildpacks

Page 18: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 19: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 20: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

• System Buildpacks• Community Buildpacks• Custom Buildpacks - write your own

Buildpack Implementations (The Opinions)

Page 21: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

• Cloud Foundry Provided buildpacks for commonly used languages– Binary– Go– Java– Node.js– .Net Core– PHP– Python– Ruby– Staticfile

System Buildpacks

Page 23: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 24: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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]

Page 25: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 26: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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/

Page 27: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 28: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

28

Developing Custom Buildpack

Page 29: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

The Basics

29

● 3 Scripts○ bin/detect○ bin/compile○ bin/release

● Put in git repo

Page 30: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 31: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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.

Page 32: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 33: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 34: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 35: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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

Page 36: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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"

Page 37: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

37

Custom Buildpack Examples

Page 38: Cloud Foundry Meetup Twin Citiesfiles.meetup.com/15560032/TCCFMeetup_20161201.pdf · • detect validate if buildpack should be applied by examining user provided artifacts or code

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