php buildpacks in the cloud on bluemix

44
‹#› Cloud Foundry for PHP developers Deploy apps built with the leading open source language to the leading open source Platform-as-a-Service Daniel Krook Senior Certified IT Specialist, IBM @DanielKrook

Upload: ibm-bluemix

Post on 10-Jun-2015

1.111 views

Category:

Technology


0 download

DESCRIPTION

Interested in Buildpacks available on Bluemix in the IBM Cloud? Check out the deck by Daniel Krook and follow him @DanielKrook.

TRANSCRIPT

Page 1: PHP Buildpacks in the Cloud on Bluemix

‹#›

Cloud Foundry for PHP developers!Deploy apps built with the leading open source language to the leading open source Platform-as-a-Service

Daniel Krook!Senior Certified IT Specialist, IBM"@DanielKrook

Page 2: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101!!§  Introducing Cloud Foundry!!§  Demo: Simple PHP app push and MySQL bind!

§  Services in Cloud Foundry!

§  Buildpacks in Cloud Foundry!

§  Demo: Scaling and zero downtime deploys!

§  Considerations for designing PHP apps for the cloud!

§  Demo: Cross-origin resource sharing in microservices!

§  Where to go from here!!

github.com/krook !slideshare.net/danielkrook !

Page 3: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices

§  Where to go from here !

API economy!

Cloud operating environment!

Software defined environments!

Page 4: PHP Buildpacks in the Cloud on Bluemix

Standardization; lower costs; faster time to value!

Networking!

Storage!

Servers!

Virtualization!

O/S!

Middleware!

Runtime!

Data!

Applications!

Traditional !on premise!

Networking!

Storage!

Servers!

Virtualization!

O/S!

Middleware!

Runtime!

Data!

Applications!

Networking!

Storage!

Servers!

Virtualization!

O/S!

Middleware!

Runtime!

Data!

Applications!

Networking!

Storage!

Servers!

Virtualization!

Middleware!

Runtime!

Data!

Applications!

O/S!

Vendor manages in cloud!Client manages!

API economy!Cloud operating environment!Software defined environments!

Infrastructure! Platform! Software!

Sys admin (Ops)! App builder (Dev)! Business user (Biz)!

Page 5: PHP Buildpacks in the Cloud on Bluemix

IaaS: the software defined data center

Networking!

Storage!

Servers!

Virtualization!

Middleware!

Runtime!

Data!

Applications!

O/S!

Software defined environments!

Infrastructure!

Ops!

Page 6: PHP Buildpacks in the Cloud on Bluemix

PaaS: the cloud operating environment

Networking!

Storage!

Servers!

Virtualization!

O/S!

Middleware!

Runtime!

Data!

Applications!

Cloud operating environment!

Platform!

Dev!

Page 7: PHP Buildpacks in the Cloud on Bluemix

SaaS: the API economy

Networking!

Storage!

Servers!

Virtualization!

O/S!

Middleware!

Runtime!

Data!

Applications!

API economy!

Software!

Biz!

OAuth  

Page 8: PHP Buildpacks in the Cloud on Bluemix

The key benefits of Platform-as-a-Service for developers

And the key disadvantages

§  There's no need to focus on provisioning, managing, or monitoring the compute, storage, network and software §  Developers can create working prototypes in a matter of minutes.

§  Developers can create new versions or deploy new code more rapidly

§  Developers can self-assemble services to create integrated applications.

§  Developers can scale applications more elastically by starting more instances.

§  Developers don’t have to worry about underlying operating system and middleware security patches.

§  Developers can mitigate backup and recovery strategies, assuming the PaaS takes care of this.

§  Applications require a different architecture mindset §  This requires developer skill and awareness of best practices and web app limitations.

§  Don’t have as much control over the underlying infrastructure. Security, versioning, performance considerations.

Page 9: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices §  Where to go from here !

Page 10: PHP Buildpacks in the Cloud on Bluemix

Cloud Foundry is the industry’s Open PaaS and provides a choice of clouds, frameworks and application services. Its unique vision is to foster contributions from a broad community of developers, users, customers, partners and ISVs while advancing development of the platform at extreme velocity.

