in container

Say Hello Again to OpenShift


As part of Say Hello to OpenShift Origin, I’d like to share how to deploy an application (the ParksMap front end) from a existing container-formatted image.

OpenShift Source-2-Image (S2I)

Source-To-Image (S2I) is a standalone tool which is very useful when creating builder images.

Source-to-image (S2I) is a tool for building reproducible Docker images. S2I produces ready-to-run images by injecting source code into a Docker image and assembling a new Docker image which incorporates the builder image and built source. The result is then ready to use with docker run. S2I supports incremental builds which re-use previously downloaded dependencies, previously built artifacts, etc.

Here is 4 points you might be interested in:
1. Speed
with S2I, the assemble process can perform a large number of complex operations without creating a new layer at each step, resulting in a fast process.
2. Patchability
S2I allows you to rebuild the application consistently if an underlying image needs a patch due to a security issue.
3. User efficiency
S2I prevents developers from performing arbitrary yum install type operations during their application build, which results in slow development iteration.
4. Ecosystem
S2I encourages a shared ecosystem of images where you can leverage best practices for your applications.

More information about S2I you can find from here

Deploy Application in project helloopenshift

Choose Python-based image

Inject code nationalparks-katacoda on Python-based image

Verify that your service can show pins of national parks and status

Check Pod Status

NAME                              TYPE      FROM          STATUS     STARTED          DURATION
builds/nationalparks-katacoda-1   Source    Git@43842c2   Complete   10 minutes ago   56s

NAME                                  DOCKER REPO                                                              TAGS      UPDATED
imagestreams/nationalparks-katacoda   docker-registry.default.svc:5000/helloopenshift/nationalparks-katacoda   latest    9 minutes ago
imagestreams/parksmap-katacoda        docker-registry.default.svc:5000/helloopenshift/parksmap-katacoda        1.0.0     15 minutes ago

NAME                            HOST/PORT                                                   PATH      SERVICES                 PORT       TERMINATION   WILDCARD
routes/nationalparks-katacoda   nationalparks-katacoda-helloopenshift.apps.pichuang.local             nationalparks-katacoda   8080-tcp                 None
routes/parksmap-katacoda        parksmap-katacoda-helloopenshift.apps.pichuang.local                  parksmap-katacoda        8080-tcp                 None

NAME                                READY     STATUS      RESTARTS   AGE       IP           NODE
po/nationalparks-katacoda-1-build   0/1       Completed   0          10m   node2.pichuang.local
po/nationalparks-katacoda-1-vmzgs   1/1       Running     0          9m   node2.pichuang.local
po/parksmap-katacoda-1-llf7x        1/1       Running     0          14m   node1.pichuang.local

NAME                          DESIRED   CURRENT   READY     AGE       CONTAINERS               IMAGES                                                                                                                                           SELECTOR
rc/nationalparks-katacoda-1   1         1         1         9m        nationalparks-katacoda   docker-registry.default.svc:5000/helloopenshift/nationalparks-katacoda@sha256:b59e7827b90861efe5a683166530b5369727f7af79199d1498fc29e9a7c691b6   deployment=nationalparks-katacoda-1,deploymentconfig=nationalparks-katacoda
rc/parksmap-katacoda-1        1         1         1         14m       parksmap-katacoda        openshiftroadshow/parksmap-katacoda@sha256:adf4ce84b52e10c6e4ef8a9d71f99e9f1acaf16b89a4689c0ba84f35a1c37bf0                                      app=parksmap-katacoda,deployment=parksmap-katacoda-1,deploymentconfig=parksmap-katacoda

NAME                         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE       SELECTOR
svc/nationalparks-katacoda   ClusterIP   <none>        8080/TCP   10m       deploymentconfig=nationalparks-katacoda
svc/parksmap-katacoda        ClusterIP   <none>        8080/TCP   14m       app=parksmap-katacoda,deploymentconfig=parksmap-katacoda

Verify services is started

Deep Dive into S2I

How does s2i work?

  1. Start a container from the builder image with the application source injected into a known directory
  2. The container process transforms that source code into the appropriate runnable setup
  3. Commit the new container and set the image entrypoint to be a script (provided by the builder image)

Install S2I

tar xvf source-to-image-v1.1.10-27f0729d-linux-amd64.tar.gz
cp s2i /usr/local/bin/

Build one python application using s2i

# s2i build <source> <builder image> <new image name>
s2i build centos/python-35-centos7 hello-s2i
docker run -p 8080:8080 hello-s2i

To show building hisotry of container image

docker history hello-s2i

You can try to diff with builder image (centos/python-35-centos7). The only different is that the new image will add one layer because s2i help to inject source code into builder image. In the case, ae01019cb16a is the new layer.