
{"id":107,"date":"2014-06-15T15:00:32","date_gmt":"2014-06-15T05:00:32","guid":{"rendered":"http:\/\/mnm.at\/markus\/?p=107"},"modified":"2014-06-15T15:03:19","modified_gmt":"2014-06-15T05:03:19","slug":"building-an-openshift-cartridge","status":"publish","type":"post","link":"https:\/\/mnm.at\/markus\/2014\/06\/15\/building-an-openshift-cartridge\/","title":{"rendered":"Building an OpenShift Cartridge"},"content":{"rendered":"<h2>The Basics<\/h2>\n<p>I used the DIY cartridge before and played with it a bit. Next I wanted to create a custom cartridge. As usual for me the first attempt was more about learning about the system than about getting things to work right away. And I must say it was a bit annoying when you start with zero or little knowledge.<\/p>\n<p>A working version is here : https:\/\/bitbucket.org\/markus_ebenhoeh\/openshift-cartridge-spring-boot-jar-runner<\/p>\n<p>Learn from my mistakes:<\/p>\n<ul>\n<li>make sure that you use the right cartridge version. I followed code that was newer than the version I was running, but even then I mixed old with new conventions. E.g. I used OPENSHIFT_LOG_DIR but that does not exist yet.<\/li>\n<li>\n<p>don\u2019t git push your code, then find the manifest URL and then try to test it. Either use the <a href=\"https:\/\/www.openshift.com\/blogs\/introducing-the-openshift-cartridge-api-version-2\">card reflector<\/a> (<a href=\"http:\/\/cartreflect-claytondev.rhcloud.com\/\">usage<\/a>)  or if you already have an http server running, just serve your code directly I changed the source to a zip on my http server and ran this just before I retried with a new application rm -f cartridge-name.zip; zip -r cartridge-name.zip *; chmod a+rX -R $PWD In the end, I just mounted a shared folder and referred the source URL to that with file:\/\/\/mnt\/public-shared\/openshift-cartridge-spring-boot-jar-runner while still hosting the same folder via http for the manifest access<\/p>\n<\/li>\n<li>\n<p>to test my cartridge I added a spring-boot application jar with an embedded tomcat. Instead of taking the smallest web-app jar that I could find I took a 29MB jar and added it into the template. This is stupid on many levels, but it also meant that it took long to do the git pull and the start and the transfer.etc having a test app in the template is important for the testing of the cartridge and afterwards for the use of it, but a smaller application is what I am going for next.<\/p>\n<\/li>\n<\/ul>\n<h2>Debugging a Failing Cartridge<\/h2>\n<p>When my cartridge completely failed I had no output and nothing to go on. I was logged on to my test origin VM but the gear\/application folder would simple be deleted at the end. So all my test log output that was supposed to show me were it failed and what the environment looked like would vanish<\/p>\n<p>So while being logged on to the test VM with root I did this dodgy thing:<\/p>\n<pre><code>cd \/var\/lib\/openshift\/\n# my user\/gear\/app folder  always starts with 5 and I had no other gears set-up\nunalias cp\nwhile true; do cp -a 5* tmp\/ ;  usleep 100000; echo next  ;done\n<\/code><\/pre>\n<p>once it failed I had more information to go on with. especially the nev folders are useful<\/p>\n<p>Other problems:<\/p>\n<ul>\n<li>I would like to see a cartridge life-cycle flow. e.g. copy file, call install, call setup etc.<\/li>\n<li>when are ENV variables available? Can I refer to my own env_xyz.erb variables when defining new ones?<\/li>\n<li>I still have no idea how the repo <\/li>\n<li>there has to be a better way to test this then to do an add-app with the updated cartridge.<\/li>\n<li>I could not find any debug output when my cartridge completely failed<\/li>\n<li>CDK is not working on Origin <a href=\"https:\/\/bugzilla.redhat.com\/show_bug.cgi?id=1017776\">bug<\/a><\/li>\n<\/ul>\n<h2>OpenShift Cartridge Development Kit<\/h2>\n<p>ran this against OpenShift Online since CDK is not working on Origin <a href=\"https:\/\/bugzilla.redhat.com\/show_bug.cgi?id=1017776\">bug<\/a>. not sure what the point is, though. I think it is about being able to have a simple way of hosting the cartridge for a certain version<\/p>\n<pre><code>rhc create-app mycart http:\/\/cdk-claytondev.rhcloud.com\nThe cartridge 'http:\/\/cdk-claytondev.rhcloud.com' will be downloaded and installed\n\nApplication Options\n-------------------\nDomain:     testcdk\nCartridges: http:\/\/cdk-claytondev.rhcloud.com\nGear Size:  default\nScaling:    no\n\nCreating application 'mycart' ... done\n\nThe CDK is configured with password XXXXXXXXXXXXXXX for builds (use 'admin' as the user)\n\nWaiting for your DNS name to be available ... done\n\nCloning into 'mycart'...\nThe authenticity of host 'mycart-testcdk.rhcloud.com (54.204.113.11)' can't be established.\nRSA key fingerprint is cf:ee:77:cb:0e:fc:02:d7:72:7e:ae:80:c0:90:88:a7.\nAre you sure you want to continue connecting (yes\/no)? yes\nWarning: Permanently added 'mycart-testcdk.rhcloud.com,54.204.113.11' (RSA) to the list of known hosts.\nX11 forwarding request failed on channel 0\n\nYour application 'mycart' is now available.\n\nURL:        http:\/\/mycart-testcdk.rhcloud.com\/\nSSH to:     539@mycart-testcdk.rhcloud.com\nGit remote: ssh:\/\/539@mycart-testcdk.rhcloud.com\/~\/git\/mycart.git\/\nCloned to:  \/xdata\/local\/dev\/markus\/git\/cdk\/mycart\n\nRun 'rhc show-app mycart' for more details about your app.\n<\/code><\/pre>\n<h2>Lifeccyle Notes<\/h2>\n<h3>first installation<\/h3>\n<pre><code>20140609_034324 setup called with --version 1.0.2 \n20140609_034324 install called with --version 1.0.2 \n20140609_034324 control called with start \n20140609_034324 start_app called \n20140609_034324 Starting spring-boot-bin-jar-runner cartridge \n20140609_034324 start_app: Using jarfile=\/var\/lib\/openshift\/539\/spring-boot-jar-runner\/web-app-jar\/simple-executable-jar-web-server-0.0.1.jar \n20140609_034324 control : checkSpringBootAppIsRunning still checking \n20140609_034325 control start successfully started the application \n<\/code><\/pre>\n<h3>git push new app code<\/h3>\n<pre><code>20140609_034411 control called with stop \n20140609_034411 stop_app called \n20140609_034411 Stopping spring-boot-bin-jar-runner cartridge \n20140609_034411 Sending SIGTERM to java:4556 ... \n20140609_034411 control called with pre-repo-archive \n20140609_034412 control called with update-configuration \n20140609_034412 control called with pre-build \n20140609_034412 control called with build \n20140609_034412 build called with \n20140609_034412 control called with update-configuration \n20140609_034412 control called with deploy \n20140609_034412 deploy called with \n20140609_034412 control called with start \n20140609_034412 start_app called \n20140609_034412 Starting spring-boot-bin-jar-runner cartridge \n20140609_034412 start_app: Using jarfile=\/var\/lib\/openshift\/539\/spring-boot-jar-runner\/web-app-jar\/simple-executable-jar-web-server-0.0.1.jar \n20140609_034412 control : checkSpringBootAppIsRunning still checking \n20140609_034412 control start successfully started the application \n20140609_034432 control called with post-deploy \n<\/code><\/pre>\n<p>There is considerable time spent between &#8220;start&#8221; and &#8220;post-deploy&#8221; not sure what&#8217;s happening there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Getting a feel for OpenShift cartridges. <a href=\"https:\/\/mnm.at\/markus\/2014\/06\/15\/building-an-openshift-cartridge\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[17,18,19,16],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-tech","tag-java","tag-openshift","tag-openshift-cartridge","tag-paas"],"_links":{"self":[{"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/comments?post=107"}],"version-history":[{"count":5,"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/posts\/107\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/media?parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/categories?post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mnm.at\/markus\/wp-json\/wp\/v2\/tags?post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}