cloudfoundry.org  

Page 11: PHP Buildpacks in the Cloud on Bluemix

Frameworks and services lend Cloud Foundry its extensibility Buildpacks (implement frameworks for apps) detect compile release package

The detect script is used to determine whether or not to apply the buildpack to an application.

The compile script builds the droplet that will be run by the DEA and will therefore contain all the components necessary to run the application.

The release script provides feedback metadata back to Cloud Foundry indicating how the application should be executed.

The package script provides artifacts, which are provided to Cloud Foundry as system buildpacks. package is intended to provide a way for developers to package a buildpack with its dependencies.

Brokered services (implement an API to provide services) fetch provision bind

Page 12: PHP Buildpacks in the Cloud on Bluemix

Cloud Foundry is built on a highly scalable distributed architecture

Routes incoming traffic to the appropriate component; generally the Cloud Controller or application

Identity management service for the platform. Acts as an OAuth2 and SCIM provider.

Monitors the state of applications and ensures that the correct number of instances are running

Exposes a REST API to the system. Manages a database of apps, services, service instances, etc

End user provided code that is “pushed” to the cloud and packaged to run in warden container

Advertises service offerings to the Cloud Controller and handles requests to create, bind, unbind, and delete service instances.

Managed by the service gateway, these nodes host service instances. A broker that can expose a service instance to a service managed outside of the cloud

A collection of code that is responsible for transforming pushed app artifacts into a ready to run droplet

A pub-sub message bus implemented with NATS that’s used for cross component communication

Droplet Execution Agent – Advertises capacity to execute droplets created by a build pack

A distributed deployment install and management tool that abstracts the details of the IaaS layer

Page 13: PHP Buildpacks in the Cloud on Bluemix

Components collaborate via messaging and REST APIs

Page 14: PHP Buildpacks in the Cloud on Bluemix

BOSH deploys and manages Cloud Foundry clusters on an IaaS

Deployment Manifest •  Release name/version •  # VMs, Job params •  Stemcells to use

Stemcell •  Base OS •  BOSH Agent

Release •  Name

Jobs •  Software Packages •  Config Templates •  Scripts

Deployed Environment

irtual Machine •  Configuration •  Software Packages

Virtual Machine •  Configuration •  Software Packages

Virtual Machine •  Configuration •  Software Packages

Virtual Machine •  Configuration •  Software Packages

Stemcells In a cloud platform, VMs are usually cloned from a template. A stemcell is a VM template containing a standard Ubuntu distribution. A BOSH agent is also embedded in the template so that BOSH can take control of VMs cloned from the stemcell.

Jobs A job is a collection of software which serves a particular purpose (e.g. MySQL or the Cloud Controller). At deployment time, each job will be install on its own stemcell VM.

Releases A release contains a number of jobs which can be deployed into the target environment. A deployment can consist of more than one release and not every job in a release must be deployed.

Page 15: PHP Buildpacks in the Cloud on Bluemix

The BOSH Cloud Provider Interface (CPI) manages the IaaS resources that Cloud Foundry needs

Stemcells create_stemcell(image, cloud_properties) delete_stemcell(stemcell)

Virtual Machines

create_vm(agent_id, stemcell, resource_pool, networks, disk_locality, env) delete_vm(vm) reboot_vm(vm) configure_networks(vm, networks)

Disks

create_disk(size, vm_locality) delete_disk(disk) attach_disk(vm, disk) detach_disk(vm, disk)

Page 16: PHP Buildpacks in the Cloud on Bluemix

Cloud Foundry distributions

Hosted public §  IBM Bluemix

http://bluemix.net

§  Pivotal WS http://run.pivotal.io

Self hosting §  “Try Cloud Foundry” on AWS

https://trycf.starkandwayne.com

§  BOSH bootstrap https://github.com/cloudfoundry-community/bosh-bootstrap

§  Deploy your own to AWS http://www.slideshare.net/SpringCentral/build-yourowncf http://docs.cloudfoundry.org/deploying/ec2/

§  Install on on a laptop https://github.com/cloudfoundry/bosh-lite https://github.com/yudai/cf_nise_installer

