Compare commits

..

No commits in common. "master" and "revert-111-nodejs6" have entirely different histories.

16 changed files with 87 additions and 334 deletions

View file

@ -1,34 +1,4 @@
Node.js sample app on OpenShift!
<!-- toc -->
- [Node.js sample app on OpenShift!](#nodejs-sample-app-on-openshift)
* [OpenShift Origin v3 setup](#openshift-origin-v3-setup)
+ [Running a virtual machine with Vagrant](#running-a-virtual-machine-with-vagrant)
+ [Running a virtual machine managed by minishift](#running-a-virtual-machine-managed-by-minishift)
+ [Starting a Docker container](#starting-a-docker-container)
+ [Downloading the Binary](#downloading-the-binary)
+ [Running an Ansible playbook](#running-an-ansible-playbook)
* [Creating a project](#creating-a-project)
* [Creating new apps](#creating-new-apps)
+ [Create a new app from source code (method 1)](#create-a-new-app-from-source-code-method-1)
+ [Create a new app from a template (method 2)](#create-a-new-app-from-a-template-method-2)
+ [Build the app](#build-the-app)
+ [Deploy the app](#deploy-the-app)
+ [Configure routing](#configure-routing)
+ [Create a new app from an image (method 3)](#create-a-new-app-from-an-image-method-3)
+ [Setting environment variables](#setting-environment-variables)
+ [Success](#success)
+ [Pushing updates](#pushing-updates)
* [Debugging](#debugging)
* [Web UI](#web-ui)
* [Looking for help](#looking-for-help)
* [Compatibility](#compatibility)
* [License](#license)
<!-- tocstop -->
## Node.js sample app on OpenShift!
----------------- -----------------
This example will serve a welcome page and the current hit count as stored in a database. This example will serve a welcome page and the current hit count as stored in a database.
@ -38,30 +8,25 @@ This example will serve a welcome page and the current hit count as stored in a
There are four methods to get started with OpenShift v3: There are four methods to get started with OpenShift v3:
- Running a virtual machine with Vagrant - Running a virtual machine with Vagrant
- Running a virtual machine managed by minishift
- Starting a Docker container - Starting a Docker container
- Downloading the binary - Downloading the binary
- Running an Ansible playbook - Running an Ansible playbook
#### Running a virtual machine with Vagrant #### Running a virtual machine with Vagrant
One option is to use the Vagrant all-in-one launch as described in the [OpenShift Origin All-In-One Virtual Machine](https://www.okd.io/vm/). This option works on Mac, Windows and Linux, but requires that you install [Vagrant](https://www.vagrantup.com/downloads.html) running [VirtualBox](https://www.virtualbox.org/wiki/Downloads). One option is to use the Vagrant all-in-one launch as described in the [OpenShift Origin All-In-One Virtual Machine](https://www.openshift.org/vm/). This option works on Mac, Windows and Linux, but requires that you install [Vagrant](https://www.vagrantup.com/downloads.html) running [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
#### Running a virtual machine managed by minishift
Another option to run virtual machine but not having to using Vagrant is to download and use the `minishift` binary as described in its [getting started](https://github.com/minishift/minishift/#getting-started) section. `minishift` can be used to spin up a VM on any of Windows, Linux or Mac with the help of supported underlying virtualization technologies like KVM, xhyve, Hyper-V, VirtualBox.
#### Starting a Docker container #### Starting a Docker container
Another option is running the OpenShift Origin Docker container image from [Docker Hub](https://hub.docker.com/r/openshift/origin/) launch as described in the [Getting Started for Administrators](https://docs.okd.io/latest/getting_started/administrators.html#running-in-a-docker-container). This method is supported on Fedora, CentOS, and Red Hat Enterprise Linux (RHEL) hosts only. Another option is running the OpenShift Origin Docker container image from [Docker Hub](https://hub.docker.com/r/openshift/origin/) launch as described in the [Getting Started for Administrators](https://docs.openshift.org/latest/getting_started/administrators.html#running-in-a-docker-container). This method is supported on Fedora, CentOS, and Red Hat Enterprise Linux (RHEL) hosts only.
#### Downloading the Binary #### Downloading the Binary
Red Hat periodically publishes OpenShift Origin Server binaries for Linux, which you can download on the OpenShift Origin GitHub [Release](https://github.com/openshift/origin/releases) page. Instructions on how to install and launch the Openshift Origin Server from binary are described in [Getting Started for Administrators](https://docs.okd.io/latest/getting_started/administrators.html#downloading-the-binary). Red Hat periodically publishes OpenShift Origin Server binaries for Linux, which you can download on the OpenShift Origin GitHub [Release](https://github.com/openshift/origin/releases) page. Instructions on how to install and launch the Openshift Origin Server from binary are described in [Getting Started for Administrators](https://docs.openshift.org/latest/getting_started/administrators.html#downloading-the-binary).
#### Running an Ansible playbook #### Running an Ansible playbook
Outlined as the [Advanced Installation](https://docs.okd.io/latest/install_config/install/advanced_install.html) method for poduction environments, OpenShift Origin is also installable via Ansible playbook made avaialble on the GitHub [openshift-ansible](https://github.com/openshift/openshift-ansible) repo. Outlined as the [Advanced Installation](https://docs.openshift.org/latest/install_config/install/advanced_install.html) method for poduction environments, OpenShift Origin is also installable via Ansible playbook made avaialble on the GitHub [openshift-ansible](https://github.com/openshift/openshift-ansible) repo.
### Creating a project ### Creating a project
@ -69,7 +34,7 @@ Outlined as the [Advanced Installation](https://docs.okd.io/latest/install_confi
After logging in with `oc login` (default username/password: openshift), if you don't have a project setup all ready, go ahead and take care of that: After logging in with `oc login` (default username/password: openshift), if you don't have a project setup all ready, go ahead and take care of that:
$ oc new-project nodejs-echo \ $ oc new-project nodejs-echo \
--display-name="nodejs" --description="Sample Node.js app" $ --display-name="nodejs" --description="Sample Node.js app"
That's it, project has been created. Though it would probably be good to set your current project to this (thought new-project does it automatically as well), such as: That's it, project has been created. Though it would probably be good to set your current project to this (thought new-project does it automatically as well), such as:
@ -87,7 +52,7 @@ You can create a new OpenShift application using the web console or by running t
Pointing `oc new-app` at source code kicks off a chain of events, for our example run: Pointing `oc new-app` at source code kicks off a chain of events, for our example run:
$ oc new-app https://github.com/sclorg/nodejs-ex -l name=myapp $ oc new-app https://github.com/openshift/nodejs-ex -l name=myapp
The tool will inspect the source code, locate an appropriate image on DockerHub, create an ImageStream for that image, and then create the right build configuration, deployment configuration and service definition. The tool will inspect the source code, locate an appropriate image on DockerHub, create an ImageStream for that image, and then create the right build configuration, deployment configuration and service definition.
@ -95,9 +60,9 @@ The tool will inspect the source code, locate an appropriate image on DockerHub,
#### Create a new app from a template (method 2) #### Create a new app from a template (method 2)
We can also [create new apps using OpenShift template files](https://docs.openshift.com/enterprise/3.0/dev_guide/new_app.html#specifying-a-template). Clone the demo app source code from [GitHub repo](https://github.com/sclorg/nodejs-ex) (fork if you like). We can also [create new apps using OpenShift template files](https://docs.openshift.com/enterprise/3.0/dev_guide/new_app.html#specifying-a-template). Clone the demo app source code from [GitHub repo](https://github.com/openshift/nodejs-ex) (fork if you like).
$ git clone https://github.com/sclorg/nodejs-ex $ git clone https://github.com/openshift/nodejs-ex
Looking at the repo, you'll notice three files in the openshift/template directory: Looking at the repo, you'll notice three files in the openshift/template directory:
@ -133,7 +98,7 @@ Which should return something like:
svc/nodejs-ex - 172.30.108.183:8080 svc/nodejs-ex - 172.30.108.183:8080
dc/nodejs-ex deploys istag/nodejs-ex:latest <- dc/nodejs-ex deploys istag/nodejs-ex:latest <-
bc/nodejs-ex builds https://github.com/sclorg/nodejs-ex with openshift/nodejs:0.10 bc/nodejs-ex builds https://github.com/openshift/nodejs-ex with openshift/nodejs:0.10
build #1 running for 7 seconds build #1 running for 7 seconds
deployment #1 waiting on image or update deployment #1 waiting on image or update
@ -179,7 +144,7 @@ Now navigate to the newly created Node.js web app at the hostname we just config
You may have noticed the index page "Page view count" reads "No database configured". Let's fix that by adding a MongoDB service. We could use the second OpenShift template example (`nodejs-mongodb.json`) but for the sake of demonstration let's point `oc new-app` at a DockerHub image: You may have noticed the index page "Page view count" reads "No database configured". Let's fix that by adding a MongoDB service. We could use the second OpenShift template example (`nodejs-mongodb.json`) but for the sake of demonstration let's point `oc new-app` at a DockerHub image:
$ oc new-app centos/mongodb-26-centos7 \ $ oc new-app centos/mongodb-26-centos7 \
-e MONGODB_USER=admin,MONGODB_DATABASE=mongo_db,MONGODB_PASSWORD=secret,MONGODB_ADMIN_PASSWORD=super-secret $ -e MONGODB_USER=admin,MONGODB_DATABASE=mongo_db,MONGODB_PASSWORD=secret,MONGODB_ADMIN_PASSWORD=super-secret
The `-e` flag sets the environment variables we want used in the configuration of our new app. The `-e` flag sets the environment variables we want used in the configuration of our new app.
@ -193,7 +158,7 @@ Running `oc status` or checking the web console will reveal the address of the n
http://10.2.2.2 to pod port 8080-tcp (svc/nodejs-ex) http://10.2.2.2 to pod port 8080-tcp (svc/nodejs-ex)
dc/nodejs-ex deploys istag/nodejs-ex:latest <- dc/nodejs-ex deploys istag/nodejs-ex:latest <-
bc/nodejs-ex builds https://github.com/sclorg/nodejs-ex with openshift/nodejs:0.10 bc/nodejs-ex builds https://github.com/openshift/nodejs-ex with openshift/nodejs:0.10
deployment #1 deployed 14 minutes ago - 1 pod deployment #1 deployed 14 minutes ago - 1 pod
Note that the url for our new Mongo instance, for our example, is `172.30.0.112:27017`, yours will likely differ. Note that the url for our new Mongo instance, for our example, is `172.30.0.112:27017`, yours will likely differ.
@ -216,7 +181,7 @@ Then check `oc status` to see that an updated deployment has been kicked off:
http://10.2.2.2 to pod port 8080-tcp (svc/nodejs-ex) http://10.2.2.2 to pod port 8080-tcp (svc/nodejs-ex)
dc/nodejs-ex deploys istag/nodejs-ex:latest <- dc/nodejs-ex deploys istag/nodejs-ex:latest <-
bc/nodejs-ex builds https://github.com/sclorg/nodejs-ex with openshift/nodejs:0.10 bc/nodejs-ex builds https://github.com/openshift/nodejs-ex with openshift/nodejs:0.10
deployment #2 deployed about a minute ago - 1 pod deployment #2 deployed about a minute ago - 1 pod
deployment #1 deployed 2 hours ago deployment #1 deployed 2 hours ago
@ -240,14 +205,11 @@ To run this example from the Web UI, you can same steps following done on the CL
<img src="http://img.youtube.com/vi/uocucZqg_0I/0.jpg" <img src="http://img.youtube.com/vi/uocucZqg_0I/0.jpg"
alt="OpenShift 3: Node.js Sample" width="240" height="180" border="10" /></a> alt="OpenShift 3: Node.js Sample" width="240" height="180" border="10" /></a>
### Looking for help ## Looking for help
If you get stuck at some point, or think that this document needs further details or clarification, you can give feedback and look for help using the channels mentioned in [the OpenShift Origin repo](https://github.com/openshift/origin), or by filing an issue. If you get stuck at some point, or think that this document needs further details or clarification, you can give feedback and look for help using the channels mentioned in [the OpenShift Origin repo](https://github.com/openshift/origin), or by filing an issue.
### Compatibility
This repository is compatible with Node.js 4 and higher, excluding any alpha or beta versions. ## License
### License
This code is dedicated to the public domain to the maximum extent permitted by applicable law, pursuant to [CC0](http://creativecommons.org/publicdomain/zero/1.0/). This code is dedicated to the public domain to the maximum extent permitted by applicable law, pursuant to [CC0](http://creativecommons.org/publicdomain/zero/1.0/).

View file

@ -1,9 +0,0 @@
name: nodejs
version: 0.1
description: An example Node.js application with no database. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md.
keywords:
- quickstart
- nodejs
home: https://access.redhat.com
sources:
- https://github.com/sclorg/nodejs-ex

View file

@ -1,3 +0,0 @@
The following service(s) have been created in your project: {{ .Values.name }}.
For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md.

View file

@ -1,38 +0,0 @@
kind: BuildConfig
apiVersion: build.openshift.io/v1
metadata:
name: {{ .Values.name | quote }}
annotations:
description: Defines how to build the application
spec:
source:
type: Git
git:
uri: {{ .Values.source_repository_url | quote }}
ref: {{ .Values.source_repository_ref | quote }}
contextDir: {{ .Values.context_dir | quote }}
strategy:
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
namespace: {{ .Values.namespace | quote }}
name: nodejs:6
env:
- name: NPM_MIRROR
value: {{ .Values.npm_mirror | quote }}
output:
to:
kind: ImageStreamTag
name: {{ print .Values.name ":latest" | quote }}
triggers:
- type: ImageChange
- type: ConfigChange
- type: GitHub
github:
secret: {{ .Values.github_webhook_secret | default (randAlphaNum 40) | quote }}
- type: Generic
generic:
secret: {{ .Values.generic_webhook_secret | default (randAlphaNum 40) | quote }}
postCommit:
script: npm test

View file

@ -1,49 +0,0 @@
kind: DeploymentConfig
apiVersion: apps.openshift.io/v1
metadata:
name: {{ .Values.name | quote }}
annotations:
description: Defines how to deploy the application server
template.alpha.openshift.io/wait-for-ready: 'true'
spec:
strategy:
type: Rolling
triggers:
- type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- nodejs-example
from:
kind: ImageStreamTag
name: {{ print .Values.name ":latest" | quote }}
- type: ConfigChange
replicas: 1
selector:
name: {{ .Values.name | quote }}
template:
metadata:
name: {{ .Values.name | quote }}
labels:
name: {{ .Values.name | quote }}
spec:
containers:
- name: nodejs-example
image: " "
ports:
- containerPort: 8080
readinessProbe:
timeoutSeconds: 3
initialDelaySeconds: 3
httpGet:
path: "/"
port: 8080
livenessProbe:
timeoutSeconds: 3
initialDelaySeconds: 30
httpGet:
path: "/"
port: 8080
resources:
limits:
memory: {{ .Values.memory_limit | quote }}

View file

@ -1,6 +0,0 @@
kind: ImageStream
apiVersion: image.openshift.io/v1
metadata:
name: {{ .Values.name | quote }}
annotations:
description: Keeps track of changes in the application image

View file

@ -1,9 +0,0 @@
kind: Route
apiVersion: route.openshift.io/v1
metadata:
name: {{ .Values.name | quote }}
spec:
host: {{ .Values.application_domain | quote }}
to:
kind: Service
name: {{ .Values.name | quote }}

View file

@ -1,13 +0,0 @@
kind: Service
apiVersion: v1
metadata:
name: {{ .Values.name | quote }}
annotations:
description: Exposes and load balances the application pods
spec:
ports:
- name: web
port: 8080
targetPort: 8080
selector:
name: {{ .Values.name | quote }}

View file

@ -1,20 +0,0 @@
# Name: The name assigned to all of the frontend objects defined in this template.
name: nodejs-example
# Namespace: The OpenShift Namespace where the ImageStream resides.
namespace: openshift
# Memory Limit: Maximum amount of memory the container can use.
memory_limit: 512Mi
# Git Repository URL: The URL of the repository with your application source code.
source_repository_url: https://github.com/sclorg/nodejs-ex.git
# Git Reference: Set this to a branch name, tag or other ref of your repository if you are not using the default branch.
source_repository_ref:
# Context Directory: Set this to the relative path to your project if it is not in the root of your repository.
context_dir:
# Application Hostname: The exposed hostname that will route to the Node.js service, if left blank a value will be defaulted.
application_domain:
# GitHub Webhook Secret: Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.
github_webhook_secret:
# Generic Webhook Secret: A secret string used to configure the Generic webhook.
generic_webhook_secret:
# Custom NPM Mirror URL: The custom NPM mirror URL
npm_mirror:

View file

@ -5,10 +5,10 @@ To do this, run:
```bash ```bash
# create the nodejs example as usual # create the nodejs example as usual
oc new-app https://github.com/sclorg/nodejs-ex oc new-app https://github.com/openshift/nodejs-ex
# now create the pipeline build controller from the openshift/pipeline # now create the pipeline build controller from the openshift/pipeline
# subdirectory # subdirectory
oc new-app https://github.com/sclorg/nodejs-ex \ oc new-app https://github.com/openshift/nodejs-ex \
--context-dir=openshift/pipeline --name nodejs-ex-pipeline --context-dir=openshift/pipeline --name nodejs-ex-pipeline
``` ```

View file

@ -4,18 +4,17 @@
"metadata": { "metadata": {
"name": "nodejs-mongo-persistent", "name": "nodejs-mongo-persistent",
"annotations": { "annotations": {
"openshift.io/display-name": "Node.js + MongoDB", "openshift.io/display-name": "Node.js + MongoDB (Persistent)",
"description": "An example Node.js application with a MongoDB database. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md.", "description": "An example Node.js application with a MongoDB database. For more information about using this template, including OpenShift considerations, see https://github.com/openshift/nodejs-ex/blob/master/README.md.",
"tags": "quickstart,nodejs", "tags": "quickstart,nodejs",
"iconClass": "icon-nodejs", "iconClass": "icon-nodejs",
"openshift.io/long-description": "This template defines resources needed to develop a NodeJS application, including a build configuration, application deployment configuration, and database deployment configuration.", "template.openshift.io/long-description": "This template defines resources needed to develop a NodeJS application, including a build configuration, application deployment configuration, and database deployment configuration.",
"openshift.io/provider-display-name": "Red Hat, Inc.", "template.openshift.io/provider-display-name": "Red Hat, Inc.",
"openshift.io/documentation-url": "https://github.com/sclorg/nodejs-ex", "template.openshift.io/documentation-url": "https://github.com/openshift/nodejs-ex",
"openshift.io/support-url": "https://access.redhat.com", "template.openshift.io/support-url": "https://access.redhat.com"
"template.openshift.io/bindable": "false"
} }
}, },
"message": "The following service(s) have been created in your project: ${NAME}, ${DATABASE_SERVICE_NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md.", "message": "The following service(s) have been created in your project: ${NAME}, ${DATABASE_SERVICE_NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/openshift/nodejs-ex/blob/master/README.md.",
"labels": { "labels": {
"template": "nodejs-mongo-persistent" "template": "nodejs-mongo-persistent"
}, },
@ -85,8 +84,7 @@
"metadata": { "metadata": {
"name": "${NAME}", "name": "${NAME}",
"annotations": { "annotations": {
"description": "Defines how to build the application", "description": "Defines how to build the application"
"template.alpha.openshift.io/wait-for-ready": "true"
} }
}, },
"spec": { "spec": {
@ -104,7 +102,7 @@
"from": { "from": {
"kind": "ImageStreamTag", "kind": "ImageStreamTag",
"namespace": "${NAMESPACE}", "namespace": "${NAMESPACE}",
"name": "nodejs:${NODEJS_VERSION}" "name": "nodejs:4"
}, },
"env": [ "env": [
{ {
@ -151,8 +149,7 @@
"metadata": { "metadata": {
"name": "${NAME}", "name": "${NAME}",
"annotations": { "annotations": {
"description": "Defines how to deploy the application server", "description": "Defines how to deploy the application server"
"template.alpha.openshift.io/wait-for-ready": "true"
} }
}, },
"spec": { "spec": {
@ -239,7 +236,7 @@
"timeoutSeconds": 3, "timeoutSeconds": 3,
"initialDelaySeconds": 3, "initialDelaySeconds": 3,
"httpGet": { "httpGet": {
"path": "/", "path": "/pagecount",
"port": 8080 "port": 8080
} }
}, },
@ -247,7 +244,7 @@
"timeoutSeconds": 3, "timeoutSeconds": 3,
"initialDelaySeconds": 30, "initialDelaySeconds": 30,
"httpGet": { "httpGet": {
"path": "/", "path": "/pagecount",
"port": 8080 "port": 8080
} }
}, },
@ -307,8 +304,7 @@
"metadata": { "metadata": {
"name": "${DATABASE_SERVICE_NAME}", "name": "${DATABASE_SERVICE_NAME}",
"annotations": { "annotations": {
"description": "Defines how to deploy the database", "description": "Defines how to deploy the database"
"template.alpha.openshift.io/wait-for-ready": "true"
} }
}, },
"spec": { "spec": {
@ -326,7 +322,7 @@
"from": { "from": {
"kind": "ImageStreamTag", "kind": "ImageStreamTag",
"namespace": "${NAMESPACE}", "namespace": "${NAMESPACE}",
"name": "mongodb:${MONGODB_VERSION}" "name": "mongodb:3.2"
} }
} }
}, },
@ -448,20 +444,6 @@
"required": true, "required": true,
"value": "openshift" "value": "openshift"
}, },
{
"name": "NODEJS_VERSION",
"displayName": "Version of NodeJS Image",
"description": "Version of NodeJS image to be used (6, 8, or latest).",
"value": "8",
"required": true
},
{
"name": "MONGODB_VERSION",
"displayName": "Version of MongoDB Image",
"description": "Version of MongoDB image to be used (3.6 or latest).",
"value": "3.6",
"required": true
},
{ {
"name": "MEMORY_LIMIT", "name": "MEMORY_LIMIT",
"displayName": "Memory Limit", "displayName": "Memory Limit",
@ -488,7 +470,7 @@
"displayName": "Git Repository URL", "displayName": "Git Repository URL",
"description": "The URL of the repository with your application source code.", "description": "The URL of the repository with your application source code.",
"required": true, "required": true,
"value": "https://github.com/sclorg/nodejs-ex.git" "value": "https://github.com/openshift/nodejs-ex.git"
}, },
{ {
"name": "SOURCE_REPOSITORY_REF", "name": "SOURCE_REPOSITORY_REF",
@ -509,7 +491,7 @@
{ {
"name": "GITHUB_WEBHOOK_SECRET", "name": "GITHUB_WEBHOOK_SECRET",
"displayName": "GitHub Webhook Secret", "displayName": "GitHub Webhook Secret",
"description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.", "description": "A secret string used to configure the GitHub webhook.",
"generate": "expression", "generate": "expression",
"from": "[a-zA-Z0-9]{40}" "from": "[a-zA-Z0-9]{40}"
}, },

View file

@ -5,20 +5,18 @@
"name": "nodejs-mongodb-example", "name": "nodejs-mongodb-example",
"annotations": { "annotations": {
"openshift.io/display-name": "Node.js + MongoDB (Ephemeral)", "openshift.io/display-name": "Node.js + MongoDB (Ephemeral)",
"description": "An example Node.js application with a MongoDB database. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md.\n\nWARNING: Any data stored will be lost upon pod destruction. Only use this template for testing.", "description": "An example Node.js application with a MongoDB database. For more information about using this template, including OpenShift considerations, see https://github.com/openshift/nodejs-ex/blob/master/README.md.\n\nWARNING: Any data stored will be lost upon pod destruction. Only use this template for testing.",
"tags": "quickstart,nodejs", "tags": "quickstart,nodejs",
"iconClass": "icon-nodejs", "iconClass": "icon-nodejs",
"openshift.io/long-description": "This template defines resources needed to develop a NodeJS application, including a build configuration, application deployment configuration, and database deployment configuration. The database is stored in non-persistent storage, so this configuration should be used for experimental purposes only.", "template.openshift.io/long-description": "This template defines resources needed to develop a NodeJS application, including a build configuration, application deployment configuration, and database deployment configuration. The database is stored in non-persistent storage, so this configuration should be used for experimental purposes only.",
"openshift.io/provider-display-name": "Red Hat, Inc.", "template.openshift.io/provider-display-name": "Red Hat, Inc.",
"openshift.io/documentation-url": "https://github.com/sclorg/nodejs-ex", "template.openshift.io/documentation-url": "https://github.com/openshift/nodejs-ex",
"openshift.io/support-url": "https://access.redhat.com", "template.openshift.io/support-url": "https://access.redhat.com"
"template.openshift.io/bindable": "false"
} }
}, },
"message": "The following service(s) have been created in your project: ${NAME}, ${DATABASE_SERVICE_NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md.", "message": "The following service(s) have been created in your project: ${NAME}, ${DATABASE_SERVICE_NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/openshift/nodejs-ex/blob/master/README.md.",
"labels": { "labels": {
"template": "nodejs-mongodb-example", "template": "nodejs-mongodb-example"
"app": "nodejs-mongodb-example"
}, },
"objects": [ "objects": [
{ {
@ -86,8 +84,7 @@
"metadata": { "metadata": {
"name": "${NAME}", "name": "${NAME}",
"annotations": { "annotations": {
"description": "Defines how to build the application", "description": "Defines how to build the application"
"template.alpha.openshift.io/wait-for-ready": "true"
} }
}, },
"spec": { "spec": {
@ -105,7 +102,7 @@
"from": { "from": {
"kind": "ImageStreamTag", "kind": "ImageStreamTag",
"namespace": "${NAMESPACE}", "namespace": "${NAMESPACE}",
"name": "nodejs:${NODEJS_VERSION}" "name": "nodejs:4"
}, },
"env": [ "env": [
{ {
@ -152,8 +149,7 @@
"metadata": { "metadata": {
"name": "${NAME}", "name": "${NAME}",
"annotations": { "annotations": {
"description": "Defines how to deploy the application server", "description": "Defines how to deploy the application server"
"template.alpha.openshift.io/wait-for-ready": "true"
} }
}, },
"spec": { "spec": {
@ -240,7 +236,7 @@
"timeoutSeconds": 3, "timeoutSeconds": 3,
"initialDelaySeconds": 3, "initialDelaySeconds": 3,
"httpGet": { "httpGet": {
"path": "/", "path": "/pagecount",
"port": 8080 "port": 8080
} }
}, },
@ -248,7 +244,7 @@
"timeoutSeconds": 3, "timeoutSeconds": 3,
"initialDelaySeconds": 30, "initialDelaySeconds": 30,
"httpGet": { "httpGet": {
"path": "/", "path": "/pagecount",
"port": 8080 "port": 8080
} }
}, },
@ -291,8 +287,7 @@
"metadata": { "metadata": {
"name": "${DATABASE_SERVICE_NAME}", "name": "${DATABASE_SERVICE_NAME}",
"annotations": { "annotations": {
"description": "Defines how to deploy the database", "description": "Defines how to deploy the database"
"template.alpha.openshift.io/wait-for-ready": "true"
} }
}, },
"spec": { "spec": {
@ -310,7 +305,7 @@
"from": { "from": {
"kind": "ImageStreamTag", "kind": "ImageStreamTag",
"namespace": "${NAMESPACE}", "namespace": "${NAMESPACE}",
"name": "mongodb:${MONGODB_VERSION}" "name": "mongodb:3.2"
} }
} }
}, },
@ -432,20 +427,6 @@
"required": true, "required": true,
"value": "openshift" "value": "openshift"
}, },
{
"name": "NODEJS_VERSION",
"displayName": "Version of NodeJS Image",
"description": "Version of NodeJS image to be used (6, 8, or latest).",
"value": "8",
"required": true
},
{
"name": "MONGODB_VERSION",
"displayName": "Version of MongoDB Image",
"description": "Version of MongoDB image to be used (3.6 or latest).",
"value": "3.6",
"required": true
},
{ {
"name": "MEMORY_LIMIT", "name": "MEMORY_LIMIT",
"displayName": "Memory Limit", "displayName": "Memory Limit",
@ -465,7 +446,7 @@
"displayName": "Git Repository URL", "displayName": "Git Repository URL",
"description": "The URL of the repository with your application source code.", "description": "The URL of the repository with your application source code.",
"required": true, "required": true,
"value": "https://github.com/sclorg/nodejs-ex.git" "value": "https://github.com/openshift/nodejs-ex.git"
}, },
{ {
"name": "SOURCE_REPOSITORY_REF", "name": "SOURCE_REPOSITORY_REF",
@ -486,7 +467,7 @@
{ {
"name": "GITHUB_WEBHOOK_SECRET", "name": "GITHUB_WEBHOOK_SECRET",
"displayName": "GitHub Webhook Secret", "displayName": "GitHub Webhook Secret",
"description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.", "description": "A secret string used to configure the GitHub webhook.",
"generate": "expression", "generate": "expression",
"from": "[a-zA-Z0-9]{40}" "from": "[a-zA-Z0-9]{40}"
}, },

View file

@ -5,20 +5,18 @@
"name": "nodejs-example", "name": "nodejs-example",
"annotations": { "annotations": {
"openshift.io/display-name": "Node.js", "openshift.io/display-name": "Node.js",
"description": "An example Node.js application with no database. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md.", "description": "An example Node.js application with no database. For more information about using this template, including OpenShift considerations, see https://github.com/openshift/nodejs-ex/blob/master/README.md.",
"tags": "quickstart,nodejs", "tags": "quickstart,nodejs",
"iconClass": "icon-nodejs", "iconClass": "icon-nodejs",
"openshift.io/long-description": "This template defines resources needed to develop a NodeJS application, including a build configuration and application deployment configuration. It does not include a database.", "template.openshift.io/long-description": "This template defines resources needed to develop a NodeJS application, including a build configuration and application deployment configuration. It does not include a database.",
"openshift.io/provider-display-name": "Red Hat, Inc.", "template.openshift.io/provider-display-name": "Red Hat, Inc.",
"openshift.io/documentation-url": "https://github.com/sclorg/nodejs-ex", "template.openshift.io/documentation-url": "https://github.com/openshift/nodejs-ex",
"openshift.io/support-url": "https://access.redhat.com", "template.openshift.io/support-url": "https://access.redhat.com"
"template.openshift.io/bindable": "false"
} }
}, },
"message": "The following service(s) have been created in your project: ${NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md.", "message": "The following service(s) have been created in your project: ${NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/openshift/nodejs-ex/blob/master/README.md.",
"labels": { "labels": {
"template": "nodejs-example", "template": "nodejs-example"
"app": "nodejs-example"
}, },
"objects": [ "objects": [
{ {
@ -73,8 +71,7 @@
"metadata": { "metadata": {
"name": "${NAME}", "name": "${NAME}",
"annotations": { "annotations": {
"description": "Defines how to build the application", "description": "Defines how to build the application"
"template.alpha.openshift.io/wait-for-ready": "true"
} }
}, },
"spec": { "spec": {
@ -92,7 +89,7 @@
"from": { "from": {
"kind": "ImageStreamTag", "kind": "ImageStreamTag",
"namespace": "${NAMESPACE}", "namespace": "${NAMESPACE}",
"name": "nodejs:${NODEJS_VERSION}" "name": "nodejs:4"
}, },
"env": [ "env": [
{ {
@ -139,8 +136,7 @@
"metadata": { "metadata": {
"name": "${NAME}", "name": "${NAME}",
"annotations": { "annotations": {
"description": "Defines how to deploy the application server", "description": "Defines how to deploy the application server"
"template.alpha.openshift.io/wait-for-ready": "true"
} }
}, },
"spec": { "spec": {
@ -208,7 +204,12 @@
} }
}, },
"env": [ "env": [
] ],
"resources": {
"limits": {
"memory": "${MEMORY_LIMIT}"
}
}
} }
] ]
} }
@ -231,13 +232,6 @@
"required": true, "required": true,
"value": "openshift" "value": "openshift"
}, },
{
"name": "NODEJS_VERSION",
"displayName": "Version of NodeJS Image",
"description": "Version of NodeJS image to be used (6, 8, or latest).",
"value": "8",
"required": true
},
{ {
"name": "MEMORY_LIMIT", "name": "MEMORY_LIMIT",
"displayName": "Memory Limit", "displayName": "Memory Limit",
@ -250,7 +244,7 @@
"displayName": "Git Repository URL", "displayName": "Git Repository URL",
"description": "The URL of the repository with your application source code.", "description": "The URL of the repository with your application source code.",
"required": true, "required": true,
"value": "https://github.com/sclorg/nodejs-ex.git" "value": "https://github.com/openshift/nodejs-ex.git"
}, },
{ {
"name": "SOURCE_REPOSITORY_REF", "name": "SOURCE_REPOSITORY_REF",
@ -271,7 +265,7 @@
{ {
"name": "GITHUB_WEBHOOK_SECRET", "name": "GITHUB_WEBHOOK_SECRET",
"displayName": "GitHub Webhook Secret", "displayName": "GitHub Webhook Secret",
"description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.", "description": "A secret string used to configure the GitHub webhook.",
"generate": "expression", "generate": "expression",
"from": "[a-zA-Z0-9]{40}" "from": "[a-zA-Z0-9]{40}"
}, },

View file

@ -23,12 +23,12 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "http://github.com/sclorg/nodejs-ex.git" "url": "http://github.com/openshift/nodejs-ex.git"
}, },
"author": "Steve Speicher <sspeiche@gmail.com>", "author": "Steve Speicher <sspeiche@gmail.com>",
"license": "CC-BY-1.0", "license": "CC-BY-1.0",
"bugs": { "bugs": {
"url": "http://github.com/sclorg/nodejs-ex/issues" "url": "http://github.com/openshift/nodejs-ex/issues"
}, },
"homepage": "http://github.com/sclorg/nodejs-ex" "homepage": "http://github.com/openshift/nodejs-ex"
} }

View file

@ -1,6 +1,8 @@
// OpenShift sample Node application // OpenShift sample Node application
var express = require('express'), var express = require('express'),
fs = require('fs'),
app = express(), app = express(),
eps = require('ejs'),
morgan = require('morgan'); morgan = require('morgan');
Object.assign=require('object-assign') Object.assign=require('object-assign')
@ -13,31 +15,13 @@ var port = process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080,
mongoURL = process.env.OPENSHIFT_MONGODB_DB_URL || process.env.MONGO_URL, mongoURL = process.env.OPENSHIFT_MONGODB_DB_URL || process.env.MONGO_URL,
mongoURLLabel = ""; mongoURLLabel = "";
if (mongoURL == null) { if (mongoURL == null && process.env.DATABASE_SERVICE_NAME) {
var mongoHost, mongoPort, mongoDatabase, mongoPassword, mongoUser; var mongoServiceName = process.env.DATABASE_SERVICE_NAME.toUpperCase(),
// If using plane old env vars via service discovery mongoHost = process.env[mongoServiceName + '_SERVICE_HOST'],
if (process.env.DATABASE_SERVICE_NAME) { mongoPort = process.env[mongoServiceName + '_SERVICE_PORT'],
var mongoServiceName = process.env.DATABASE_SERVICE_NAME.toUpperCase(); mongoDatabase = process.env[mongoServiceName + '_DATABASE'],
mongoHost = process.env[mongoServiceName + '_SERVICE_HOST']; mongoPassword = process.env[mongoServiceName + '_PASSWORD']
mongoPort = process.env[mongoServiceName + '_SERVICE_PORT']; mongoUser = process.env[mongoServiceName + '_USER'];
mongoDatabase = process.env[mongoServiceName + '_DATABASE'];
mongoPassword = process.env[mongoServiceName + '_PASSWORD'];
mongoUser = process.env[mongoServiceName + '_USER'];
// If using env vars from secret from service binding
} else if (process.env.database_name) {
mongoDatabase = process.env.database_name;
mongoPassword = process.env.password;
mongoUser = process.env.username;
var mongoUriParts = process.env.uri && process.env.uri.split("//");
if (mongoUriParts.length == 2) {
mongoUriParts = mongoUriParts[1].split(":");
if (mongoUriParts && mongoUriParts.length == 2) {
mongoHost = mongoUriParts[0];
mongoPort = mongoUriParts[1];
}
}
}
if (mongoHost && mongoPort && mongoDatabase) { if (mongoHost && mongoPort && mongoDatabase) {
mongoURLLabel = mongoURL = 'mongodb://'; mongoURLLabel = mongoURL = 'mongodb://';
@ -47,6 +31,7 @@ if (mongoURL == null) {
// Provide UI label that excludes user id and pw // Provide UI label that excludes user id and pw
mongoURLLabel += mongoHost + ':' + mongoPort + '/' + mongoDatabase; mongoURLLabel += mongoHost + ':' + mongoPort + '/' + mongoDatabase;
mongoURL += mongoHost + ':' + mongoPort + '/' + mongoDatabase; mongoURL += mongoHost + ':' + mongoPort + '/' + mongoDatabase;
} }
} }
var db = null, var db = null,
@ -84,9 +69,6 @@ app.get('/', function (req, res) {
// Create a document with request IP and current time of request // Create a document with request IP and current time of request
col.insert({ip: req.ip, date: Date.now()}); col.insert({ip: req.ip, date: Date.now()});
col.count(function(err, count){ col.count(function(err, count){
if (err) {
console.log('Error running count. Message:\n'+err);
}
res.render('index.html', { pageCountMessage : count, dbInfo: dbDetails }); res.render('index.html', { pageCountMessage : count, dbInfo: dbDetails });
}); });
} else { } else {

View file

@ -224,11 +224,11 @@ pre {
<section class='col-xs-12 col-sm-6 col-md-6'> <section class='col-xs-12 col-sm-6 col-md-6'>
<section> <section>
<h2>How to use this example application</h2> <h2>How to use this example application</h2>
<p>For instructions on how to use this application with OpenShift, start by reading the <a href="http://docs.okd.io/latest/dev_guide/templates.html#using-the-quickstart-templates">Developer Guide</a>.</p> <p>For instructions on how to use this application with OpenShift, start by reading the <a href="http://docs.openshift.org/latest/dev_guide/templates.html#using-the-quickstart-templates">Developer Guide</a>.</p>
<h2>Deploying code changes</h2> <h2>Deploying code changes</h2>
<p> <p>
The source code for this application is available to be forked from the <a href="https://www.github.com/sclorg/nodejs-ex">OpenShift GitHub repository</a>. The source code for this application is available to be forked from the <a href="https://www.github.com/openshift/nodejs-ex">OpenShift GitHub repository</a>.
You can configure a webhook in your repository to make OpenShift automatically start a build whenever you push your code: You can configure a webhook in your repository to make OpenShift automatically start a build whenever you push your code:
</p> </p>
@ -239,8 +239,7 @@ pre {
<li>Click the Configuration tab</li> <li>Click the Configuration tab</li>
<li>Click the "Copy to clipboard" icon to the right of the "GitHub webhook URL" field</li> <li>Click the "Copy to clipboard" icon to the right of the "GitHub webhook URL" field</li>
<li>Navigate to your repository on GitHub and click on repository settings &gt; webhooks &gt; Add webhook</li> <li>Navigate to your repository on GitHub and click on repository settings &gt; webhooks &gt; Add webhook</li>
<li>Paste your webhook URL provided by OpenShift in the "Payload URL" field</li> <li>Paste your webhook URL provided by OpenShift</li>
<li>Change the "Content type" to 'application/json'</li>
<li>Leave the defaults for the remaining fields &mdash; that's it!</li> <li>Leave the defaults for the remaining fields &mdash; that's it!</li>
</ol> </ol>
<p>After you save your webhook, if you refresh your settings page you can see the status of the ping that Github sent to OpenShift to verify it can reach the server.</p> <p>After you save your webhook, if you refresh your settings page you can see the status of the ping that Github sent to OpenShift to verify it can reach the server.</p>
@ -266,20 +265,20 @@ $ git push</pre>
<h2>Managing your application</h2> <h2>Managing your application</h2>
<p>Documentation on how to manage your application from the Web Console or Command Line is available at the <a href="http://docs.okd.io/latest/dev_guide/overview.html">Developer Guide</a>.</p> <p>Documentation on how to manage your application from the Web Console or Command Line is available at the <a href="http://docs.openshift.org/latest/dev_guide/overview.html">Developer Guide</a>.</p>
<h3>Web Console</h3> <h3>Web Console</h3>
<p>You can use the Web Console to view the state of your application components and launch new builds.</p> <p>You can use the Web Console to view the state of your application components and launch new builds.</p>
<h3>Command Line</h3> <h3>Command Line</h3>
<p>With the <a href="http://docs.okd.io/latest/cli_reference/overview.html">OpenShift command line interface</a> (CLI), you can create applications and manage projects from a terminal.</p> <p>With the <a href="http://docs.openshift.org/latest/cli_reference/overview.html">OpenShift command line interface</a> (CLI), you can create applications and manage projects from a terminal.</p>
<h2>Development Resources</h2> <h2>Development Resources</h2>
<ul> <ul>
<li><a href="http://docs.okd.io/latest/welcome/index.html">OpenShift Documentation</a></li> <li><a href="http://docs.openshift.org/latest/welcome/index.html">OpenShift Documentation</a></li>
<li><a href="https://github.com/openshift/origin">Openshift Origin GitHub</a></li> <li><a href="https://github.com/openshift/origin">Openshift Origin GitHub</a></li>
<li><a href="https://github.com/openshift/source-to-image">Source To Image GitHub</a></li> <li><a href="https://github.com/openshift/source-to-image">Source To Image GitHub</a></li>
<li><a href="http://docs.okd.io/latest/using_images/s2i_images/nodejs.html">Getting Started with Node.js on OpenShift</a></li> <li><a href="http://docs.openshift.org/latest/using_images/s2i_images/nodejs.html">Getting Started with Node.js on OpenShift</a></li>
<li><a href="http://stackoverflow.com/questions/tagged/openshift">Stack Overflow questions for OpenShift</a></li> <li><a href="http://stackoverflow.com/questions/tagged/openshift">Stack Overflow questions for OpenShift</a></li>
<li><a href="http://git-scm.com/documentation">Git documentation</a></li> <li><a href="http://git-scm.com/documentation">Git documentation</a></li>
</ul> </ul>