extending openshift origin: build your own cartridge with bill decoste of red hat
TRANSCRIPT
OpenShift Community DayWriting CartridgesBill DeCostePrincipal Software [email protected]
Target Audience
You...
Wish to offer new user services on an OpenShift PaaS
Customize an existing user service on a PaaS
What are Cartridges?
Cartridge A technology stack or framework (PHP, Perl, Java/JEE, Ruby, Python, MySQL, etc.) definition
Plugin Auth, DNS, etc.
Gear Allocation of memory, compute, and storage resources for running applications. Live on Nodes.
Application Instantiation of a Cartridge. Overloaded term, I know.
Scaled/Scalable Application Instantiated in multiple Gears
Suggestions ...
Start with a DIY (More significant for Cart V1)Resolve many installation and configuration issues (e.g. bindings, logging)
Existing Quickstart or sample?
Start with a similar cartridgeApache based?
JEE Application Server?
Embeddable Database?
Requirements
The OpenShift Cartridge API consists of:Executable files
stdout/stderr
Environment variables
You can use any language but we find bash the fastestBash SDK provided, other languages planned
The software you are packaging either needs to be on the system or included in your cartridge
History Cartridge V1.0
Opensource, but not easy to implement or customizeOverly large number of files/scripts
Blurred Node vs Cartridge responsibility(e.g. root access required by Cartridge)
Each version required a new Cartridge
Difficult to maintainAPIs not versioned
History Cartridge V2.0
Eased implementation, customization, and maintenanceGreatly reduced number of files/scripts
Well-defined Cartridge vs Node responsibility(e.g. root access not required by Cartridge)
Well-defined and versioned API
Multiple versions supported in single Cartridge
Documentation: https://github.com/openshift/origin-server/blob/master/node/README.writing_cartridges.md
Minimal Cartridge
+- bin
| +- setup
| +- control
+- env
+- metadata
| +- manifest.yml
*Assumes packaged software already installed on system*Most cartridges will have more files
metadata/manifest.yml
ElementsName
Version
Cartridge-Version
Cartridge-Vendor
Endpoints
*Other elements for defining features of your cartridge and it's packaged software
Endpoints
Cartridges must explicitly declare which ports they will bind to, and provide meaningful variable names to describe:The IP address(es) reserved/available for binding
The Gear-local ports to which the cartridge services will bind
(Optional) Publicly proxied ports which expose Gear-local ports for use by the application's users or across application Gears
Endpoints:- Private-IP-Name: (e.g. IP => OPENSHIFT_shortname_IP) Private-Port-Name: (e.g. HTTP_PORT) Private-Port: (e.g. 8080) Public-Port-Name: (e.g. HTTP_PROXY_PORT)
Hooks (in-flux)
Cartridges may need to act when some other cartridge is added/removed from an application.
This functionality is supported using Publish/Subscribe connectors in the manifest.yml.Subscribes: set-mysql-connection-info:subscribe script Type: "NET_TCP:db:mysql"subscription keyPublishes: publish-mysql-connection-info:publish script Type: "NET_TCP:db:mysql"subscription key
bin/setup
Responsible for creating and/or configuring the files that were copied from the cartridge repository into the gear's directory.
Option --versionWhich version of the packaged software has been called for
Possible to support n versions of the software, allows reuse of like code/configuration files etc
bin/control
OpenShift calls control when it wants work from you or your packaged softwarestart cartridge and the package software (httpd)
stop cartridge and the package software (mysqld)
build The application developer pushed new code to your language cartridge for processing (maven)
deploy Code compiled but application not yet started. (Update database)
Others: threaddump, restart, reload, status
bin/teardown
Prepares the gear for the cartridge to be removed. This script will not called when the gear is destroyed.
The teardown script is only run when a cartridge is to be removed from the gear.
The gear is expected to continue to operate minus the functionality of your cartridge.
Template
Provides an minimal example of an application written in the language/framework your cartridge is packagingTypically application to web applications (e.g. homepage)
Action HooksExecutables for custom lifecycle
e.g. pre-build, post-build, pre-deploy, post-deployNOTE: Build lifecycle details available in doc
MarkersControl cartridge behavior
e.g. hot_deploy, disable_auto_scaling, force_clean_build, java7
System Environmental Variables (in-flux)
System Provided (subset)OPENSHIFT_APP_DNS the application's fully qualified domain name that your cartridge is a part ofOPENSHIFT_APP_NAME the validated user assigned name for the application. Black list is system dependent.OPENSHIFT_APP_UUID OpenShift assigned UUID for the applicationOPENSHIFT_DATA_DIR the directory where your cartridge may store dataOPENSHIFT_GEAR_DNS the gear's fully qualified domain name that your cartridge is a part of. May or may not be equal to OPENSHIFT_APP_DNSOPENSHIFT_GEAR_NAME OpenShift assigned name for the gear. May or may not be equal to OPENSHIFT_APP_NAMEOPENSHIFT_GEAR_UUID OpenShift assigned UUID for the gearOPENSHIFT_HOMEDIR OpenShift assigned directory for the gearOPENSHIFT_REPO_DIR the directory where the developer's application is "archived" to and will be run from.OPENSHIFT_TMP_DIR the directory where your cartridge may store temporary data
Cartridge Provided (examples)OPENSHIFT_MYSQL_DB_HOST OPENSHIFT_MYSQL_DB_PASSWORDOPENSHIFT_MYSQL_DB_PORTOPENSHIFT_MYSQL_DB_USERNAME
Installing a V2 Cartridge
Typically available as RPMs
Added to /usr/libexec/openshift/cartridges/v2
Install Cartridge:
oo-admin-cartridge -a install -s /usr/libexec/openshift/cartridges/v2/XXXClear Cache
From /var/www/openshift/broker, run bundle exec rake tmp:clear OR Run `script/rails console` and enter 'Rails.cache.clear',Confirmrhc cartridge list
Quickstarts/Samples
Many, many easy-to-install applications to showcase Cartridge use
https://github.com/openshift
Django, Rails, Tomcat, JEE, Mongo, Redmine, CakePHP, IronMQ, etc.
Typically follow install pattern:rhc create app cd app git remote add upstream git pull -s recursive -X theirs upstream master
Add your own!
NOTE: Quickstarts blend of v1/v2. Not all tested vs V2 yet
Thank You!
Channels
G+ Communityhttps://plus.google.com/communities/114361859072744017486
E-MailOpenShift Users: [email protected]
Origin Developers: [email protected]
IRC: irc.freenode.netOpenShift Users: #openshift
Origin Developers: #openshift-dev
Node/Cartridge Developers: #openshift-dev-node
Channels
Forumshttp://openshift.redhat.com/community/forums/openshift
Blogshttps://openshift.redhat.com/community/blogs/http://mattoncloud.org/http://www.billdecoste.nethttp://www.krishnaraman.nethttp://cloud-mechanic.blogspot.com
OpenSource
GitHub: https://github.com/openshiftOrigin: origin-server
OSE: enterprise-server
Community Cartridges: origin-community-cartridges
Quickstarts, Examples
Watch, Star, Contribute!!!
Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level
Click to edit the title text format
Click to edit the outline text format