§  Stackato Micro Cloud

http://www.activestate.com/stackato/get_stackato

Private §  Pivotal CF

http://run.pivotal.io

Page 17: PHP Buildpacks in the Cloud on Bluemix

The Cloud Foundry Foundation

Page 18: PHP Buildpacks in the Cloud on Bluemix

Cloud Foundry versus other Platforms-as-a-Service

http://paasify.it

http://bit.ly/pivotal-paas-compare !http://bit.ly/altoros-paas-compare !

Page 19: PHP Buildpacks in the Cloud on Bluemix

What about Docker?

There are several projects underway to leverage Docker to host the Cloud Foundry PaaS, as well as the applications that run on it.

Page 20: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices

§  Where to go from here !

$ cf push my-php-app

Page 21: PHP Buildpacks in the Cloud on Bluemix

Demo 1: PHP app push and debug §  Download the Cloud Foundry CLI, log in and target your cloud

§  Clone meetup-cf-php-1 from https://github.com/krook/meetup-cf-php-1.git §  Create index.php with syntax error

§  cf push meetup-cf-php-1 -m 128M -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git

§  Load page in browser: http://meetup-cf-php-1.mybluemix.net

§  cf logs meetup-cf-php-1 --recent

§  Fix syntax error in index.php!

§  cf push meetup-cf-php-1

§  Load page in browser: http://meetup-cf-php-1.mybluemix.net

!

Page 22: PHP Buildpacks in the Cloud on Bluemix

Demo 2: PHP app push and bind to MySQL §  Clone meetup-cf-php-2 from https://github.com/krook/meetup-cf-php-2.git

§  cf push (uses the manifest.yml settings)

§  Load page in browser: http://meetup-cf-php-2.mybluemix.net

§  cf marketplace (view the services catalog)

§  cf create-service mysql 100 meetup-cf-mysql (provision a MySQL service)

§  cf services (view my service instances)

§  cf bind-service meetup-cf-php-2 meetup-cf-mysql (bind the MySQL instance to my PHP app)

§  cf restage meetup-cf-php-2 (make the service available in my VCAP_SERVICES env variable)

§  Load page in browser: http://meetup-cf-php-2.mybluemix.net

!

Page 23: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices

§  Where to go from here ! $ cf bind-service my-php-app mysql-srv

Page 24: PHP Buildpacks in the Cloud on Bluemix

Cloud Foundry provides several community services

Page 25: PHP Buildpacks in the Cloud on Bluemix

More services can be added with the Cloud Foundry service broker API

Page 26: PHP Buildpacks in the Cloud on Bluemix

Cloud Foundry provides the framework to bind services to your apps

Page 27: PHP Buildpacks in the Cloud on Bluemix

Sample service catalog from Cloud Foundry hosted providers

IBM Bluemix (bluemix.net)! Pivotal WS (run.pivotal.io)!

In addition to a catalog of data, queue, mail, log, push services, providers may offer auto-scaling and DevOps integration

Page 28: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices

§  Where to go from here ! $ cf push my-php-app –b git://…my-bp.git

Page 29: PHP Buildpacks in the Cloud on Bluemix

The Cloud Foundry Heroku buildpack model Buildpacks implement execution environments for apps. They can be either a raw language (Java), or with frameworks (Spring, servlet, standalone). When pushed, the entire application is encapsulated into a “droplet” and is run in an isolated Linux container on the pool of “droplet execution agents.”

bin/detect The detect script is used to determine whether or not to apply the buildpack to an application.

bin/compile The compile script builds the droplet that will be run by the DEA and will therefore contain all the components necessary to run the application.

bin/release The release script provides feedback metadata back to Cloud Foundry indicating how the application should be executed.

bin/package The package script provides artifacts, which are provided to Cloud Foundry as system buildpacks. package is intended to provide a way for developers to package a buildpack with its dependencies.

Scripts can be written in a variety of languages (bash, Python, Ruby, etc.)

Page 30: PHP Buildpacks in the Cloud on Bluemix

Comparing the popular PHP buildpacks Source PHP version

(default) Web server

(default) Extensions

(default) Memory

(minimum) Notes

