extending cloud foundry with custom services and buildpacks

100
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Extending Cloud Foundry With Custom Integration Cornelia Davis Scott Frederick Thursday, November 21, 13

Upload: cornelia-davis

Post on 10-May-2015

1.829 views

Category:

Technology


3 download

DESCRIPTION

Presentation given at Spring One 2013 by Cornelia Davis and Scott Frederick. Covers the different types of Cloud Foundry services, including marketplace services on run.pivotal.io, user defined service instances and Cloud Foundry Service Brokers. Also covers buildpacks, the mechanism for bringing application context to the applications that are deployed to and run within the Cloud Foundry PaaS.

TRANSCRIPT

Page 1: Extending Cloud Foundry with Custom Services and Buildpacks

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Extending Cloud FoundryWith Custom Integration

Cornelia DavisScott Frederick

Thursday, November 21, 13

Page 2: Extending Cloud Foundry with Custom Services and Buildpacks

Who and What...

2Thursday, November 21, 13

Page 3: Extending Cloud Foundry with Custom Services and Buildpacks

Who and What...

2

Extending the set of services

Customizing application containers

Thursday, November 21, 13

Page 4: Extending Cloud Foundry with Custom Services and Buildpacks

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Services

Thursday, November 21, 13

Page 5: Extending Cloud Foundry with Custom Services and Buildpacks

Demo

4Thursday, November 21, 13

Page 6: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

Browse

Thursday, November 21, 13

Page 7: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP)

Browse

Thursday, November 21, 13

Page 8: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)

Browse

Thursday, November 21, 13

Page 9: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

Browse

Thursday, November 21, 13

Page 10: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

Browse

Thursday, November 21, 13

Page 11: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

Browse

Thursday, November 21, 13

Page 12: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP)

Browse

Thursday, November 21, 13

Page 13: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP) bind (HTTP)

Browse

Thursday, November 21, 13

Page 14: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP) bind (HTTP)up to you

Browse

Thursday, November 21, 13

Page 15: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP) bind (HTTP)up to you

credentials

Browse

Thursday, November 21, 13

Page 16: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP) bind (HTTP)up to you

credentials

Browse

Thursday, November 21, 13

Page 17: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP) bind (HTTP)up to you

...go ahead and deploy (HTTP)

credentials

Browse

Thursday, November 21, 13

Page 18: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP) bind (HTTP)up to you

...go ahead and deploy (HTTP)

credentials

DropletcredentialsBrowse

Thursday, November 21, 13

Page 19: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP) bind (HTTP)up to you

...go ahead and deploy (HTTP)

credentials

DropletcredentialsBrowse

Thursday, November 21, 13

Page 20: Extending Cloud Foundry with Custom Services and Buildpacks

When you cf push

5

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)

VM for Service Instances

DEA

CLI

MySQL(process)

provision (HTTP) provision (HTTP)up to you

bind (HTTP) bind (HTTP)up to you

...go ahead and deploy (HTTP)

credentials

DropletcredentialsBrowse Note:

• Don’t call ‘em “Gateways” anymore• Broker only used during

•(un)provision•(un)bind

Thursday, November 21, 13

Page 21: Extending Cloud Foundry with Custom Services and Buildpacks

Demo

6Thursday, November 21, 13

Page 22: Extending Cloud Foundry with Custom Services and Buildpacks

Agenda

§Extending services offerings within run.pivotal.io–Partnering

§Building services–Into your own Cloud Foundry

§User-provided service instances–For access to pre&externally-provisioned services

Thursday, November 21, 13

Page 23: Extending Cloud Foundry with Custom Services and Buildpacks

run.pivotal.io Marketplace Services

8

run.pivotal.io

Thursday, November 21, 13

Page 24: Extending Cloud Foundry with Custom Services and Buildpacks

run.pivotal.io Marketplace Services

8

Contact Nima Badiey ([email protected])

to play

run.pivotal.io

Thursday, November 21, 13

Page 25: Extending Cloud Foundry with Custom Services and Buildpacks

run.pivotal.io Marketplace Services

9

Cloud Controller

AppDirectService Broker

DEABrowser

