I had an itch to scratch, and I wanted to get a bit more familiar with Openshift. I had used it in the past, but it was time to have another go. The app and the code are now available. Feel free to check out:
This is a simple app that takes the URL of a markdown file on GitHub, and outputs a pandoc converted PDF. I wanted to use pandoc specifically, because it produces PDF’s that were beautifully created with LaTeX. To embed a link in your upstream documentation that points to a PDF, just append the file’s URL to this app’s url, under a /pdf/ path. For example:
If you want to hear more about what I did, read on…
Start by getting a free Openshift account. You’ll also want to install the client tools. Nothing is worse than having to interact with your app via a web interface. Hackers use terminals. Lucky, the Openshift team knows this, and they’ve created a great command line tool called
rhc to make it all possible.
I started by following their instructions:
$ sudo yum install rubygem-rhc $ sudo gem update rhc
Unfortunately, this left with a problem:
$ rhc /usr/share/rubygems/rubygems/dependency.rb:298:in `to_specs': Could not find 'rhc' (>= 0) among 37 total gem(s) (Gem::LoadError) from /usr/share/rubygems/rubygems/dependency.rb:309:in `to_spec' from /usr/share/rubygems/rubygems/core_ext/kernel_gem.rb:47:in `gem' from /usr/local/bin/rhc:22:in `'
I solved this by running:
$ gem install rhc
Which makes my user
rhc to take precedence over the system one. Then run:
$ rhc setup
and the rhc client will take you through some setup steps such as uploading your public ssh key to the Openshift infrastructure. The beauty of this tool is that it will work with the Red Hat hosted infrastructure, or you can use it with your own infrastructure if you want to host your own Openshift servers. This alone means you’ll never get locked in to a third-party providers terms or pricing.
Create a new app:
To get a fresh python 3.3 app going, you can run:
$ rhc create-app <appname> python-3.3
From this point on, it’s fairly straight forward, and you can now hack your way through the app in python. To push a new version of your app into production, it’s just a git commit away:
$ git add -p && git commit -m 'Awesome new commit...' && git push && rhc tail
Creating a new app from existing code:
If you want to push a new app from an existing code base, it’s as easy as:
$ rhc create-app awesomesauce python-3.3 --from-code https://github.com/purpleidea/pdfdoc Application Options ------------------- Domain: purpleidea Cartridges: python-3.3 Source Code: https://github.com/purpleidea/pdfdoc Gear Size: default Scaling: no Creating application 'awesomesauce' ... done Waiting for your DNS name to be available ... done Cloning into 'awesomesauce'... The authenticity of host 'awesomesauce-purpleidea.rhcloud.com (203.0.113.13)' can't be established. RSA key fingerprint is 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'awesomesauce-purpleidea.rhcloud.com,203.0.113.13' (RSA) to the list of known hosts. Your application 'awesomesauce' is now available. URL: http://awesomesauce-purpleidea.rhcloud.com/ SSH to: email@example.com Git remote: ssh://firstname.lastname@example.org/~/git/awesomesauce.git/ Cloned to: /home/james/code/awesomesauce Run 'rhc show-app awesomesauce' for more details about your app.
In my case, my app also needs some binaries installed. I haven’t yet automated this process, but I think it can be done be creating a custom cartridge. Help to do this would be appreciated!
Updating your app:
In the case of an app that I already deployed with this method, updating it from the upstream source is quite easy. You just pull down and relevant commits, and then push them up to your app’s git repo:
$ git pull upstream master From https://github.com/purpleidea/pdfdoc * branch master -> FETCH_HEAD Updating 5ac5577..bdf9601 Fast-forward wsgi.py | 2 -- 1 file changed, 2 deletions(-) $ git push origin master Counting objects: 7, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 312 bytes | 0 bytes/s, done. Total 3 (delta 2), reused 0 (delta 0) remote: Stopping Python 3.3 cartridge remote: Waiting for stop to finish remote: Waiting for stop to finish remote: Building git ref 'master', commit bdf9601 remote: Activating virtenv remote: Checking for pip dependency listed in requirements.txt file.. remote: You must give at least one requirement to install (see "pip help install") remote: Running setup.py script.. remote: running develop remote: running egg_info remote: creating pdfdoc.egg-info remote: writing pdfdoc.egg-info/PKG-INFO remote: writing dependency_links to pdfdoc.egg-info/dependency_links.txt remote: writing top-level names to pdfdoc.egg-info/top_level.txt remote: writing manifest file 'pdfdoc.egg-info/SOURCES.txt' remote: reading manifest file 'pdfdoc.egg-info/SOURCES.txt' remote: writing manifest file 'pdfdoc.egg-info/SOURCES.txt' remote: running build_ext remote: Creating /var/lib/openshift/00112233445566778899aabb/app-root/runtime/dependencies/python/virtenv/venv/lib/python3.3/site-packages/pdfdoc.egg-link (link to .) remote: pdfdoc 0.0.1 is already the active version in easy-install.pth remote: remote: Installed /var/lib/openshift/00112233445566778899aabb/app-root/runtime/repo remote: Processing dependencies for pdfdoc==0.0.1 remote: Finished processing dependencies for pdfdoc==0.0.1 remote: Preparing build for deployment remote: Deployment id is 9c2ee03c remote: Activating deployment remote: Starting Python 3.3 cartridge (Apache+mod_wsgi) remote: Application directory "/" selected as DocumentRoot remote: Application "wsgi.py" selected as default WSGI entry point remote: ------------------------- remote: Git Post-Receive Result: success remote: Activation status: success remote: Deployment completed with status: success To ssh://email@example.com/~/git/awesomesauce.git/ 5ac5577..bdf9601 master -> master $
I hope this helped you getting going with Openshift. Feel free to send me patches!