Node.js on OpenShift

In the Enterprise

Lance Ball

Senior Software Engineer

[email protected]

@lanceball

Enterprise

Architecture

Enterprise Architecture

Enterprise Architecture

Nahh... I'm good

Who Am I

µ-Services

Applications composed of small, independenly deployable services communicating 

over the network, usually with HTTP, transferring data/state between them, usually with JSON.

 

µ-Service Challenges

Operational Complexity

Resiliency

Recovery

Elasticity

Service & Failure

Discovery

Why OpenShift?

Red Hat

Middleware

Online

On Premise

Developer

OpenShift Building Blocks

  • Kubernetes

  • Docker

  • S2I - Source to Image

  • GitHub

OpenShift Origin

Origin is the upstream community project that powers OpenShift. Built around a core of Docker container packaging and Kubernetes container cluster management, Origin is also augmented by application lifecycle management functionality and DevOps tooling. Origin provides a complete open source container application platform.

Developer Tools

  • OpenShift Online

  • Minishift

  • Container Development Kit

  • Day to day developer environment
  • Single local cluster on your laptop
  • Download from GitHub
    • https://github.com/minishift/minishift/releases

Minishift

Brief Minishift Demo

# Start minishift
# Lots of output while minishift
# downloads docker images

$ minishift start --vm-driver=virtualbox

# Set local paths
$ eval $(minishift oc-env)

# Ensure oc is using minishift
$ oc config use-context minishift

# Open the web console
$ minishift console

Provided Builder Images

  • Provides runtime customization
  • Builtin with OpenShift
  • Also provided by community
  • "Easy" to create your own

Builder Images

Controlling Your Environment

# The parent image uses ONBUILD command
# to add package.json, run npm install and
# ultimately run the application

FROM bucharestgold/centos7-nodejs:7.10.0

# Set environment variables available
# in the runtime container
ENV ZIPKIN_SERVER_URL="http://zipkin"

Dockerfiles

ONBUILD

ONBUILD COPY package.json /opt/app-root/src
ONBUILD COPY . /opt/app-root/src

# Drop the root user and make the content of
# /opt/app-root owned by user 1001
# Do this after we've copied the local directory
# to avoid UID conflicts
ONBUILD RUN chown -R 1001:0 /opt/app-root && chmod -R ug+rwx /opt/app-root
ONBUILD USER 1001

# Install the app
ONBUILD RUN npm -s install

CMD ["/bin/bash", "-c", "npm run -d $NPM_RUN" ]
$ oc new-project bonjour-tout-le-monde

$ oc new-build --binary --name=bonjour -l app=bonjour

$ oc start-build bonjour --from-dir=. --follow

$ oc new-app bonjour -l app=bonjour

$ oc expose service bonjour

New Project

$ oc new-build \
   --image-stream=centos7-s2i-nodejs:latest \
   --binary --name=hola -l app=hola

$ oc start-build hola --from-dir=. --follow

$ oc new-app hola -l app=hola

$ oc expose-service hola

s2i Builds

Importing Image Streams

{
  "kind": "ImageStream",
  "apiVersion": "v1",
  "metadata": {
    "name": "centos7-s2i-nodejs",
    "creationTimestamp": "2017-05-07T00:55:49.860Z"
  },
  "spec": {
    "tags": [
      {
        "name": "4.8.3",
        "annotations": {
          "description": "Build and run Node.js applications",
          "iconClass": "icon-nodejs",
          "tags": "builder, node, nodejs, nodejs-7.10.0, nodejs-7.10.0",
          "supports": "nodejs:7, nodejs:7.10, nodejs",
          "sampleRepo": "https://github.com/bucharest-gold/s2i-nodejs.git"
        },
        "from": {
          "kind": "DockerImage",
          "name": "bucharestgold/centos7-s2i-nodejs:7.10.0"
        }
      }
    ]
  }
}

Image Streams

Let's Try

Some Stuff Live!

Questions

Merci Beaucoup!

Lance Ball

Sr. Software Engineer

Red Hat

http://lanceball.com/riviera-dev-2017

@lanceball  / @lance