Thursday, November 21, 13

Page 26: Extending Cloud Foundry with Custom Services and Buildpacks

run.pivotal.io Marketplace Services

9

Cloud Controller

AppDirectService Broker

DEA

Dropletcredentials

Browser

credentials

Thursday, November 21, 13

Page 27: Extending Cloud Foundry with Custom Services and Buildpacks

run.pivotal.io Marketplace Services

9

Cloud Controller

AppDirectService Broker

DEA

Dropletcredentials

Browser

credentials

Thursday, November 21, 13

Page 28: Extending Cloud Foundry with Custom Services and Buildpacks

Demo

10Thursday, November 21, 13

Page 29: Extending Cloud Foundry with Custom Services and Buildpacks

Cloud Foundry Services• There is only one built in - mysql

– or many more depending on how you count• How to build them - the evolution:

– CF v1, subclass Ruby base classes– CF v2, a RESTful protocol (which is itself evolving)

Polyglot!

• There are three parts to the protocol...

11Thursday, November 21, 13

Page 30: Extending Cloud Foundry with Custom Services and Buildpacks

1Broker Registers Offerings

12

Rou

ter

Cloud Controller

VM for Service Instances

DEA

CLI

My Service(process)

Bro

wse

r

UA

A

On Broker Startup...

Service Broker

(i.e. mysql)

Thursday, November 21, 13

Page 31: Extending Cloud Foundry with Custom Services and Buildpacks

1Broker Registers Offerings

12

Rou

ter

Cloud Controller

VM for Service Instances

DEA

CLI

My Service(process)

Authenticate

Bro

wse

r

UA

A

On Broker Startup...

Service Broker

(i.e. mysql)

Thursday, November 21, 13

Page 32: Extending Cloud Foundry with Custom Services and Buildpacks

1Broker Registers Offerings

12

Rou

ter

Cloud Controller

VM for Service Instances

DEA

CLI

My Service(process)

Authenticate

Bro

wse

r

UA

Atoken

On Broker Startup...

Service Broker

(i.e. mysql)

Thursday, November 21, 13

Page 33: Extending Cloud Foundry with Custom Services and Buildpacks

1Broker Registers Offerings

12

Rou

ter

Cloud Controller

VM for Service Instances

DEA

CLI

My Service(process)

Authenticate

Services Catalog

Bro

wse

r

UA

Atoken

Get catalog (HTTP)

On Broker Startup...

Service Broker

(i.e. mysql)

Thursday, November 21, 13

Page 34: Extending Cloud Foundry with Custom Services and Buildpacks

1Broker Registers Offerings

12

Rou

ter

Cloud Controller

VM for Service Instances

DEA

CLI

My Service(process)

Authenticate

Services Catalog

Bro

wse

r

UA

Atoken

Get catalog (HTTP)

Update catalog (HTTP)

On Broker Startup...

Service Broker

(i.e. mysql)

Thursday, November 21, 13

Page 35: Extending Cloud Foundry with Custom Services and Buildpacks

2Broker Services (un)provision and (un)bind

13

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

CLI

My Service(process)U

AA

Prerequisite...

Thursday, November 21, 13

Page 36: Extending Cloud Foundry with Custom Services and Buildpacks

2Broker Services (un)provision and (un)bind

13

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

CLI

My Service(process)U

AA

Prerequisite...

shared secret

Thursday, November 21, 13

Page 37: Extending Cloud Foundry with Custom Services and Buildpacks

2Broker Services (un)provision and (un)bind

13

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

CLI

My Service(process)U

AA

provide shared secret (HTTP)

Prerequisite...

shared secret

Thursday, November 21, 13

Page 38: Extending Cloud Foundry with Custom Services and Buildpacks

2Broker Services (un)provision and (un)bind

14

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

DEA

CLI

My Service(process)

Bro

wse

r

UA

A

Thursday, November 21, 13

Page 39: Extending Cloud Foundry with Custom Services and Buildpacks

2Broker Services (un)provision and (un)bind

14

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

DEA

CLI

My Service(process)

Bro

wse

r

UA

A

Thursday, November 21, 13

Page 40: Extending Cloud Foundry with Custom Services and Buildpacks

2Broker Services (un)provision and (un)bind

14

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

DEA

CLI

My Service(process)

up to you

Bro

wse

r

UA

A (un)provision (HTTP)

Thursday, November 21, 13

Page 41: Extending Cloud Foundry with Custom Services and Buildpacks

2Broker Services (un)provision and (un)bind

14

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

DEA

CLI

My Service(process)

up to you

Dropletcredentials

Bro

wse

r

UA

A (un)provision (HTTP)

(un)bind (HTTP)

credentials

Thursday, November 21, 13

Page 42: Extending Cloud Foundry with Custom Services and Buildpacks

2Broker Services (un)provision and (un)bind

14

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

DEA

CLI

My Service(process)

up to you

Dropletcredentials

Bro

wse

r

UA

A (un)provision (HTTP)

(un)bind (HTTP)

credentials

Thursday, November 21, 13

Page 43: Extending Cloud Foundry with Custom Services and Buildpacks

3Orphan Management

15

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

CLI

My Service(process)

Services Catalog

UA

A

Broker is responsible for eventual consistency...

Thursday, November 21, 13

Page 44: Extending Cloud Foundry with Custom Services and Buildpacks

3Orphan Management

15

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

CLI

My Service(process)

Authenticate

Services Catalog

UA

Atoken

Broker is responsible for eventual consistency...

Thursday, November 21, 13

Page 45: Extending Cloud Foundry with Custom Services and Buildpacks

3Orphan Management

15

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

CLI

My Service(process)

Authenticate

Services Catalog

UA

Atoken

Get catalog (HTTP)

Broker is responsible for eventual consistency...

Thursday, November 21, 13

Page 46: Extending Cloud Foundry with Custom Services and Buildpacks

3Orphan Management

15

Rou

ter

Cloud Controller

Service Broker

(i.e. mysql)VM for Service

Instances

CLI

My Service(process)

Authenticate

up to you

Services Catalog

UA

Atoken

Get catalog (HTTP)

Broker is responsible for eventual consistency...

Thursday, November 21, 13

Page 47: Extending Cloud Foundry with Custom Services and Buildpacks

New (V2) Services API• Simplifies things a bunch!• Unidirectional - everything initiated from Cloud Controller• Asynchronous provisioning• From V1 RESTful Services API:

– Replace offerings registration with endpoint that allows the CC to GET the offerings

– Remove orphan management

16Thursday, November 21, 13

Page 48: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

17

VM for Service Broker

Service Broker

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

NATS

One option (CF v1 services)...

Thursday, November 21, 13

Page 49: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

17

VM for Service Broker

Service Broker

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

NATS

provision

One option (CF v1 services)...

Thursday, November 21, 13

Page 50: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

17

VM for Service Broker

Service Broker

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

NATS

provision

One option (CF v1 services)...

Thursday, November 21, 13

Page 51: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

17

VM for Service Broker

Service Broker

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

NATS

provision

One option (CF v1 services)...

Thursday, November 21, 13

Page 52: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

17

VM for Service Broker

Service Broker

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

VM for Service Instances

My Service(process)

Node

NATS

provision

One option (CF v1 services)...

Thursday, November 21, 13

Page 53: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

18

VM for Service Broker

Service Broker

VM for Service Instances

Node

VM for Service Instances

Node

VM for Service Instances

Node

NATS

Another...

WardenSvc Process

WardenSvc Process

WardenSvc Process

Thursday, November 21, 13

Page 54: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

18

VM for Service Broker

Service Broker

VM for Service Instances

Node

VM for Service Instances

Node

VM for Service Instances

Node

NATS

provision

Another...

WardenSvc Process

WardenSvc Process

WardenSvc Process

Thursday, November 21, 13

Page 55: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

18

VM for Service Broker

Service Broker

VM for Service Instances

Node

VM for Service Instances

Node

VM for Service Instances

Node

NATS

provision

Another...

WardenSvc Process

WardenSvc Process

WardenSvc Process

WardenSvc Process

Thursday, November 21, 13

Page 56: Extending Cloud Foundry with Custom Services and Buildpacks

