Compare commits
140 Commits
Author | SHA1 | Date |
---|---|---|
Honza Horak | e59fe7571f | |
liangxia | 38584bb52a | |
Honza Horak | 905416d88f | |
Honza Horak | f9a97276a0 | |
root | e56c06e04a | |
sspeiche | 5f15c1edb0 | |
Ben Parees | b078bcff2f | |
rubenhulzebos | 58e352aa69 | |
Honza Horak | e79929f0b6 | |
Adam Kaplan | 9b0e5f1539 | |
Ben Parees | 24e7e684ac | |
Gl4di4torRr | 0cb2d44935 | |
Honza Horak | a2aa814098 | |
Jan Wozniak | 003d0ac8d6 | |
Honza Horak | 8d138f94d7 | |
Ben Parees | d416548286 | |
Ben Parees | 93fc25fd35 | |
Dharmit Shah | dd9d5afa3b | |
Ben Parees | ef1b71a300 | |
Ali Ok | e8d39a4936 | |
Ben Parees | 5faaac6933 | |
Pavel Valena | e79d273ea5 | |
Ben Parees | debf979e0d | |
Jim Minter | c8e18b759c | |
Ben Parees | d1af14dc9f | |
gabemontero | 4759b1bf2d | |
Ben Parees | e598bfbe1f | |
Jim Minter | b84f207d3d | |
Ben Parees | 96e651f58a | |
Ben Parees | 8ac25c1e3c | |
Ben Parees | b9ba509aff | |
Jim Minter | d6a27c221f | |
Ben Parees | 44abae3f81 | |
Mordechai Weinberg | 64c46cb6ee | |
Ben Parees | 253f8095a9 | |
mordicool | 08397daddd | |
Ben Parees | eb75af97ef | |
Jim Minter | 5647b2a31c | |
Ben Parees | 7c814b0d2c | |
Jim Minter | 5ffcf0a43c | |
Ben Parees | 863b14eab0 | |
Corey Daley | 324865499e | |
Ben Parees | f12494cff0 | |
Corey Daley | 1a31042c81 | |
Ben Parees | 68b66caa93 | |
Jim Minter | 5d9081445f | |
Ben Parees | 3d44de3ba8 | |
Ben Parees | 9a913714c7 | |
Ben Parees | 95c092763d | |
Ben Parees | 814cde009f | |
Ben Parees | b8d7dd7328 | |
sspeiche | 6b92fdf4cd | |
Ben Parees | c1faa896c2 | |
Vu Dinh | 2631c4a95e | |
Ben Parees | e81cacfa03 | |
Ben Parees | 513d4703ad | |
Ben Parees | 7f7c9dd258 | |
Corey Daley | 214b5bb005 | |
Ben Parees | 36bb782477 | |
Ben Parees | fafa1c4893 | |
Ben Parees | 343689f74d | |
guangxuli | 3f51ad1438 | |
Ben Parees | 81e1afb25e | |
jupierce | 7d73fbd2a8 | |
Ben Parees | fb4415ce65 | |
Jim Minter | 4344883eb6 | |
Ben Parees | 69b359bdfc | |
luciddreamz | 572d5d4af1 | |
Ben Parees | 9ebc30eb44 | |
Sally O'Malley | 36aeea7271 | |
Jacob Lucky | 9457131bdb | |
Ionut Palade | 0e748ed338 | |
Ben Parees | e61190a1a1 | |
Ben Parees | 8b9463d1d4 | |
Ben Parees | b450b768b5 | |
Ben Parees | c984686993 | |
Vu Dinh | 325aaf4483 | |
Ben Parees | c56041b2c7 | |
Ben Parees | 3b643fc6bc | |
Ben Parees | 46537887f2 | |
gabemontero | 9a6db38edb | |
Ben Parees | f8edda4f04 | |
gabemontero | d8a485dbb7 | |
Ben Parees | 17ff3cdbce | |
gabemontero | c074be2189 | |
Ben Parees | 3f08ff2b61 | |
Ben Parees | eaed1b5e10 | |
Ben Parees | 21c5ab2cbf | |
PI-Victor | 1335e5640f | |
Ben Parees | 81f62ffe6a | |
Ben Parees | 4303514cc1 | |
brennv | 416e234522 | |
Ben Parees | ec380095d4 | |
Ben Parees | d3bfc8b240 | |
Ben Parees | 0e8b9b4009 | |
pi-victor | 4166119035 | |
Ben Parees | 6263b25a02 | |
gabemontero | bab042519e | |
Ben Parees | 02352585f8 | |
gabemontero | ee1068b426 | |
Ben Parees | c7f0e817af | |
gabemontero | 33d299b625 | |
Ben Parees | 155485968b | |
gabemontero | ee0de00cdf | |
Ben Parees | b17a07bf0a | |
Michal Fojtik | 6015715f91 | |
Ben Parees | 933ca6638c | |
gabemontero | 5aa4e30ad9 | |
Ben Parees | 34dafc6cdf | |
Ben Parees | 4efa27f2ac | |
Ben Parees | df1f4ae1c4 | |
Ben Parees | cafa1f4398 | |
Ben Parees | ca985b6d4b | |
Ben Parees | 7eef122c09 | |
Ben Parees | eb3e57d679 | |
Michal Fojtik | d9b1b3a154 | |
sspeiche | c9f8146151 | |
Ben Parees | bf57558da2 | |
Ben Parees | bb2d4ff9d4 | |
Michal Fojtik | 457a80a7be | |
Ben Parees | b10d0e8e1a | |
Ben Parees | 1b284ff6a5 | |
gabemontero | 1ca4fbfd5a | |
Ben Parees | c647e25455 | |
Ben Parees | b0a4206bbe | |
Clayton Coleman | 9204cad248 | |
Ben Parees | a4f2d9482e | |
Ben Parees | 605ce4e6a9 | |
Ben Parees | c2630834d2 | |
Ben Parees | 654a6bce07 | |
Rodolfo Carvalho | ea308ce51f | |
sspeiche | ddeacadac2 | |
Michal Fojtik | 9d30467d90 | |
Rodolfo Carvalho | c0a4e7bebb | |
Ben Parees | 970919d0cc | |
Martin Nagy | b6cf9e1cd4 | |
Ben Parees | 7484bd5cb1 | |
Rodolfo Carvalho | e3b78520d9 | |
Steve Speicher | 9c7c6c9578 | |
jhadvig | a4afe7cc93 |
|
@ -1 +1,2 @@
|
|||
/node_modules/
|
||||
/node_modules/
|
||||
npm-debug.log
|
250
README.md
250
README.md
|
@ -1,63 +1,253 @@
|
|||
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 an http response of various "machine" stats from the "machine" the Node.js app is running on to [http://host:8080](http://host:8080).
|
||||
This example will serve a welcome page and the current hit count as stored in a database.
|
||||
|
||||
### OpenShift setup ###
|
||||
### OpenShift Origin v3 setup
|
||||
|
||||
One possible option is to use the Docker all-in-one launch as described in the [origins project](https://github.com/openshift/origins).
|
||||
There are four methods to get started with OpenShift v3:
|
||||
|
||||
### The project ###
|
||||
- Running a virtual machine with Vagrant
|
||||
- Running a virtual machine managed by minishift
|
||||
- Starting a Docker container
|
||||
- Downloading the binary
|
||||
- Running an Ansible playbook
|
||||
|
||||
If you don't have a project setup all ready, go ahead and take care of that
|
||||
#### Running a virtual machine with Vagrant
|
||||
|
||||
$ osc new-project nodejs-echo --display-name="nodejs" --description="Sample Node.js app"
|
||||
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).
|
||||
|
||||
#### 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
|
||||
|
||||
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.
|
||||
|
||||
#### 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).
|
||||
|
||||
#### 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.
|
||||
|
||||
|
||||
### Creating a project
|
||||
|
||||
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 \
|
||||
--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:
|
||||
|
||||
$ osc project nodejs
|
||||
$ oc project nodejs-echo
|
||||
|
||||
### The app ###
|
||||
### Creating new apps
|
||||
|
||||
Now let's pull in the app source code from [GitHub repo](https://github.com/openshift/nodejs-ex) (fork if you like)
|
||||
You can create a new OpenShift application using the web console or by running the `oc new-app` command from the CLI. With the OpenShift CLI there are three ways to create a new application, by specifying either:
|
||||
|
||||
#### create ####
|
||||
- [source code](https://docs.openshift.com/enterprise/3.0/dev_guide/new_app.html#specifying-source-code)
|
||||
- [OpenShift templates](https://docs.openshift.com/enterprise/3.0/dev_guide/new_app.html#specifying-a-template)
|
||||
- [DockerHub images](https://docs.openshift.com/enterprise/3.0/dev_guide/new_app.html#specifying-an-image)
|
||||
|
||||
$ osc new-app https://github.com/openshift/nodejs-ex
|
||||
|
||||
That should be it, `new-app` will take care of creating the right build configuration, deployment configuration and service definition. Next you'll be able to kick off the build.
|
||||
#### Create a new app from source code (method 1)
|
||||
|
||||
Note, you can follow along with the web console (located at https://ip-address:8443/console) to see what new resources have been created and watch the progress of the build and deployment.
|
||||
Pointing `oc new-app` at source code kicks off a chain of events, for our example run:
|
||||
|
||||
#### build ####
|
||||
$ oc new-app https://github.com/sclorg/nodejs-ex -l name=myapp
|
||||
|
||||
$ osc start-build nodejs --follow
|
||||
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.
|
||||
|
||||
You can alternatively leave off `--follow` and use `osc build-logs nodejs-n` where n is the number of the build (output of start-build).
|
||||
(The -l flag will apply a label of "name=myapp" to all the resources created by new-app, for easy management later.)
|
||||
|
||||
#### deploy ####
|
||||
#### Create a new app from a template (method 2)
|
||||
|
||||
happens automatically, to monitor its status either watch the web console or `osc get pods` to see when the pod is up. Another helpful command is
|
||||
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).
|
||||
|
||||
$ osc status
|
||||
$ git clone https://github.com/sclorg/nodejs-ex
|
||||
|
||||
This will help indicate what IP address the service is running, the default port for it to deploy at is 8080.
|
||||
Looking at the repo, you'll notice three files in the openshift/template directory:
|
||||
|
||||
#### enjoy ####
|
||||
nodejs-ex
|
||||
├── openshift
|
||||
│ └── templates
|
||||
│ ├── nodejs.json
|
||||
│ ├── nodejs-mongodb.json
|
||||
│ └── nodejs-mongodb-persistent.json
|
||||
├── package.json
|
||||
├── README.md
|
||||
├── server.js
|
||||
├── tests
|
||||
│ └── app_test.js
|
||||
└── views
|
||||
└── index.html
|
||||
|
||||
Run/test our app by simply doing an HTTP GET request
|
||||
We can create the the new app from the `nodejs.json` template by using the `-f` flag and pointing the tool at a path to the template file:
|
||||
|
||||
$ curl ip-address:8080
|
||||
$ oc new-app -f /path/to/nodejs.json
|
||||
|
||||
#### update ####
|
||||
#### Build the app
|
||||
|
||||
Assuming you used the URL of your own forked report, we can easily push changes to that hosted repo and simply repeat the steps above to build (this is obviously just demonstrating the manually kicking off of builds) which will trigger the new built image to be deployed.
|
||||
`oc new-app` will kick off a build once all required dependencies are confirmed.
|
||||
|
||||
### Web UI ###
|
||||
Check the status of your new nodejs app with the command:
|
||||
|
||||
To run this example from the Web UI, you can same steps following done on the CLI as defined above by [The project](#the-project). Here's a video showing it in motion:
|
||||
$ oc status
|
||||
|
||||
Which should return something like:
|
||||
|
||||
In project nodejs (nodejs-echo) on server https://10.2.2.2:8443
|
||||
|
||||
svc/nodejs-ex - 172.30.108.183:8080
|
||||
dc/nodejs-ex deploys istag/nodejs-ex:latest <-
|
||||
bc/nodejs-ex builds https://github.com/sclorg/nodejs-ex with openshift/nodejs:0.10
|
||||
build #1 running for 7 seconds
|
||||
deployment #1 waiting on image or update
|
||||
|
||||
Note the server address for the web console, as yours will likely differ if you're not using the Vagrant set-up. You can follow along with the web console to see what new resources have been created and watch the progress of builds and deployments.
|
||||
|
||||
If the build is not yet started (you can check by running `oc get builds`), start one and stream the logs with:
|
||||
|
||||
$ oc start-build nodejs-ex --follow
|
||||
|
||||
You can alternatively leave off `--follow` and use `oc logs build/nodejs-ex-n` where *n* is the number of the build to track the output of the build.
|
||||
|
||||
#### Deploy the app
|
||||
|
||||
Deployment happens automatically once the new application image is available. To monitor its status either watch the web console or execute `oc get pods` to see when the pod is up. Another helpful command is
|
||||
|
||||
$ oc get svc
|
||||
|
||||
This will help indicate what IP address the service is running, the default port for it to deploy at is 8080. Output should look like:
|
||||
|
||||
NAME CLUSTER-IP EXTERNAL-IP PORT(S) SELECTOR AGE
|
||||
nodejs-ex 172.30.249.251 <none> 8080/TCP deploymentconfig=nodejs-ex,name=myapp 17m
|
||||
|
||||
#### Configure routing
|
||||
|
||||
An OpenShift route exposes a service at a host name, like www.example.com, so that external clients can reach it by name.
|
||||
|
||||
DNS resolution for a host name is handled separately from routing; you may wish to configure a cloud domain that will always correctly resolve to the OpenShift router, or if using an unrelated host name you may need to modify its DNS records independently to resolve to the router.
|
||||
|
||||
That aside, let's explore our new web console, which for our example is running at [https://10.2.2.2:8443](https://10.2.2.2:8443).
|
||||
|
||||
After logging into the web console with your same CLI `oc login` credentials, click on the project we just created, then click `Create route`.
|
||||
|
||||
If you're running OpenShift on a local machine, you can preview the new app by setting the Hostname to a localhost like: *10.2.2.2*.
|
||||
|
||||
This could also be accomplished by running:
|
||||
|
||||
$ oc expose svc/nodejs-ex --hostname=www.example.com
|
||||
|
||||
Now navigate to the newly created Node.js web app at the hostname we just configured, for our example it was simply [https://10.2.2.2](https://10.2.2.2).
|
||||
|
||||
#### Create a new app from an image (method 3)
|
||||
|
||||
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 \
|
||||
-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.
|
||||
|
||||
Running `oc status` or checking the web console will reveal the address of the newly created MongoDB:
|
||||
|
||||
In project nodejs-echo on server https://10.2.2.2:8443
|
||||
|
||||
svc/mongodb-26-centos7 - 172.30.0.112:27017
|
||||
dc/mongodb-26-centos7 deploys istag/mongodb-26-centos7:latest
|
||||
deployment #1 running for 43 seconds - 1 pod
|
||||
|
||||
http://10.2.2.2 to pod port 8080-tcp (svc/nodejs-ex)
|
||||
dc/nodejs-ex deploys istag/nodejs-ex:latest <-
|
||||
bc/nodejs-ex builds https://github.com/sclorg/nodejs-ex with openshift/nodejs:0.10
|
||||
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.
|
||||
|
||||
#### Setting environment variables
|
||||
|
||||
To take a look at environment variables set for each pod, run `oc env pods --all --list`.
|
||||
|
||||
We need to add the environment variable `MONGO_URL` to our Node.js web app so that it will utilize our MongoDB, and enable the "Page view count" feature. Run:
|
||||
|
||||
$ oc set env dc/nodejs-ex MONGO_URL='mongodb://admin:secret@172.30.0.112:27017/mongo_db'
|
||||
|
||||
Then check `oc status` to see that an updated deployment has been kicked off:
|
||||
|
||||
In project nodejs-echo on server https://10.2.2.2:8443
|
||||
|
||||
svc/mongodb-26-centos7 - 172.30.0.112:27017
|
||||
dc/mongodb-26-centos7 deploys istag/mongodb-26-centos7:latest
|
||||
deployment #1 deployed 2 hours ago - 1 pod
|
||||
|
||||
http://10.2.2.2 to pod port 8080-tcp (svc/nodejs-ex)
|
||||
dc/nodejs-ex deploys istag/nodejs-ex:latest <-
|
||||
bc/nodejs-ex builds https://github.com/sclorg/nodejs-ex with openshift/nodejs:0.10
|
||||
deployment #2 deployed about a minute ago - 1 pod
|
||||
deployment #1 deployed 2 hours ago
|
||||
|
||||
#### Success
|
||||
|
||||
You should now have a Node.js welcome page showing the current hit count, as stored in a MongoDB database.
|
||||
|
||||
#### Pushing updates
|
||||
|
||||
Assuming you used the URL of your own forked repository, we can easily push changes and simply repeat the steps above which will trigger the newly built image to be deployed.
|
||||
|
||||
### Debugging
|
||||
|
||||
Review some of the common tips and suggestions [here](https://github.com/openshift/origin/blob/master/docs/debugging-openshift.md).
|
||||
|
||||
### Web UI
|
||||
|
||||
To run this example from the Web UI, you can same steps following done on the CLI as defined above. Here's a video showing it in motion:
|
||||
|
||||
<a href="http://www.youtube.com/watch?feature=player_embedded&v=uocucZqg_0I&t=225" target="_blank">
|
||||
<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>
|
||||
|
||||
### 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.
|
||||
|
||||
### Compatibility
|
||||
|
||||
This repository is compatible with Node.js 4 and higher, excluding any alpha or beta versions.
|
||||
|
||||
### 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/).
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
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
|
|
@ -0,0 +1,3 @@
|
|||
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.
|
|
@ -0,0 +1,38 @@
|
|||
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
|
|
@ -0,0 +1,49 @@
|
|||
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 }}
|
|
@ -0,0 +1,6 @@
|
|||
kind: ImageStream
|
||||
apiVersion: image.openshift.io/v1
|
||||
metadata:
|
||||
name: {{ .Values.name | quote }}
|
||||
annotations:
|
||||
description: Keeps track of changes in the application image
|
|
@ -0,0 +1,9 @@
|
|||
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 }}
|
|
@ -0,0 +1,13 @@
|
|||
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 }}
|
|
@ -0,0 +1,20 @@
|
|||
# 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:
|
|
@ -0,0 +1,6 @@
|
|||
node('nodejs') {
|
||||
stage 'build'
|
||||
openshiftBuild(buildConfig: 'nodejs-ex', showBuildLogs: 'true')
|
||||
stage 'deploy'
|
||||
openshiftDeploy(deploymentConfig: 'nodejs-ex')
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
This directory contains a Jenkinsfile which can be used to build
|
||||
nodejs-ex using an OpenShift build pipeline.
|
||||
|
||||
To do this, run:
|
||||
|
||||
```bash
|
||||
# create the nodejs example as usual
|
||||
oc new-app https://github.com/sclorg/nodejs-ex
|
||||
|
||||
# now create the pipeline build controller from the openshift/pipeline
|
||||
# subdirectory
|
||||
oc new-app https://github.com/sclorg/nodejs-ex \
|
||||
--context-dir=openshift/pipeline --name nodejs-ex-pipeline
|
||||
```
|
|
@ -0,0 +1,563 @@
|
|||
{
|
||||
"kind": "Template",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nodejs-mongo-persistent",
|
||||
"annotations": {
|
||||
"openshift.io/display-name": "Node.js + MongoDB",
|
||||
"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.",
|
||||
"tags": "quickstart,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.",
|
||||
"openshift.io/provider-display-name": "Red Hat, Inc.",
|
||||
"openshift.io/documentation-url": "https://github.com/sclorg/nodejs-ex",
|
||||
"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.",
|
||||
"labels": {
|
||||
"template": "nodejs-mongo-persistent"
|
||||
},
|
||||
"objects": [
|
||||
{
|
||||
"kind": "Secret",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}"
|
||||
},
|
||||
"stringData": {
|
||||
"database-user": "${DATABASE_USER}",
|
||||
"database-password": "${DATABASE_PASSWORD}",
|
||||
"database-admin-password" : "${DATABASE_ADMIN_PASSWORD}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Exposes and load balances the application pods",
|
||||
"service.alpha.openshift.io/dependencies": "[{\"name\": \"${DATABASE_SERVICE_NAME}\", \"kind\": \"Service\"}]"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "web",
|
||||
"port": 8080,
|
||||
"targetPort": 8080
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"name": "${NAME}"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Route",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}"
|
||||
},
|
||||
"spec": {
|
||||
"host": "${APPLICATION_DOMAIN}",
|
||||
"to": {
|
||||
"kind": "Service",
|
||||
"name": "${NAME}"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "ImageStream",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Keeps track of changes in the application image"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "BuildConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Defines how to build the application",
|
||||
"template.alpha.openshift.io/wait-for-ready": "true"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"source": {
|
||||
"type": "Git",
|
||||
"git": {
|
||||
"uri": "${SOURCE_REPOSITORY_URL}",
|
||||
"ref": "${SOURCE_REPOSITORY_REF}"
|
||||
},
|
||||
"contextDir": "${CONTEXT_DIR}"
|
||||
},
|
||||
"strategy": {
|
||||
"type": "Source",
|
||||
"sourceStrategy": {
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"namespace": "${NAMESPACE}",
|
||||
"name": "nodejs:${NODEJS_VERSION}"
|
||||
},
|
||||
"env": [
|
||||
{
|
||||
"name": "NPM_MIRROR",
|
||||
"value": "${NPM_MIRROR}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"output": {
|
||||
"to": {
|
||||
"kind": "ImageStreamTag",
|
||||
"name": "${NAME}:latest"
|
||||
}
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ImageChange"
|
||||
},
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
},
|
||||
{
|
||||
"type": "GitHub",
|
||||
"github": {
|
||||
"secret": "${GITHUB_WEBHOOK_SECRET}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Generic",
|
||||
"generic": {
|
||||
"secret": "${GENERIC_WEBHOOK_SECRET}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"postCommit": {
|
||||
"script": "npm test"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "DeploymentConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Defines how to deploy the application server",
|
||||
"template.alpha.openshift.io/wait-for-ready": "true"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ImageChange",
|
||||
"imageChangeParams": {
|
||||
"automatic": true,
|
||||
"containerNames": [
|
||||
"nodejs-mongo-persistent"
|
||||
],
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"name": "${NAME}:latest"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
}
|
||||
],
|
||||
"replicas": 1,
|
||||
"selector": {
|
||||
"name": "${NAME}"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"labels": {
|
||||
"name": "${NAME}"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"name": "nodejs-mongo-persistent",
|
||||
"image": " ",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 8080
|
||||
}
|
||||
],
|
||||
"env": [
|
||||
{
|
||||
"name": "DATABASE_SERVICE_NAME",
|
||||
"value": "${DATABASE_SERVICE_NAME}"
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_USER",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-user"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_PASSWORD",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-password"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_DATABASE",
|
||||
"value": "${DATABASE_NAME}"
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_ADMIN_PASSWORD",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-admin-password"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"readinessProbe": {
|
||||
"timeoutSeconds": 3,
|
||||
"initialDelaySeconds": 3,
|
||||
"httpGet": {
|
||||
"path": "/",
|
||||
"port": 8080
|
||||
}
|
||||
},
|
||||
"livenessProbe": {
|
||||
"timeoutSeconds": 3,
|
||||
"initialDelaySeconds": 30,
|
||||
"httpGet": {
|
||||
"path": "/",
|
||||
"port": 8080
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
"limits": {
|
||||
"memory": "${MEMORY_LIMIT}"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "PersistentVolumeClaim",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${DATABASE_SERVICE_NAME}"
|
||||
},
|
||||
"spec": {
|
||||
"accessModes": [
|
||||
"ReadWriteOnce"
|
||||
],
|
||||
"resources": {
|
||||
"requests": {
|
||||
"storage": "${VOLUME_CAPACITY}"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${DATABASE_SERVICE_NAME}",
|
||||
"annotations": {
|
||||
"description": "Exposes the database server"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "mongodb",
|
||||
"port": 27017,
|
||||
"targetPort": 27017
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"name": "${DATABASE_SERVICE_NAME}"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "DeploymentConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${DATABASE_SERVICE_NAME}",
|
||||
"annotations": {
|
||||
"description": "Defines how to deploy the database",
|
||||
"template.alpha.openshift.io/wait-for-ready": "true"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ImageChange",
|
||||
"imageChangeParams": {
|
||||
"automatic": true,
|
||||
"containerNames": [
|
||||
"mongodb"
|
||||
],
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"namespace": "${NAMESPACE}",
|
||||
"name": "mongodb:${MONGODB_VERSION}"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
}
|
||||
],
|
||||
"replicas": 1,
|
||||
"selector": {
|
||||
"name": "${DATABASE_SERVICE_NAME}"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"name": "${DATABASE_SERVICE_NAME}",
|
||||
"labels": {
|
||||
"name": "${DATABASE_SERVICE_NAME}"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"name": "mongodb",
|
||||
"image": " ",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 27017
|
||||
}
|
||||
],
|
||||
"env": [
|
||||
{
|
||||
"name": "MONGODB_USER",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-user"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_PASSWORD",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-password"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_DATABASE",
|
||||
"value": "${DATABASE_NAME}"
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_ADMIN_PASSWORD",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-admin-password"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"readinessProbe": {
|
||||
"timeoutSeconds": 1,
|
||||
"initialDelaySeconds": 3,
|
||||
"exec": {
|
||||
"command": [
|
||||
"/bin/sh",
|
||||
"-i",
|
||||
"-c",
|
||||
"mongo 127.0.0.1:27017/$MONGODB_DATABASE -u $MONGODB_USER -p $MONGODB_PASSWORD --eval=\"quit()\""
|
||||
]
|
||||
}
|
||||
},
|
||||
"livenessProbe": {
|
||||
"timeoutSeconds": 1,
|
||||
"initialDelaySeconds": 30,
|
||||
"tcpSocket": {
|
||||
"port": 27017
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
"limits": {
|
||||
"memory": "${MEMORY_MONGODB_LIMIT}"
|
||||
}
|
||||
},
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "${DATABASE_SERVICE_NAME}-data",
|
||||
"mountPath": "/var/lib/mongodb/data"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "${DATABASE_SERVICE_NAME}-data",
|
||||
"persistentVolumeClaim": {
|
||||
"claimName": "${DATABASE_SERVICE_NAME}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "NAME",
|
||||
"displayName": "Name",
|
||||
"description": "The name assigned to all of the frontend objects defined in this template.",
|
||||
"required": true,
|
||||
"value": "nodejs-mongo-persistent"
|
||||
},
|
||||
{
|
||||
"name": "NAMESPACE",
|
||||
"displayName": "Namespace",
|
||||
"description": "The OpenShift Namespace where the ImageStream resides.",
|
||||
"required": true,
|
||||
"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",
|
||||
"displayName": "Memory Limit",
|
||||
"description": "Maximum amount of memory the Node.js container can use.",
|
||||
"required": true,
|
||||
"value": "512Mi"
|
||||
},
|
||||
{
|
||||
"name": "MEMORY_MONGODB_LIMIT",
|
||||
"displayName": "Memory Limit (MongoDB)",
|
||||
"description": "Maximum amount of memory the MongoDB container can use.",
|
||||
"required": true,
|
||||
"value": "512Mi"
|
||||
},
|
||||
{
|
||||
"name": "VOLUME_CAPACITY",
|
||||
"displayName": "Volume Capacity",
|
||||
"description": "Volume space available for data, e.g. 512Mi, 2Gi",
|
||||
"value": "1Gi",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "SOURCE_REPOSITORY_URL",
|
||||
"displayName": "Git Repository URL",
|
||||
"description": "The URL of the repository with your application source code.",
|
||||
"required": true,
|
||||
"value": "https://github.com/sclorg/nodejs-ex.git"
|
||||
},
|
||||
{
|
||||
"name": "SOURCE_REPOSITORY_REF",
|
||||
"displayName": "Git Reference",
|
||||
"description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch."
|
||||
},
|
||||
{
|
||||
"name": "CONTEXT_DIR",
|
||||
"displayName": "Context Directory",
|
||||
"description": "Set this to the relative path to your project if it is not in the root of your repository."
|
||||
},
|
||||
{
|
||||
"name": "APPLICATION_DOMAIN",
|
||||
"displayName": "Application Hostname",
|
||||
"description": "The exposed hostname that will route to the Node.js service, if left blank a value will be defaulted.",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "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.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{40}"
|
||||
},
|
||||
{
|
||||
"name": "GENERIC_WEBHOOK_SECRET",
|
||||
"displayName": "Generic Webhook Secret",
|
||||
"description": "A secret string used to configure the Generic webhook.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{40}"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_SERVICE_NAME",
|
||||
"displayName": "Database Service Name",
|
||||
"required": true,
|
||||
"value": "mongodb"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_USER",
|
||||
"displayName": "MongoDB Username",
|
||||
"description": "Username for MongoDB user that will be used for accessing the database.",
|
||||
"generate": "expression",
|
||||
"from": "user[A-Z0-9]{3}"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_PASSWORD",
|
||||
"displayName": "MongoDB Password",
|
||||
"description": "Password for the MongoDB user.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{16}"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_NAME",
|
||||
"displayName": "Database Name",
|
||||
"required": true,
|
||||
"value": "sampledb"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_ADMIN_PASSWORD",
|
||||
"displayName": "Database Administrator Password",
|
||||
"description": "Password for the database admin user.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{16}"
|
||||
},
|
||||
{
|
||||
"name": "NPM_MIRROR",
|
||||
"displayName": "Custom NPM Mirror URL",
|
||||
"description": "The custom NPM mirror URL",
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,540 @@
|
|||
{
|
||||
"kind": "Template",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nodejs-mongodb-example",
|
||||
"annotations": {
|
||||
"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.",
|
||||
"tags": "quickstart,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.",
|
||||
"openshift.io/provider-display-name": "Red Hat, Inc.",
|
||||
"openshift.io/documentation-url": "https://github.com/sclorg/nodejs-ex",
|
||||
"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.",
|
||||
"labels": {
|
||||
"template": "nodejs-mongodb-example",
|
||||
"app": "nodejs-mongodb-example"
|
||||
},
|
||||
"objects": [
|
||||
{
|
||||
"kind": "Secret",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}"
|
||||
},
|
||||
"stringData": {
|
||||
"database-user": "${DATABASE_USER}",
|
||||
"database-password": "${DATABASE_PASSWORD}",
|
||||
"database-admin-password" : "${DATABASE_ADMIN_PASSWORD}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Exposes and load balances the application pods",
|
||||
"service.alpha.openshift.io/dependencies": "[{\"name\": \"${DATABASE_SERVICE_NAME}\", \"kind\": \"Service\"}]"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "web",
|
||||
"port": 8080,
|
||||
"targetPort": 8080
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"name": "${NAME}"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Route",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}"
|
||||
},
|
||||
"spec": {
|
||||
"host": "${APPLICATION_DOMAIN}",
|
||||
"to": {
|
||||
"kind": "Service",
|
||||
"name": "${NAME}"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "ImageStream",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Keeps track of changes in the application image"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "BuildConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Defines how to build the application",
|
||||
"template.alpha.openshift.io/wait-for-ready": "true"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"source": {
|
||||
"type": "Git",
|
||||
"git": {
|
||||
"uri": "${SOURCE_REPOSITORY_URL}",
|
||||
"ref": "${SOURCE_REPOSITORY_REF}"
|
||||
},
|
||||
"contextDir": "${CONTEXT_DIR}"
|
||||
},
|
||||
"strategy": {
|
||||
"type": "Source",
|
||||
"sourceStrategy": {
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"namespace": "${NAMESPACE}",
|
||||
"name": "nodejs:${NODEJS_VERSION}"
|
||||
},
|
||||
"env": [
|
||||
{
|
||||
"name": "NPM_MIRROR",
|
||||
"value": "${NPM_MIRROR}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"output": {
|
||||
"to": {
|
||||
"kind": "ImageStreamTag",
|
||||
"name": "${NAME}:latest"
|
||||
}
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ImageChange"
|
||||
},
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
},
|
||||
{
|
||||
"type": "GitHub",
|
||||
"github": {
|
||||
"secret": "${GITHUB_WEBHOOK_SECRET}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Generic",
|
||||
"generic": {
|
||||
"secret": "${GENERIC_WEBHOOK_SECRET}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"postCommit": {
|
||||
"script": "npm test"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "DeploymentConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Defines how to deploy the application server",
|
||||
"template.alpha.openshift.io/wait-for-ready": "true"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ImageChange",
|
||||
"imageChangeParams": {
|
||||
"automatic": true,
|
||||
"containerNames": [
|
||||
"nodejs-mongodb-example"
|
||||
],
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"name": "${NAME}:latest"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
}
|
||||
],
|
||||
"replicas": 1,
|
||||
"selector": {
|
||||
"name": "${NAME}"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"name": "${NAME}",
|
||||
"labels": {
|
||||
"name": "${NAME}"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"name": "nodejs-mongodb-example",
|
||||
"image": " ",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 8080
|
||||
}
|
||||
],
|
||||
"env": [
|
||||
{
|
||||
"name": "DATABASE_SERVICE_NAME",
|
||||
"value": "${DATABASE_SERVICE_NAME}"
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_USER",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-user"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_PASSWORD",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-password"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_DATABASE",
|
||||
"value": "${DATABASE_NAME}"
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_ADMIN_PASSWORD",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-admin-password"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"readinessProbe": {
|
||||
"timeoutSeconds": 3,
|
||||
"initialDelaySeconds": 3,
|
||||
"httpGet": {
|
||||
"path": "/",
|
||||
"port": 8080
|
||||
}
|
||||
},
|
||||
"livenessProbe": {
|
||||
"timeoutSeconds": 3,
|
||||
"initialDelaySeconds": 30,
|
||||
"httpGet": {
|
||||
"path": "/",
|
||||
"port": 8080
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
"limits": {
|
||||
"memory": "${MEMORY_LIMIT}"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${DATABASE_SERVICE_NAME}",
|
||||
"annotations": {
|
||||
"description": "Exposes the database server"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"ports": [
|
||||
{
|
||||
"name": "mongodb",
|
||||
"port": 27017,
|
||||
"targetPort": 27017
|
||||
}
|
||||
],
|
||||
"selector": {
|
||||
"name": "${DATABASE_SERVICE_NAME}"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "DeploymentConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "${DATABASE_SERVICE_NAME}",
|
||||
"annotations": {
|
||||
"description": "Defines how to deploy the database",
|
||||
"template.alpha.openshift.io/wait-for-ready": "true"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ImageChange",
|
||||
"imageChangeParams": {
|
||||
"automatic": true,
|
||||
"containerNames": [
|
||||
"mongodb"
|
||||
],
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"namespace": "${NAMESPACE}",
|
||||
"name": "mongodb:${MONGODB_VERSION}"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
}
|
||||
],
|
||||
"replicas": 1,
|
||||
"selector": {
|
||||
"name": "${DATABASE_SERVICE_NAME}"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"name": "${DATABASE_SERVICE_NAME}",
|
||||
"labels": {
|
||||
"name": "${DATABASE_SERVICE_NAME}"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"name": "mongodb",
|
||||
"image": " ",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 27017
|
||||
}
|
||||
],
|
||||
"env": [
|
||||
{
|
||||
"name": "MONGODB_USER",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-user"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_PASSWORD",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-password"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_DATABASE",
|
||||
"value": "${DATABASE_NAME}"
|
||||
},
|
||||
{
|
||||
"name": "MONGODB_ADMIN_PASSWORD",
|
||||
"valueFrom": {
|
||||
"secretKeyRef" : {
|
||||
"name" : "${NAME}",
|
||||
"key" : "database-admin-password"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"readinessProbe": {
|
||||
"timeoutSeconds": 1,
|
||||
"initialDelaySeconds": 3,
|
||||
"exec": {
|
||||
"command": [
|
||||
"/bin/sh",
|
||||
"-i",
|
||||
"-c",
|
||||
"mongo 127.0.0.1:27017/$MONGODB_DATABASE -u $MONGODB_USER -p $MONGODB_PASSWORD --eval=\"quit()\""
|
||||
]
|
||||
}
|
||||
},
|
||||
"livenessProbe": {
|
||||
"timeoutSeconds": 1,
|
||||
"initialDelaySeconds": 30,
|
||||
"tcpSocket": {
|
||||
"port": 27017
|
||||
}
|
||||
},
|
||||
"resources": {
|
||||
"limits": {
|
||||
"memory": "${MEMORY_MONGODB_LIMIT}"
|
||||
}
|
||||
},
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "${DATABASE_SERVICE_NAME}-data",
|
||||
"mountPath": "/var/lib/mongodb/data"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "${DATABASE_SERVICE_NAME}-data",
|
||||
"emptyDir": {
|
||||
"medium": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "NAME",
|
||||
"displayName": "Name",
|
||||
"description": "The name assigned to all of the frontend objects defined in this template.",
|
||||
"required": true,
|
||||
"value": "nodejs-mongodb-example"
|
||||
},
|
||||
{
|
||||
"name": "NAMESPACE",
|
||||
"displayName": "Namespace",
|
||||
"description": "The OpenShift Namespace where the ImageStream resides.",
|
||||
"required": true,
|
||||
"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",
|
||||
"displayName": "Memory Limit",
|
||||
"description": "Maximum amount of memory the Node.js container can use.",
|
||||
"required": true,
|
||||
"value": "512Mi"
|
||||
},
|
||||
{
|
||||
"name": "MEMORY_MONGODB_LIMIT",
|
||||
"displayName": "Memory Limit (MongoDB)",
|
||||
"description": "Maximum amount of memory the MongoDB container can use.",
|
||||
"required": true,
|
||||
"value": "512Mi"
|
||||
},
|
||||
{
|
||||
"name": "SOURCE_REPOSITORY_URL",
|
||||
"displayName": "Git Repository URL",
|
||||
"description": "The URL of the repository with your application source code.",
|
||||
"required": true,
|
||||
"value": "https://github.com/sclorg/nodejs-ex.git"
|
||||
},
|
||||
{
|
||||
"name": "SOURCE_REPOSITORY_REF",
|
||||
"displayName": "Git Reference",
|
||||
"description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch."
|
||||
},
|
||||
{
|
||||
"name": "CONTEXT_DIR",
|
||||
"displayName": "Context Directory",
|
||||
"description": "Set this to the relative path to your project if it is not in the root of your repository."
|
||||
},
|
||||
{
|
||||
"name": "APPLICATION_DOMAIN",
|
||||
"displayName": "Application Hostname",
|
||||
"description": "The exposed hostname that will route to the Node.js service, if left blank a value will be defaulted.",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "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.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{40}"
|
||||
},
|
||||
{
|
||||
"name": "GENERIC_WEBHOOK_SECRET",
|
||||
"displayName": "Generic Webhook Secret",
|
||||
"description": "A secret string used to configure the Generic webhook.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{40}"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_SERVICE_NAME",
|
||||
"displayName": "Database Service Name",
|
||||
"required": true,
|
||||
"value": "mongodb"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_USER",
|
||||
"displayName": "MongoDB Username",
|
||||
"description": "Username for MongoDB user that will be used for accessing the database.",
|
||||
"generate": "expression",
|
||||
"from": "user[A-Z0-9]{3}"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_PASSWORD",
|
||||
"displayName": "MongoDB Password",
|
||||
"description": "Password for the MongoDB user.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{16}"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_NAME",
|
||||
"displayName": "Database Name",
|
||||
"required": true,
|
||||
"value": "sampledb"
|
||||
},
|
||||
{
|
||||
"name": "DATABASE_ADMIN_PASSWORD",
|
||||
"displayName": "Database Administrator Password",
|
||||
"description": "Password for the database admin user.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{16}"
|
||||
},
|
||||
{
|
||||
"name": "NPM_MIRROR",
|
||||
"displayName": "Custom NPM Mirror URL",
|
||||
"description": "The custom NPM mirror URL",
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
|
@ -4,20 +4,28 @@
|
|||
"metadata": {
|
||||
"name": "nodejs-example",
|
||||
"annotations": {
|
||||
"description": "An example Node.js application with no database",
|
||||
"tags": "instant-app,nodejs",
|
||||
"iconClass": "icon-nodejs"
|
||||
"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.",
|
||||
"tags": "quickstart,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.",
|
||||
"openshift.io/provider-display-name": "Red Hat, Inc.",
|
||||
"openshift.io/documentation-url": "https://github.com/sclorg/nodejs-ex",
|
||||
"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.",
|
||||
"labels": {
|
||||
"template": "nodejs-example"
|
||||
"template": "nodejs-example",
|
||||
"app": "nodejs-example"
|
||||
},
|
||||
"objects": [
|
||||
{
|
||||
"kind": "Service",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nodejs-frontend",
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Exposes and load balances the application pods"
|
||||
}
|
||||
|
@ -31,7 +39,7 @@
|
|||
}
|
||||
],
|
||||
"selector": {
|
||||
"name": "nodejs-frontend"
|
||||
"name": "${NAME}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -39,13 +47,13 @@
|
|||
"kind": "Route",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nodejs-route"
|
||||
"name": "${NAME}"
|
||||
},
|
||||
"spec": {
|
||||
"host": "${APPLICATION_DOMAIN}",
|
||||
"to": {
|
||||
"kind": "Service",
|
||||
"name": "nodejs-frontend"
|
||||
"name": "${NAME}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -53,7 +61,7 @@
|
|||
"kind": "ImageStream",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nodejs-example",
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Keeps track of changes in the application image"
|
||||
}
|
||||
|
@ -63,9 +71,10 @@
|
|||
"kind": "BuildConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nodejs-example",
|
||||
"name": "${NAME}",
|
||||
"annotations": {
|
||||
"description": "Defines how to build the application"
|
||||
"description": "Defines how to build the application",
|
||||
"template.alpha.openshift.io/wait-for-ready": "true"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
|
@ -82,37 +91,56 @@
|
|||
"sourceStrategy": {
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"namespace": "openshift",
|
||||
"name": "nodejs:0.10"
|
||||
}
|
||||
"namespace": "${NAMESPACE}",
|
||||
"name": "nodejs:${NODEJS_VERSION}"
|
||||
},
|
||||
"env": [
|
||||
{
|
||||
"name": "NPM_MIRROR",
|
||||
"value": "${NPM_MIRROR}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"output": {
|
||||
"to": {
|
||||
"kind": "ImageStreamTag",
|
||||
"name": "nodejs-example:latest"
|
||||
"name": "${NAME}:latest"
|
||||
}
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
"type": "ImageChange"
|
||||
},
|
||||
{
|
||||
"type": "ConfigChange"
|
||||
},
|
||||
{
|
||||
"type": "GitHub",
|
||||
"github": {
|
||||
"secret": "${GITHUB_WEBHOOK_SECRET}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Generic",
|
||||
"generic": {
|
||||
"secret": "${GENERIC_WEBHOOK_SECRET}"
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"postCommit": {
|
||||
"script": "npm test"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "DeploymentConfig",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "nodejs-frontend",
|
||||
"name": "${NAME}",
|
||||
"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": {
|
||||
|
@ -129,7 +157,7 @@
|
|||
],
|
||||
"from": {
|
||||
"kind": "ImageStreamTag",
|
||||
"name": "nodejs-example:latest"
|
||||
"name": "${NAME}:latest"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -139,24 +167,47 @@
|
|||
],
|
||||
"replicas": 1,
|
||||
"selector": {
|
||||
"name": "nodejs-frontend"
|
||||
"name": "${NAME}"
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"name": "nodejs-frontend",
|
||||
"name": "${NAME}",
|
||||
"labels": {
|
||||
"name": "nodejs-frontend"
|
||||
"name": "${NAME}"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"name": "nodejs-example",
|
||||
"image": "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": "${MEMORY_LIMIT}"
|
||||
}
|
||||
},
|
||||
"env": [
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -166,29 +217,76 @@
|
|||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "NAME",
|
||||
"displayName": "Name",
|
||||
"description": "The name assigned to all of the frontend objects defined in this template.",
|
||||
"required": true,
|
||||
"value": "nodejs-example"
|
||||
},
|
||||
{
|
||||
"name": "NAMESPACE",
|
||||
"displayName": "Namespace",
|
||||
"description": "The OpenShift Namespace where the ImageStream resides.",
|
||||
"required": true,
|
||||
"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",
|
||||
"displayName": "Memory Limit",
|
||||
"description": "Maximum amount of memory the container can use.",
|
||||
"required": true,
|
||||
"value": "512Mi"
|
||||
},
|
||||
{
|
||||
"name": "SOURCE_REPOSITORY_URL",
|
||||
"description": "The URL of the repository with your application source code",
|
||||
"value": "https://github.com/openshift/nodejs-ex.git"
|
||||
"displayName": "Git Repository URL",
|
||||
"description": "The URL of the repository with your application source code.",
|
||||
"required": true,
|
||||
"value": "https://github.com/sclorg/nodejs-ex.git"
|
||||
},
|
||||
{
|
||||
"name": "SOURCE_REPOSITORY_REF",
|
||||
"description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch"
|
||||
"displayName": "Git Reference",
|
||||
"description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch."
|
||||
},
|
||||
{
|
||||
"name": "CONTEXT_DIR",
|
||||
"description": "Set this to the relative path to your project if it is not in the root of your repository"
|
||||
"displayName": "Context Directory",
|
||||
"description": "Set this to the relative path to your project if it is not in the root of your repository."
|
||||
},
|
||||
{
|
||||
"name": "APPLICATION_DOMAIN",
|
||||
"description": "The exposed hostname that will route to the Node.js service",
|
||||
"value": "nodejs-example.openshiftapps.com"
|
||||
"displayName": "Application Hostname",
|
||||
"description": "The exposed hostname that will route to the Node.js service, if left blank a value will be defaulted.",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "GITHUB_WEBHOOK_SECRET",
|
||||
"description": "A secret string used to configure the GitHub webhook",
|
||||
"displayName": "GitHub Webhook Secret",
|
||||
"description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{40}"
|
||||
},
|
||||
{
|
||||
"name": "GENERIC_WEBHOOK_SECRET",
|
||||
"displayName": "Generic Webhook Secret",
|
||||
"description": "A secret string used to configure the Generic webhook.",
|
||||
"generate": "expression",
|
||||
"from": "[a-zA-Z0-9]{40}"
|
||||
},
|
||||
{
|
||||
"name": "NPM_MIRROR",
|
||||
"displayName": "Custom NPM Mirror URL",
|
||||
"description": "The custom NPM mirror URL",
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
27
package.json
27
package.json
|
@ -4,30 +4,31 @@
|
|||
"description": "Node.js sample app for OpenShift 3",
|
||||
"main": "server.js",
|
||||
"dependencies": {
|
||||
"express": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "*"
|
||||
"chai": "^3.5.0",
|
||||
"chai-http": "^2.0.1",
|
||||
"ejs": "^2.4.1",
|
||||
"express": "^4.13.4",
|
||||
"mocha": "^2.4.5",
|
||||
"mongodb": "^2.1.16",
|
||||
"morgan": "^1.7.0",
|
||||
"object-assign":"4.1.0"
|
||||
},
|
||||
"engine": {
|
||||
"node": "*",
|
||||
"npm": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nodemon --ignore node_modules/ server.js",
|
||||
"start": "node server.js"
|
||||
"start": "node server.js",
|
||||
"test": "IP=0.0.0.0 PORT=3030 mocha --timeout 5000 tests/*_test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/openshift/nodejs-ex.git"
|
||||
"url": "http://github.com/sclorg/nodejs-ex.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Echo"
|
||||
],
|
||||
"author": "Steve Speicher <sspeiche@gmail.com>",
|
||||
"license": "",
|
||||
"license": "CC-BY-1.0",
|
||||
"bugs": {
|
||||
"url": "http://github.com/openshift/nodejs-ex/issues"
|
||||
"url": "http://github.com/sclorg/nodejs-ex/issues"
|
||||
},
|
||||
"homepage": "http://github.com/openshift/nodejs-ex"
|
||||
"homepage": "http://github.com/sclorg/nodejs-ex"
|
||||
}
|
||||
|
|
163
server.js
163
server.js
|
@ -1,54 +1,125 @@
|
|||
var util = require('util');
|
||||
var url = require('url');
|
||||
var qs = require('querystring');
|
||||
var os = require('os')
|
||||
var port = process.env.PORT || process.env.port || process.env.OPENSHIFT_NODEJS_PORT || 8080;
|
||||
var ip = process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0';
|
||||
var nodeEnv = process.env.NODE_ENV || 'unknown';
|
||||
// OpenShift sample Node application
|
||||
var express = require('express'),
|
||||
app = express(),
|
||||
morgan = require('morgan');
|
||||
|
||||
Object.assign=require('object-assign')
|
||||
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
app.engine('html', require('ejs').renderFile);
|
||||
app.use(morgan('combined'))
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
var url_parts = url.parse(req.url, true);
|
||||
var port = process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080,
|
||||
ip = process.env.IP || process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0',
|
||||
mongoURL = process.env.OPENSHIFT_MONGODB_DB_URL || process.env.MONGO_URL,
|
||||
mongoURLLabel = "";
|
||||
|
||||
var body = '';
|
||||
req.on('data', function (data) {
|
||||
body += data;
|
||||
});
|
||||
req.on('end', function () {
|
||||
var formattedBody = qs.parse(body);
|
||||
if (mongoURL == null) {
|
||||
var mongoHost, mongoPort, mongoDatabase, mongoPassword, mongoUser;
|
||||
// If using plane old env vars via service discovery
|
||||
if (process.env.DATABASE_SERVICE_NAME) {
|
||||
var mongoServiceName = process.env.DATABASE_SERVICE_NAME.toUpperCase();
|
||||
mongoHost = process.env[mongoServiceName + '_SERVICE_HOST'];
|
||||
mongoPort = process.env[mongoServiceName + '_SERVICE_PORT'];
|
||||
mongoDatabase = process.env[mongoServiceName + '_DATABASE'];
|
||||
mongoPassword = process.env[mongoServiceName + '_PASSWORD'];
|
||||
mongoUser = process.env[mongoServiceName + '_USER'];
|
||||
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
// 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.write('Hello OpenShift World! This is a Node.js-based sample application.\n');
|
||||
res.write('Host: ' + req.headers.host + '\n');
|
||||
res.write('\n');
|
||||
res.write('node.js Production Mode: ' + (nodeEnv == 'production' ? 'yes' : 'no') + '\n');
|
||||
res.write('\n');
|
||||
res.write('HTTP/' + req.httpVersion +'\n');
|
||||
res.write('Request headers:\n');
|
||||
res.write(util.inspect(req.headers, null) + '\n');
|
||||
res.write('Request query:\n');
|
||||
res.write(util.inspect(url_parts.query, null) + '\n');
|
||||
res.write('Request body:\n');
|
||||
res.write(util.inspect(formattedBody, null) + '\n');
|
||||
res.write('\n');
|
||||
res.write('Host: ' + os.hostname() + '\n');
|
||||
res.write('OS Type: ' + os.type() + '\n');
|
||||
res.write('OS Platform: ' + os.platform() + '\n');
|
||||
res.write('OS Arch: ' + os.arch() + '\n');
|
||||
res.write('OS Release: ' + os.release() + '\n');
|
||||
res.write('OS Uptime: ' + os.uptime() + '\n');
|
||||
res.write('OS Free memory: ' + os.freemem() / 1024 / 1024 + 'mb\n');
|
||||
res.write('OS Total memory: ' + os.totalmem() / 1024 / 1024 + 'mb\n');
|
||||
res.write('OS CPU count: ' + os.cpus().length + '\n');
|
||||
res.write('OS CPU model: ' + os.cpus()[0].model + '\n');
|
||||
res.write('OS CPU speed: ' + os.cpus()[0].speed + 'mhz\n');
|
||||
res.end('\n');
|
||||
});
|
||||
next();
|
||||
if (mongoHost && mongoPort && mongoDatabase) {
|
||||
mongoURLLabel = mongoURL = 'mongodb://';
|
||||
if (mongoUser && mongoPassword) {
|
||||
mongoURL += mongoUser + ':' + mongoPassword + '@';
|
||||
}
|
||||
// Provide UI label that excludes user id and pw
|
||||
mongoURLLabel += mongoHost + ':' + mongoPort + '/' + mongoDatabase;
|
||||
mongoURL += mongoHost + ':' + mongoPort + '/' + mongoDatabase;
|
||||
}
|
||||
}
|
||||
var db = null,
|
||||
dbDetails = new Object();
|
||||
|
||||
var initDb = function(callback) {
|
||||
if (mongoURL == null) return;
|
||||
|
||||
var mongodb = require('mongodb');
|
||||
if (mongodb == null) return;
|
||||
|
||||
mongodb.connect(mongoURL, function(err, conn) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
db = conn;
|
||||
dbDetails.databaseName = db.databaseName;
|
||||
dbDetails.url = mongoURLLabel;
|
||||
dbDetails.type = 'MongoDB';
|
||||
|
||||
console.log('Connected to MongoDB at: %s', mongoURL);
|
||||
});
|
||||
};
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
// try to initialize the db on every request if it's not already
|
||||
// initialized.
|
||||
if (!db) {
|
||||
initDb(function(err){});
|
||||
}
|
||||
if (db) {
|
||||
var col = db.collection('counts');
|
||||
// Create a document with request IP and current time of request
|
||||
col.insert({ip: req.ip, date: Date.now()});
|
||||
col.count(function(err, count){
|
||||
if (err) {
|
||||
console.log('Error running count. Message:\n'+err);
|
||||
}
|
||||
res.render('index.html', { pageCountMessage : count, dbInfo: dbDetails });
|
||||
});
|
||||
} else {
|
||||
res.render('index.html', { pageCountMessage : null});
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/pagecount', function (req, res) {
|
||||
// try to initialize the db on every request if it's not already
|
||||
// initialized.
|
||||
if (!db) {
|
||||
initDb(function(err){});
|
||||
}
|
||||
if (db) {
|
||||
db.collection('counts').count(function(err, count ){
|
||||
res.send('{ pageCount: ' + count + '}');
|
||||
});
|
||||
} else {
|
||||
res.send('{ pageCount: -1 }');
|
||||
}
|
||||
});
|
||||
|
||||
// error handling
|
||||
app.use(function(err, req, res, next){
|
||||
console.error(err.stack);
|
||||
res.status(500).send('Something bad happened!');
|
||||
});
|
||||
|
||||
initDb(function(err){
|
||||
console.log('Error connecting to Mongo. Message:\n'+err);
|
||||
});
|
||||
|
||||
app.listen(port, ip);
|
||||
console.log('Server running on ' + ip + ':' + port);
|
||||
console.log('Server running on http://%s:%s', ip, port);
|
||||
|
||||
module.exports = app ;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
var server = require('../server'),
|
||||
chai = require('chai'),
|
||||
chaiHTTP = require('chai-http'),
|
||||
should = chai.should();
|
||||
|
||||
chai.use(chaiHTTP);
|
||||
|
||||
reqServer = process.env.HTTP_TEST_SERVER || server
|
||||
|
||||
describe('Basic routes tests', function() {
|
||||
|
||||
it('GET to / should return 200', function(done){
|
||||
chai.request(reqServer)
|
||||
.get('/')
|
||||
.end(function(err, res) {
|
||||
res.should.have.status(200);
|
||||
done();
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
it('GET to /pagecount should return 200', function(done){
|
||||
chai.request(reqServer)
|
||||
.get('/pagecount')
|
||||
.end(function(err, res) {
|
||||
res.should.have.status(200);
|
||||
done();
|
||||
})
|
||||
|
||||
})
|
||||
})
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue