Writing Cartridges for OpenShiftJhon HoncePr Software Engineer, Red Hat IncOpenShift Origin Community Day (Boston)June 13,...
The OpenShift Ecosystem: GUI/CLI, Broker, NodeGUIrhc (CLI)BrokerNode(Cartridges)REST APIssh|git MCollectivesnapshot.tgzgit...
Where does my code fit?● Application – application developer● Gears – PaaS developer● Cartridges – Cartridge authors● Web ...
The Cartridge API● Low overhead● Named executable files● stdout/stderr● Environment variables● Configuration files:manifes...
Minimal Cartridge – identify cartridge+- bin| +- setup| +- control+- env+- metadata| +- manifest.yml● Assumes packaged sof...
Minimal Cartridge – required files+- bin| +- setup| +- control+- env+- metadata| +- manifest.yml● Assumes packaged softwar...
Minimal Cartridge+- bin| +- setup| +- control+- env+- metadata| +- manifest.yml● Assumes packaged softwarealready installe...
My Cartridge needs to be seen!+- bin| +- …| +- control+…● control Arguments● start● stop● manifest.yml.:Endpoints:- Privat...
My Cartridge needs to be invoked+- bin| +- …| +- control+…● Basic control arguments● start● stop● manifest.yml.:Endpoints:...
My Cartridge needs to be seen!+- bin| +- …| +- control+…● Basic control arguments● start● stop● manifest.yml.:Endpoints:- ...
Tip: control script can be trivial.:case “$1” instart)/usr/sbin/httpd -C "Include $OPENSHIFT_DOG_CONF_DIR/*.conf" -f $HTTP...
My Cartridge needs help, a database cartridge+- hooks| +- …| +- publish-db-connection-info+…● manifest.yml.:Publishes:publ...
My Cartridge needs help, a database cartridge!● manifest.yml.:Publishes:publish-db-connection-info:Type: "ENV:NET_TCP:db:c...
My Cartridge needs needs to be listening● Pub/Sub Protocol● The Type: element determines both the message format andwhethe...
Let the Platform the cartridge can use a database● Pub/Sub Protocol● The Type: element determines both the message format ...
Let the Platform the cartridge can use a database● Pub/Sub Protocol● The Type: element determines both the message format ...
My Cartridge needs to be listening for databases● Pub/Sub Protocol● The Type: element determines both the message format a...
My Cartridge needs to be listening for databases● Pub/Sub Protocol● The Type: element determines both the message format a...
Customize Work Flows● Cartridge Authors● Implement additional control actions● Provide optional scrips● Application Develo...
For Language Frameworks: A sample application● template directory● Checked in as the gears initial git repository● A “comp...
Environment VariablesThe Node/Application/Gear/Cartridge all have sharedenvironment variables in their scope● Node Scope v...
Example Platform Environment Variables● OPENSHIFT_APP_NAME● OPENSHIFT_APP_DNS● OPENSHIFT_DATA_DIR● OPENSHIFT_HOMEDIR● OPEN...
Creating An Application With Your Cartridge● rhc create-app dog001 http://…/metadata/manifest.yml● Tip: use raw URL from g...
Tip: Origin VM as a development platform● http://openshift.github.io/● Broker-Node communication● /var/log/mcollective.log...
Tip: Examples – Online Cartridges● http://tinyurl.com/online-cartridges● JBoss EWS: multiple versions of packaged software...
Tip: Using bash for scripts● -e and -u options are your friends● -e exit on error● -u using unset variable is an error● -x...
ERB File Rendering● Unified method of doing value substitutions inconfiguration files● httpd.conf, php.ini, etc● metadata/...
Title hereText with no bullets● Bullets layer one● Bullets layer two● Bullets layer three
Additional Resources!● Cartridge Writing Guide:http://tinyurl.com/writing-cartridges● IRC Freenode● #openshift (applicatio...
For more information:http://openshift.github.ioFollow us on twitter:@openshiftJoin us on irc (freenode):openshift
Upcoming SlideShare
Loading in …5
×

OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce

598 views
531 views

Published on

Presenters: Jhon Honce

Cartridges allow developers to provide services running on top of the Red Hat OpenShift Platform-as-a-Service (PaaS). OpenShift already provides cartridges for numerous web application frameworks and databases. Writing your own cartridges allows you to customize or enhance an existing service, or provide new services. In this session, the presenter will discuss best practices for cartridge development and the latest changes in the OpenShift cartridge support.