It’s Up To YOU Patterns

18

VM for Service Broker

Service Broker

VM for Service Instances

Node

VM for Service Instances

Node

VM for Service Instances

Node

NATS

provision

Another...

WardenSvc Process

WardenSvc Process

WardenSvc Process

WardenSvc Process

Thursday, November 21, 13

Page 57: Extending Cloud Foundry with Custom Services and Buildpacks

VM for Service Instances

VM for Service Instances

VM for Service Instances

It’s Up To YOU Patterns

19

VM for Service Broker

Service Broker

NATS

And another...

NodeNode

Node

Thursday, November 21, 13

Page 58: Extending Cloud Foundry with Custom Services and Buildpacks

VM for Service Instances

VM for Service Instances

VM for Service Instances

It’s Up To YOU Patterns

19

VM for Service Broker

Service Broker

NATS

provision

And another...

NodeNode

Node

Thursday, November 21, 13

Page 59: Extending Cloud Foundry with Custom Services and Buildpacks

VM for Service Instances

VM for Service Instances

VM for Service Instances

It’s Up To YOU Patterns

19

VM for Service Broker

Service Broker

NATS

provision

And another...

NodeNode

Node

Thursday, November 21, 13

Page 60: Extending Cloud Foundry with Custom Services and Buildpacks

VM for Service Instances

VM for Service Instances

VM for Service Instances

It’s Up To YOU Patterns

19

VM for Service Broker

Service Broker

NATS

provision

And another...

NodeNode

Warden

Warden WardenSvc Process Svc Process

Svc Process

Node

Thursday, November 21, 13

Page 61: Extending Cloud Foundry with Custom Services and Buildpacks

VM for Service Instances

VM for Service Instances

VM for Service Instances

It’s Up To YOU Patterns

19

VM for Service Broker

Service Broker

NATS

provision

And another...

NodeNode

Warden

Warden WardenSvc Process Svc Process

Svc Process

Node

Thursday, November 21, 13

Page 62: Extending Cloud Foundry with Custom Services and Buildpacks

BOSH deployment

packages

- service broker - your impl

- service node - services binaries - services warden - your node impl

20

jobs

- service broker - ref service broker pkg - start web service

- service node - ref service node pkg - start node

Provisions broker VMs

Provisions service VMs

Configure shared secret (for example)

Thursday, November 21, 13

Page 63: Extending Cloud Foundry with Custom Services and Buildpacks

But what about...

21

AppDirect Service Broker

Service Broker

Service Broker

MySQL MySvc

core

Thursday, November 21, 13

Page 64: Extending Cloud Foundry with Custom Services and Buildpacks

But what about...

21

AppDirect Service Broker

Service Broker

Service Broker

MySQL MySvc

core

ERP Oracle

?

Thursday, November 21, 13

Page 65: Extending Cloud Foundry with Custom Services and Buildpacks

User-provided Service Instances

22

Rou

ter

Cloud Controller

CLI

UA

A

Prerequisite...

ERP

OracleDEA

Bro

wse

r

Thursday, November 21, 13

Page 66: Extending Cloud Foundry with Custom Services and Buildpacks

User-provided Service Instances

22

Rou

ter

Cloud Controller

CLI

UA

Aprovide service credentials (HTTP)

Prerequisite...

ERP

OracleDEA

Bro

wse

r

credentials

Thursday, November 21, 13

Page 67: Extending Cloud Foundry with Custom Services and Buildpacks

User-provided Service Instances

22

Rou

ter

Cloud Controller

CLI

UA

Aprovide service credentials (HTTP)

Prerequisite...

ERP

OracleDEA

Dropletcredentials

Bro

wse

r

credentials(un)bind (HTTP)

Thursday, November 21, 13

Page 68: Extending Cloud Foundry with Custom Services and Buildpacks

User-provided Service Instances

22

Rou

ter

Cloud Controller

CLI

UA

Aprovide service credentials (HTTP)

Prerequisite...

ERP

OracleDEA

Dropletcredentials

Bro

wse

r

credentials(un)bind (HTTP)

Thursday, November 21, 13

