Deploying an App with S2I

Adding total consistency to your build process and environment

View source on GitHub

Source to Image (S2I)

One of the useful components of OpenShift is its source-to-image capability. S2I is a framework that makes it easy to turn your source code into runnable images. The main advantage of using S2I for building reproducible Docker images is the ease of use for developers. You’ll see just how simple it can be in this lab.

Let’s build a node.js web server using S2I

We can do this either via the command line (CLI) or the web console. You decide which you’d rather do and follow the steps below:

Goto the terminal and type the following (be sure to substitute in the correct base for the Git server URL):
$ oc new-app --name=webapp http://{LOCAL GIT SERVER URL}/openshiftexamples-nodemongo.git#offline
$ oc expose service webapp
OpenShift auotmatically detected the source code type and selected the nodejs builder image
Click "Add to Project"

Click "Browse Catalog" and filter for nodejs, then click the nodejs:0.10 builder image

Fill out the boxes to look as follows:

Notes: You will need to click to expand the "advanced options"
Give it the name: webapp The github repository URL is: http://openshift.example.com:3000/demo/openshiftexamples-nodemongo.git
The Git Reference needs to be set to: offline

Scroll to the bottom and click "Create"
OpenShift will display a next steps page with details about what happened and what you can do next. Read that, then:
Click "Go to overview"

Check out the build details

We can see the details of what the S2I builder did. This can be helpful to diagnose issues if builds are failing.

TIP: For a node.js app, running “npm shrinkwrap” is a good practice to perform on your branch before releasing changes that you plan to build/deploy as an image with S2I

Goto the terminal and type the following:
$ oc get builds
In the output, note the name of your build and use it to see the logs with:
$ oc logs builds/[BUILD_NAME]
The console will print out the full log for your build. Note, you could pipe this to more or less for easier viewing in the CLI.
Hover over "Builds" and then click on "Builds"

Click on the "webapp" link

Click on the "View Log" tab to see the details of your latest build
You should see a log output similar to the one below:

See the app in action

Let’s see this app in action!

Goto the terminal and type the following:
$ oc get routes
Copy the HOST/PORT and paste into your favorite web browser
Click on Overview

Click the URL that is listed in the header

The app should look like this in your web browser:

We haven’t added a database yet, so the app will display a warning about that, don’t worry, we will set that up in the next lab.

Summary

In this lab we deployed a sample application using source to image. This process built our code and wrapped that in a Docker image. It then deployed the image into our OpenShift platform in a pod and exposed a route to allow outside web traffic to access our application. In the next lab we will look at some details of this app’s deployment and make some changes to see how OpenShift can help to automate our development processes.