Pivotal (Dan Mikusa)

5.4

(Latest 5.5 and 5.6 also

supported)

Apache

(nginx and standalone apps also supported)

Minimal set to start, lots of extensions

supported and can be specified.

96 MB

•  Created from the ground up for Cloud Foundry, no Heroku legacy code

•  Supports offline mode •  Supports Composer, but doesn’t require it •  Very configurable (options.json). •  Very actively improved and kept up to date. •  Optimized to download as little as possible •  Supports a wider variety of Ubuntu stem cells •  Supports latest stable PHP 5.4, 5.5, 5.6 •  Known to work with popular frameworks, such as

CodeIgniter and Phalcon •  Lots of samples •  Supports other running processes •  Apache 2 license

Heroku (David Zuelke) 5.5

Apache

(nginx also supported)

Minimal 128 MB

•  Forked from Heroku, still compatible with Heroku •  Supports offline mode •  Requires you use Composer (or fake it) for dependencies •  MIT license •  Known to work with popular projects like WordPress •  Will be built in to future versions of Cloud Foundry

Zend

5.4

(Long term support through Zend Server 7)

Apache All the same

available in Zend Server 7

512 MB

•  Supported by Zend. •  Provides the whole familiar Zend Server GUI. •  Provides a consistent experience between CF and other

cloud delivery models (IaaS, patterns) •  Provides Zend value add: Z-Ray, monitoring, performance,

audit trail, job queue •  Requires MySQL

Page 31: PHP Buildpacks in the Cloud on Bluemix

Pushing an app with a specific buildpack

§  Pivotal §  cf push my-php-app -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git

§  Heroku §  cf push my-php-app -b https://github.com/cloudfoundry/php-buildpack.git

§  Zend §  cf push my-php-app -b https://github.com/zendtech/zend-server-php-buildpack-bluemix.git

§  All support configuration options, but you can also fork one of these and make your own!

Page 32: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices

§  Where to go from here !

$ cf scale my-php-app –i 300

Page 33: PHP Buildpacks in the Cloud on Bluemix

Demo 3: Scaling your PHP app up and down §  cf scale meetup-cf-php-1 -i 3 (scale our app up to 3 instances)

§  cf app meetup-cf-php-1 (view the status of the new instances)

§  Load page in browser: http://meetup-cf-php-1.mybluemix.net

§  Reload several times and watch the hostname change (three will alternate)

§  cf scale meetup-cf-php-1 -i 2 (scale our app down to 2 instances)

§  cf app meetup-cf-php-1 (view the status of the new instances)

!

Page 34: PHP Buildpacks in the Cloud on Bluemix

Demo 4: Zero downtime deploys §  Clone meetup-cf-php-3 from https://github.com/krook/meetup-cf-php-3.git

§  cf push meetup-cf-php-blue

§  Load page in browser: http://meetup-cf-php-blue.mybluemix.net  

§  cf apps (view the status of the one blue Version 1 instance)

§  cf rename meetup-cf-php-blue meetup-cf-php-green

§  cf apps (view the status of the one renamed green Version 1 instance)

§  Update code to Version 2

§  cf push

§  cf apps (view the status of the blue instance (V2) and green instance (V1) mapped to same domain)

§  Reload page in browser several times to see the alternating versions: http://meetup-cf-php-blue.mybluemix.net    §  cf delete meetup-cf-php-green –f (delete the old green (v1) instance, routing all traffic to blue (V2))  

§  Reload page in browser several times to see the new version only: http://meetup-cf-php-blue.mybluemix.net  

!

Page 35: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices

§  Where to go from here !

Page 36: PHP Buildpacks in the Cloud on Bluemix

Best practices for microservices architectures

12factor.net!

The 12 factor app is a methodology for building apps that: •  Use declarative formats for setup automation, to minimize time and cost for new

developers joining the project;�

•  Have a clean contract with the underlying operating system, offering maximum portability between execution environments;

•  Are suitable for deployment on modern cloud platforms, obviating the need for servers and systems administration;

•  Minimize divergence between development and production, enabling continuous deployment for maximum agility;

•  And can scale up without significant changes to tooling, architecture, or development practices.