Page 69: Extending Cloud Foundry with Custom Services and Buildpacks

Demo

23Thursday, November 21, 13

Page 70: Extending Cloud Foundry with Custom Services and Buildpacks

Tell ‘em what you told ‘em...

§Extending services offerings within run.pivotal.io–Partnering

§Building services–Into your own Cloud Foundry

§User-provided service instances–For access to pre&externally-provisioned services

Thursday, November 21, 13

Page 71: Extending Cloud Foundry with Custom Services and Buildpacks

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Buildpacks

Thursday, November 21, 13

Page 72: Extending Cloud Foundry with Custom Services and Buildpacks

Deploying to Cloud Foundry

26Thursday, November 21, 13

Page 73: Extending Cloud Foundry with Custom Services and Buildpacks

Staging and Buildpacks

Buildpacks are responsible for preparing the machine image for an application

27

Application

Container

Runtime

Operating System

Libraries

DEA

Buildpack } Droplet

Thursday, November 21, 13

Page 74: Extending Cloud Foundry with Custom Services and Buildpacks

CompatibilityCloud Foundry buildpacks follow the Heroku buildpack design

Cloud Foundry and Heroku buildpacks are compatible (if you take care to make them compatible)

Other PaaS providers are adopting the buildpack design

28Thursday, November 21, 13

Page 75: Extending Cloud Foundry with Custom Services and Buildpacks

Built-in or BYO

cf push

The application is tested against a set of curated

buildpacks

29

cf push --buildpack <url>

The buildpack is referenced by a Git URL

Thursday, November 21, 13

Page 76: Extending Cloud Foundry with Custom Services and Buildpacks

Built-in Buildpacks

30

→→→

Thursday, November 21, 13

Page 77: Extending Cloud Foundry with Custom Services and Buildpacks

Tested Buildpackshttps://github.com/cloudfoundry-community/cf-docs-contrib/wiki/Buildpacks

31

LanguagesContainers

Haskell

Thursday, November 21, 13

Page 78: Extending Cloud Foundry with Custom Services and Buildpacks

/bin/detect app_directoryInspect app bits to determine buildpack applicability

/bin/compile app_directory cache_directory Download and install runtime, container, packages, libraries; install app bits as necessary

/bin/release app_directoryBuild app start command

32

Buildpack API

Thursday, November 21, 13

Page 79: Extending Cloud Foundry with Custom Services and Buildpacks

/bin/detect

Inspect the app bits to determine if the buildpack knows how to handle the application

33

Gemfile exists

package.json exists

setup.py exists

On match, return exit code 0 and write to STDOUT a string identifying the buildpack

(often just the name of the language supported)

Thursday, November 21, 13

Page 80: Extending Cloud Foundry with Custom Services and Buildpacks

/bin/detect

$ cf push

DEA iterates over built-in buildpacks calling

/bin/detect scripts until one of them returns

exit code 0

34

$ cf push --buildpack <url>

/bin/detect is not called

Thursday, November 21, 13

Page 81: Extending Cloud Foundry with Custom Services and Buildpacks

/bin/compile

Download and install any necessaryruntime (Java VM, Ruby interpreter, JavaScript interpreter)container (web server)support libraries, packages, modules (Ruby gems, NPM packages)

...and then installing the app bits into the runtime or container

35Thursday, November 21, 13

Page 82: Extending Cloud Foundry with Custom Services and Buildpacks

/bin/compile CachingRuntime, container, and support packages are downloaded from sources external to Cloud Foundry

DEA provides a location for storing downloaded artifacts to speed subsequent staging operations

36Thursday, November 21, 13

Page 83: Extending Cloud Foundry with Custom Services and Buildpacks

/bin/release

Build a YAML-formatted hash with three possible keys

37

addons: []config_vars: {}default_process_types: web: <start command>

On Cloud Foundry, currently only the web: value is used to get the start command for the app

Thursday, November 21, 13

Page 84: Extending Cloud Foundry with Custom Services and Buildpacks

Java BuildpackSupports a variety of JVM languages, containers, and frameworks with a modular, configurable, and extensible design

38Thursday, November 21, 13

