I use kubernetes for application hosting in general, however I’ve recently started using OpenShift and I really enjoy its continuous delivery feature. While using kubernetes I need to build, push, version and store docker containers by myself, in OpenShift these features are supported by cluster.
I have to say that I’m a big fan of Elixir so I’ve decided to spin my application to OpenShift cluster. It seemed tricky because OpenShift doesn’t support Elixir by default, yet at the end of the day it’s not a real problem because I can add support for any programming language by myself using s2i tool. I’ve created an example that builds and deploys Elixir application to OpenShift cluster and I’d like to share it with you below.
First, I’ve started from ImageStream. Basically imageStream matches external or internal docker image to OpenShift docker internal registry. For example it allows to create imageStream Ruby with tag my_ruby_app that points to external image ruby:2.4-alpine. It’s very useful because it allows to control images versions.
I’ve created a minimal, working ImageStream example. It uses global lookupPolicy and allows OpenShift to share images between projects. ReferencePolicy has been set to Source and OpenShift cluster will try download image from ‘from’ directive as a result. ReferencePolicy may be set to Local as well and in that case it will only use integrated registry.
description: "Build and run Elixir application"
ImageStream uses base image for application build (in my case it’s a es1o/s2i-elixir:1.4.5-4 image). Image must contain executable script assemble in $PATH. This obligatory script is used for building container with application. Cluster executes run script when the container starts and the script also comes from source docker image at the same time. Run script is optional, but if it exists cluster will deploy application after the build finishes successfully.
At this point we have ImageStream with image with assemble and run scripts in place, so in the next step we can create sample application. I’ve used my side project as an example.
oc new-app myproject/elixir:1.4~https://github.com/es1o/esioci.git
The command shown above creates BuildConfig for application. A build is triggered by default when configuration or image has been changed. Such build can be also triggered by oc command or by using a webhook. The application image with the latest tag is automatically pushed to OpenShift internal registry after the build is finished.
As a result of the procedure described above we now have ImageStream and application that can be accessible with route.
Whole example is stored in github repository: https://github.com/es1o/s2i-elixir.