The 12 factor methodology can be applied to apps written in any programming language, and which use any combination of backing services (database, queue, memory cache, etc).

Page 37: PHP Buildpacks in the Cloud on Bluemix

Designing apps for the cloud: PaaS best practices Following these guidelines makes an application cloud-friendly, and facilitates deployment to Cloud Foundry and other cloud platforms.

§  Avoid writing to the local filesystem §  Local file system storage is short-lived

Your application can write local files while it is running, the files will disappear after the application restarts.

§  Instances of the same application do not share a local file systemEach application instance runs in its own isolated container. Thus a file written by one instance is not visible to other instances of the same application.

§  HTTP sessions are not persisted or replicatedSession data that must be available after an application crashes or stops, or that needs to be shared by all instances of an application, should be stored in a Cloud Foundry service.

§  Run multiple instances to increase availabilityTo avoid the risk of an application being unavailable during Cloud Foundry upgrade processes, you should run more than one instance of an application.

§  Design as if your application can be restarted, destroyed, started at any time!

http://bit.ly/cf-paas-bp !

Page 38: PHP Buildpacks in the Cloud on Bluemix

Pitfall: cross-origin resource sharing (CORS) As you break monolithic apps into discrete services that are aggregated by a JavaScript front-end, you’ll likely run into an issue with the sandbox environment of the browser. Standard HTTP headers provide a way to overcome this limitation (http://bit.ly/cf-cors).

http://js-front-end.example.com

http://service-1.example.com

http://www.example.com/service-1 http://www.example.com/service-2 http://www.example.com/service-3

http://service-2.example.com http://service-3.example.com

Page 39: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices

§  Where to go from here !

Page 40: PHP Buildpacks in the Cloud on Bluemix

Demo 5: Breaking a monolithic app into microservices

§  http://krook-service-consumer.mybluemix.net

§  http://krook-service-provider.mybluemix.net/non-cors-provider!

§  http://krook-service-provider.mybluemix.net/cors-provider!

!

Page 41: PHP Buildpacks in the Cloud on Bluemix

More complex PHP apps on Cloud Foundry

.

§  WordPress §  http://bit.ly/cf-wp-zend §  http://bit.ly/cf-wp-jstart

§  Symfony

§  http://bit.ly/cf-symfony

§  Laravel §  http://bit.ly/cf-laravel

§  RESTful web services §  http://bit.ly/cf-rest

§  Piwik §  http://bit.ly/cf-piwik

Page 42: PHP Buildpacks in the Cloud on Bluemix

Agenda §  Cloud 101 §  Introducing Cloud Foundry §  Demo: Simple PHP app push and MySQL bind

§  Services in Cloud Foundry

§  Buildpacks in Cloud Foundry

§  Demo: Scaling and zero downtime deploys

§  Considerations for designing PHP apps for the cloud

§  Demo: Cross-origin resource sharing in microservices

§  Where to go from here !

Page 43: PHP Buildpacks in the Cloud on Bluemix

Getting started with Cloud Foundry

Basics §  Trial accounts with hosted providers

http://bluemix.net http://run.pivotal.io

§  Cloud Foundry documentation http://docs.cloudfoundry.org

§  Cloud Foundry community http://cloudfoundry.org

§  Cloud Foundry on GitHub https://github.com/cloudfoundry

Advanced §  “Try Cloud Foundry” on AWS

https://trycf.starkandwayne.com

§  BOSH bootstrap https://github.com/cloudfoundry-community/bosh-bootstrap

§  Deploy your own to AWS http://www.slideshare.net/SpringCentral/build-yourowncf http://docs.cloudfoundry.org/deploying/ec2/

§  Install on on a laptop https://github.com/cloudfoundry/bosh-lite https://github.com/yudai/cf_nise_installer

§  Stackato Micro Cloud

http://www.activestate.com/stackato/get_stackato

Page 44: PHP Buildpacks in the Cloud on Bluemix

‹#›

Cloud Foundry for PHP developers!Deploy apps built with the leading open source language to the leading open source Platform-as-a-Service

Daniel Krook!Senior Certified IT Specialist, IBM"@danielkrook