Page 85: Extending Cloud Foundry with Custom Services and Buildpacks

Java Buildpack Concepts

39

Containers

How an application is run

Frameworks

Additional application transformations

JREsJava Runtimes

Thursday, November 21, 13

Page 86: Extending Cloud Foundry with Custom Services and Buildpacks

Java Buildpack Concepts

40

Containers Frameworks

JREs

OpenJDK

Java main()TomcatGroovy

Spring Boot CLIPlay

Spring configPlay config

Play JPA configNew Relic

Thursday, November 21, 13

Page 87: Extending Cloud Foundry with Custom Services and Buildpacks

Container Detection Criteria

41

Java main() META-INF/MANIFEST.MF exists with Main-class attribute set

Tomcat WEB-INF directory exists

Groovy.groovy file with a main() method, or.groovy file with no classes, or.groovy file with a shebang (#!) declaration

Spring Boot CLIone or more POGO .groovy files with no main() method, andno WEB-INF directory

Play start and lib/play.play_*.jar exist

Choose zero or one

Thursday, November 21, 13

Page 88: Extending Cloud Foundry with Custom Services and Buildpacks

Framework Detection Criteria

42

Spring spring-core*.jar exists

Play config Play application detected

Play JPA config play-java-jpa plugin exists in app

New Relic New Relic service bound to app

Choose all that apply

Thursday, November 21, 13

Page 89: Extending Cloud Foundry with Custom Services and Buildpacks

/bin/compile Output Example-----> Downloaded app package (18M)

-----> Downloading OpenJDK 1.7.0_21 JRE (17.5s) Expanding JRE to .java (1.4s)

-----> Downloading Auto Reconfiguration 0.7.1 (1.4s) Modifying /WEB-INF/web.xml for Auto Reconfig-----> Downloading Tomcat 7.0.42 (3.5s) Expanding Tomcat to .tomcat (0.2s)

Downloading Buildpack Tomcat Support 1.1.1 (0.0s)-----> Uploading droplet (55M)

43

DEA

Buildpack

DEA

Thursday, November 21, 13

Page 90: Extending Cloud Foundry with Custom Services and Buildpacks

See What’s Going On $ cf files <app-name> app

.buildpack-diagnostics/

.java/

.lib/

.tomcat/

META-INF/

WEB-INF/

assets/

44

Buildpack-installed runtime Buildpack-installed support libraries Buildpack-installed container

DEA-downloaded application files

Thursday, November 21, 13

Page 91: Extending Cloud Foundry with Custom Services and Buildpacks

See What’s Going On $ cf files <app-name> staging_info.yml

detected_buildpack: openjdk-1.7.0_21, tomcat-7.0.42,

spring-auto-reconfiguration-0.7.1

start_command: JAVA_HOME=.java

JAVA_OPTS="-Dhttp.port=$PORT

-Djava.io.tmpdir=$TMPDIR -XX:MaxPermSize=52428K

-XX:OnOutOfMemoryError=./.buildpack-diagnostics/killjava

-Xmx384M -Xss1M" .tomcat/bin/catalina.sh run

45Thursday, November 21, 13

Page 92: Extending Cloud Foundry with Custom Services and Buildpacks

CustomizationTwo ways to customize the Java buildpack

Configure artifacts used by standard JREs, Containers, and Frameworks

Extend the buildpack with your own JREs, Containers, and Frameworks

Customization is done by forking the buildpack

46Thursday, November 21, 13

Page 93: Extending Cloud Foundry with Custom Services and Buildpacks

Customization by ConfigurationConfiguration files in java-buildpack/config determine the behavior of a JRE, Container, or Framework

47

# cloudfoundry/java-buildpack/config/openjdk.yml---version: 1.7.0_+

repository_root: "http://download.pivotal.io.s3.amazonaws.com/openjdk/{platform}/{architecture}"

memory_sizes:

memory_heuristics:

  heap: 0.75

  permgen: 0.1

  stack: 0.05

  native: 0.1

# http://download.pivotal.io.s3.amazonaws.com/openjdk/lucid/x86_64/index.yml---1.6.0_27: http://download.pivotal.io.s3.amazonaws.com/openjdk/lucid/x86_64/openjdk-1.6.0_27.tar.gz1.7.0_21: http://download.pivotal.io.s3.amazonaws.com/openjdk/lucid/x86_64/openjdk-1.7.0_21.tar.gz1.7.0_25: http://download.pivotal.io.s3.amazonaws.com/openjdk/lucid/x86_64/openjdk-1.7.0_25.tar.gz1.8.0_M6: http://download.pivotal.io.s3.amazonaws.com/openjdk/lucid/x86_64/openjdk-1.8.0_M6.tar.gz1.8.0_M7: http://download.pivotal.io.s3.amazonaws.com/openjdk/lucid/x86_64/openjdk-1.8.0_M7.tar.gz

Thursday, November 21, 13

Page 94: Extending Cloud Foundry with Custom Services and Buildpacks

Customization by ConfigurationExample: customizing the Tomcat artifact for download

48

# cloudfoundry/java-buildpack/config/tomcat.yml---version: 7.0.42repository_root: "http://files.example.com/tomcat-custom"support:  version: 1.1.+  repository_root: "http://files.example.com/tomcat-buildpack-support"

# http://files.example.com/tomcat-custom/index.yml---7.0.40: http://files.example.com/tomcat-custom/tomcat-7.0.40.tar.gz7.0.41: http://files.example.com/tomcat-custom/tomcat-7.0.41.tar.gz7.0.42: http://files.example.com/tomcat-custom/tomcat-7.0.42.tar.gz

Thursday, November 21, 13

Page 95: Extending Cloud Foundry with Custom Services and Buildpacks

Customization by ConfigurationTomcat container supports simple customization of context.xml and server.xml.

49

cloudfoundry/java-buildpack/resources/tomcat/confcontext.xmlserver.xml

Thursday, November 21, 13

Page 96: Extending Cloud Foundry with Custom Services and Buildpacks

Customization by ExtensionImplement a JRE, Container, or Framework support class as one Ruby file in the appropriate directory

(with additional support classes as necessary)

50

cloudfoundry/java-buildpack/lib/java_buildpack

jrecontainerframework

Thursday, November 21, 13

Page 97: Extending Cloud Foundry with Custom Services and Buildpacks

Customization by ExtensionSupport class types have similar interfaces, following the buildpack scripts naming conventions

51

# initialize the support class with platform information provided in context# context includes app_dir, lib_dir, environment, java_home, java_opts, vcap_application, vcap_servicesdef initialize(context)

# return a String or an Array<String> that uniquely identifies the container/framework/jre, or nildef detect

# download and unpack the container/framework/jre, and transform the application as necessarydef compile

# create and return the command to run the application with (containers) or add options to context[:java_opts] (frameworks)def release

Thursday, November 21, 13

Page 98: Extending Cloud Foundry with Custom Services and Buildpacks

Customization by ExtensionAdd new support class to config/components.yml

52

---containers:  - "JavaBuildpack::Container::Groovy"  - "JavaBuildpack::Container::Main"  - "JavaBuildpack::Container::SpringBootCli"  - "JavaBuildpack::Container::Tomcat"  - "JavaBuildpack::Container::Play"jres:  - "JavaBuildpack::Jre::OpenJdk"frameworks:  - "JavaBuildpack::Framework::JavaOpts"  - "JavaBuildpack::Framework::NewRelic"  - "JavaBuildpack::Framework::PlayAutoReconfiguration"  - "JavaBuildpack::Framework::PlayJpaPlugin"  - "JavaBuildpack::Framework::SpringAutoReconfiguration"

Thursday, November 21, 13

Page 99: Extending Cloud Foundry with Custom Services and Buildpacks

CustomizationMuch more information and documentation included in the GitHub repository

https://github.com/cloudfoundry/java-buildpack

53Thursday, November 21, 13

Page 100: Extending Cloud Foundry with Custom Services and Buildpacks

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Cornelia [email protected]@cdavisafc

Scott [email protected]

@scottyfred

Community Engineer, Cloud Foundry at Pivotal

Thursday, November 21, 13