* Latest changes made in the platform to ease cartridge development
* OpenShift Cartridges vs. plugins
* Outline for development of a new cartridge
* Customization of existing cartridges
* Quickstarts: leveraging a cartridge or cartridges to provide a complete application

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
598
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce

  1. 1. Writing Cartridges for OpenShiftJhon HoncePr Software Engineer, Red Hat IncOpenShift Origin Community Day (Boston)June 13, 2013http://openshift.github.io
  2. 2. The OpenShift Ecosystem: GUI/CLI, Broker, NodeGUIrhc (CLI)BrokerNode(Cartridges)REST APIssh|git MCollectivesnapshot.tgzgitrepository
  3. 3. Where does my code fit?● Application – application developer● Gears – PaaS developer● Cartridges – Cartridge authors● Web Frameworks, Databases, Daemons● Encapsulates some piece software for use withinthe PaaS
  4. 4. The Cartridge API● Low overhead● Named executable files● stdout/stderr● Environment variables● Configuration files:manifest.yml, managed_files.yml● You can use any language● source $OPENSHIFT_CARTRIDGE_SDK_BASH● The software you are packaging must either be on thesystem or included in your cartridge
  5. 5. Minimal Cartridge – identify cartridge+- bin| +- setup| +- control+- env+- metadata| +- manifest.yml● Assumes packaged softwarealready installed on system● Most cartridges will havemore files● manifest.ymlName: dogCartridge-Short-Name: DOG.:Version: ‘1.0’Cartridge-Version: 0.0.1Cartridge-Vendor: honce
  6. 6. Minimal Cartridge – required files+- bin| +- setup| +- control+- env+- metadata| +- manifest.yml● Assumes packaged softwarealready installed on system● Most cartridges will havemore files● manifest.ymlName: dogCartridge-Short-Name: DOG.:Version: ‘1.0’Cartridge-Version: 0.0.1Cartridge-Vendor: honce
  7. 7. Minimal Cartridge+- bin| +- setup| +- control+- env+- metadata| +- manifest.yml● Assumes packaged softwarealready installed on system● Most cartridges will havemore files● manifest.ymlName: dogCartridge-Short-Name: DOG.:Version: ‘1.0’Cartridge-Version: 0.0.1Cartridge-Vendor: honce
  8. 8. My Cartridge needs to be seen!+- bin| +- …| +- control+…● control Arguments● start● stop● manifest.yml.:Endpoints:- Private-IP-Name: IPPrivate-Port-Name: PORTPrivate-Port: 8080Public-Port-Name: PROXY_PORTMappings:- Frontend: ""Backend: ""● Environment VariablesOPENSHIFT_<SHORT_NAME>_IPOPENSHIFT_<SHORT_NAME>_PORTOPENSHIFT_…_PROXY_PORT
  9. 9. My Cartridge needs to be invoked+- bin| +- …| +- control+…● Basic control arguments● start● stop● manifest.yml.:Endpoints:- Private-IP-Name: IPPrivate-Port-Name: PORTPrivate-Port: 8080Public-Port-Name: PROXY_PORTMappings:- Frontend: ""Backend: ""
  10. 10. My Cartridge needs to be seen!+- bin| +- …| +- control+…● Basic control arguments● start● stop● manifest.yml.:Endpoints:- Private-IP-Name: IPPrivate-Port-Name: PORTPrivate-Port: 8080Public-Port-Name: PROXY_PORTMappings:- Frontend: ""Backend: ""
  11. 11. Tip: control script can be trivial.:case “$1” instart)/usr/sbin/httpd -C "Include $OPENSHIFT_DOG_CONF_DIR/*.conf" -f $HTTPD_CFG_FILE -k start ;;stop)… -k stop ;;restart)… -k restart ;;esac
  12. 12. My Cartridge needs help, a database cartridge+- hooks| +- …| +- publish-db-connection-info+…● manifest.yml.:Publishes:publish-db-connection-info:Type: "ENV:NET_TCP:db:connection-info"● Pub/Sub Protocol● publish-db-connection-info is a scriptecho OPENSHIFT_MYSQL_DB_HOST=$OPENSHIFT_GEAR_DNSecho OPENSHIFT_MYSQL_DB_PORT=$OPENSHIFT_MYSQL_DB_PROXY_PORTecho OPENSHIFT_MYSQL_DB_URL=”mysql://…/”
  13. 13. My Cartridge needs help, a database cartridge!● manifest.yml.:Publishes:publish-db-connection-info:Type: "ENV:NET_TCP:db:connection-info"● Publish/Subscribe Protocol● publish-db-connection-info is a scriptecho OPENSHIFT_MYSQL_DB_HOST=$OPENSHIFT_GEAR_DNSecho OPENSHIFT_MYSQL_DB_PORT=$OPENSHIFT_MYSQL_DB_PROXY_PORTecho OPENSHIFT_MYSQL_DB_URL=”mysql://…/”
  14. 14. My Cartridge needs needs to be listening● Pub/Sub Protocol● The Type: element determines both the message format andwhether the subscribe hook may be implemented in thePlatform● A provided hook script will be run in place of Platform code● manifest.yml.:Subscribes:set-db-connection-info:Type: “ENV:NET_TCP:db:connection-info”Required: false
  15. 15. Let the Platform the cartridge can use a database● Pub/Sub Protocol● The Type: element determines both the message format andwhether the subscribe hook may be implemented in thePlatform● A provided hook script will be run in place of Platform code● manifest.yml.:Subscribes:set-db-connection-info:Type: “ENV:NET_TCP:db:connection-info”Required: false
  16. 16. Let the Platform the cartridge can use a database● Pub/Sub Protocol● The Type: element determines both the message format andwhether the subscribe hook may be implemented in thePlatform● A provided hook script will be run in place of Platform code● manifest.yml.:Subscribes:set-db-connection-info:Type: “ENV:NET_TCP:db:connection-info”Required: false
  17. 17. My Cartridge needs to be listening for databases● Pub/Sub Protocol● The Type: element determines both the message format andwhether the subscribe hook may be implemented in thePlatform● A provided hook script will be run in place of Platform code● manifest.yml.:Subscribes:set-db-connection-info:Type: “ENV:NET_TCP:db:connection-info”Required: false
  18. 18. My Cartridge needs to be listening for databases● Pub/Sub Protocol● The Type: element determines both the message format andwhether the subscribe hook may be implemented in thePlatform● A provided hook script will be run in place of Platform code● manifest.yml.:Subscribes:set-db-connection-info:Type: “ENV:NET_TCP:db:connection-info”Required: false
  19. 19. Customize Work Flows● Cartridge Authors● Implement additional control actions● Provide optional scrips● Application Developers● .openshift/action_hooks● .openshift/markers● git pushed from developers repository
  20. 20. For Language Frameworks: A sample application● template directory● Checked in as the gears initial git repository● A “complete” application demonstrating that yourcartridge is ready for business● If you should add the manifest element:● Install-Build-Required: false● Speeds up the installation of your cartridge● You need to do work for the application developer
  21. 21. Environment VariablesThe Node/Application/Gear/Cartridge all have sharedenvironment variables in their scope● Node Scope variables● /etc/openshift/env● Gear Scope● .../<gear uuid>/.env● Application Scope● .../<gear uuid>/.env/<cartridge name>● Cartridge Scope● .../<gear uuid>/<cartridge name>/env
  22. 22. Example Platform Environment Variables● OPENSHIFT_APP_NAME● OPENSHIFT_APP_DNS● OPENSHIFT_DATA_DIR● OPENSHIFT_HOMEDIR● OPENSHIFT_TMP_DIR● OPENSHIFT_<SHORT NAME>_DIR● OPENSHIFT_<SHORT NAME>_IP● OPENSHIFT_<SHORT NAME>_PORT● You and application developer use these to tie into the software youare packaging● System tracks them and builds the correct process environment foryou
  23. 23. Creating An Application With Your Cartridge● rhc create-app dog001 http://…/metadata/manifest.yml● Tip: use raw URL from github● manifest.yml contains Source-Url element● Source-Url addresses root of your cartridge● Tip: use download zip file from github repository
  24. 24. Tip: Origin VM as a development platform● http://openshift.github.io/● Broker-Node communication● /var/log/mcollective.log● Node logging● /var/log/openshift/node/platform.log● Node detailed logging● /var/log/openshift/node/platform-trace.log● Warning: Origin – Fedora 18Online – RHEL 6
  25. 25. Tip: Examples – Online Cartridges● http://tinyurl.com/online-cartridges● JBoss EWS: multiple versions of packaged softwareand support for multiple java versions● MySQL: pub/sub database connections● PHP My Admin: one cartridge dependent on another
  26. 26. Tip: Using bash for scripts● -e and -u options are your friends● -e exit on error● -u using unset variable is an error● -x for debugging● Bash “SDK” (Library of functions)● source $OPENSHIFT_CARTRIDGE_SDK_BASH
  27. 27. ERB File Rendering● Unified method of doing value substitutions inconfiguration files● httpd.conf, php.ini, etc● metadata/managed_files.yml● processed_templates:- **/*.erb● All environment variables available● No code can be executed
  28. 28. Title hereText with no bullets● Bullets layer one● Bullets layer two● Bullets layer three
  29. 29. Additional Resources!● Cartridge Writing Guide:http://tinyurl.com/writing-cartridges● IRC Freenode● #openshift (application developers)● #openshift-dev (PaaS development)● #openshift-dev-node (cartridge/node development)● Email● dev@lists.openshift.redhat.com
  30. 30. For more information:http://openshift.github.ioFollow us on twitter:@openshiftJoin us on irc (freenode):openshift

×