Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .bluemix/deploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Sample Deploy Stage",
"longDescription": "The Delivery Pipeline automates continuous deployment.",
"type": "object",
"properties": {
"dev-region": {
"description": "The bluemix region",
"type": "string"
},
"dev-organization": {
"description": "The bluemix org",
"type": "string"
},
"dev-space": {
"description": "The bluemix space",
"type": "string"
},
"app-name": {
"description": "app name",
"type": "string"
}
},
"required": ["dev-region", "dev-organization", "dev-space", "app-name"],
"form": [{
"type": "validator",
"url": "/devops/setup/bm-helper/helper.html"
}, {
"type": "text",
"readonly": false,
"title": "App Name",
"key": "app-name"
}, {
"type": "table",
"columnCount": 3,
"widths": ["28%", "28%", "28%"],
"items": [{
"type": "label",
"title": "Region"
}, {
"type": "label",
"title": "Organization"
}, {
"type": "label",
"title": "Space"
}, {
"type": "select",
"key": "dev-region"
}, {
"type": "select",
"key": "dev-organization"
}, {
"type": "select",
"key": "dev-space",
"readonly": false
}]
}]
}
57 changes: 57 additions & 0 deletions .bluemix/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
stages:
- name: Build Stage
inputs:
- type: git
branch: develop
service: ${REPO}
jobs:
- name: Build
type: builder
artifact_dir: ''
- name: Deploy Stage
inputs:
- type: job
stage: Build Stage
job: Build
triggers:
- type: stage
jobs:
- name: Deploy
type: deployer
target:
region_id: ${CF_REGION_ID}
organization: ${CF_ORGANIZATION}
space: ${CF_SPACE}
application: ${CF_APP}
script: |-
#!/bin/bash
export MONGO_SERVICE_NAME=Node-mongodb

if ! cf service ${MONGO_SERVICE_NAME} ; then
cf create-service compose-for-mongodb Standard ${MONGO_SERVICE_NAME}
fi

if ! cf app $CF_APP; then
cf push $CF_APP
else
OLD_CF_APP=${CF_APP}-OLD-$(date +"%s")
rollback() {
set +e
if cf app $OLD_CF_APP; then
cf logs $CF_APP --recent
cf delete $CF_APP -f
cf rename $OLD_CF_APP $CF_APP
fi
exit 1
}
set -e
trap rollback ERR
cf rename $CF_APP $OLD_CF_APP
cf push $CF_APP
cf delete $OLD_CF_APP -f
fi
# Export app name and URL for use in later Pipeline jobs
export CF_APP_NAME="$CF_APP"
export APP_URL=http://$(cf app $CF_APP_NAME | grep urls: | awk '{print $2}')
# View logs
#cf logs "${CF_APP}" --recent
44 changes: 44 additions & 0 deletions .bluemix/toolchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Continuous Delivery Toolchain
description: "This toolchain includes tools to develop and deploy your app. Depending on your app, when you create the toolchain, the GitHub repository will either be empty or will contain source code from your app.\n\nThis toolchain uses tools that are part of the Continuous Delivery service. If an instance of that service isn't already in your organization, when you click **Create**, it is automatically added at no cost to you. For more information and terms, see the [Bluemix catalog](/catalog/services/continuous-delivery/).\n\nTo get started, click **Create**."
version: 0.2
required:
- deploy
- repo

toolchain:
name: 'nodemongo-{{timestamp}}'

# Github repos
repo:
service_id: githubpublic
parameters:
repo_name: '{{toolchain.name}}'
repo_url: 'https://github.com/IBM-MIL/node-mongo-sample.git'
type: clone
has_issues: true

# Pipelines
build:
service_id: pipeline
parameters:
name: "{{name}}"
ui-pipeline: true
configuration:
content: $file(pipeline.yml)
env:
REPO: "repo"
CF_APP: "{{deploy.parameters.app-name}}"
CF_SPACE: "{{deploy.parameters.dev-space}}"
CF_ORGANIZATION: "{{deploy.parameters.dev-organization}}"
CF_REGION_ID: "{{deploy.parameters.dev-region}}"
execute: true
services: ["repo"]
hidden: ["form"]

#Deployment
deploy:
schema:
$ref: deploy.json
service-category: pipeline
parameters:
app-name: 'nodemongosample-{{timestamp}}'
4 changes: 4 additions & 0 deletions .cfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git/
node_modules/
test/
vcap-local.js
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# node-mongo-sample
Node and Mongo Sample


Deploy to Bluemix!

[![Deploy to Bluemix](https://hub.jazz.net/deploy/button.png)](https://bluemix.net/deploy?repository=https://github.com/IBM-MIL/node-mongo-sample.git&branch=develop)
14 changes: 14 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
applications:
- disk_quota: 1024M
name: nodemongosample
domain: mybluemix.net
host: node-mongo-sample-123
memory: 256M
instances: 1
timeout: 180
buildpack: sdk-for-nodejs
command: npm start
services:
- Node-mongodb
env:
OPENAPI_SPEC: /swagger/api
107 changes: 107 additions & 0 deletions mongo-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

const dbName = 'example';

module.exports = function () {
var module = {};
var myDb;
var ObjectID = require("mongodb").ObjectID;
var MongoClient = require("mongodb").MongoClient;

module.init = function(appEnv) {
// Mongo instrumentation
var mongoCredentials = appEnv.services['compose-for-mongodb'][0].credentials;
var mongoCa = [new Buffer(mongoCredentials.ca_certificate_base64, "base64")];
var mongoClientConfig = {
mongos: {
ssl: true,
sslValidate: true,
sslCA: mongoCa,
poolSize: 5,
reconnectTries: 1
}, server: {
auto_reconnect: true
}, db: {
numberOfRetries: 24,
retryMiliSeconds: 5000
}
};
MongoClient.connect(mongoCredentials.uri, mongoClientConfig, (err, db) => {
if(err) {
console.log(err);
} else {
db.createCollection(dbName, (err, collection) => {
myDb = collection;
//console.log(myDb);
if (err) {
console.error('failed to connection to collection: ' + dbName);
console.error(err);
}
});
console.log("Connected to MongoDB!");
}
});
};

module.getAllPromise = function getAllPromise() {
return new Promise((resolve, reject) => {
var documentsStream = myDb.find().stream();
var documents = [];
documentsStream.on("data", (item) => {
documents.push(item);
});
documentsStream.on("end", () => {
resolve(documents);
});
});
}

module.getPromise = function getPromise(id) {
return new Promise((resolve, reject) => {
myDb.findOne({'_id': id}, (err, item) => {
if (err) {
console.log(err);
reject({'result': err});
}
resolve({'result': item});
});
});
}

module.insertPromise = function insertPromise(jsonData) {
return new Promise((resolve, reject) => {
myDb.insert(jsonData, {w:1}, function(err, result){
if (err) {
reject({'result': err});
}
resolve({'result': result});
});
});
}

module.checkIdPromise = function checkIdPromise(jsonData, id) {
if (!jsonData['_id']) {
jsonData['_id'] = formatId(id);
} else {
jsonData['_id'] = formatId(jsonData['_id']);
}
return module.insertPromise(jsonData);
}

module.deletePromise = function deletePromise(id) {
return new Promise((resolve, reject) => {
myDb.remove({'_id': formatId(id)}, {w:1}, (err, result) => {
if (err) {
console.error(err);
reject({'result': err});
}
resolve({'result': result});
});
});
}

function formatId(id) {
return id.length > 23 ? ObjectID(id) : id;
}

return module;
};
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "nodemongosample",
"version": "1.0.0",
"description": "A generated Bluemix application",
"private": true,
"engines": {
"node": "^6.9.0"
},
"scripts": {
"start": "node server.js",
"debug": "node --nolazy --debug-brk=5858 server.js"
},
"dependencies": {
"appmetrics-dash": "^3.0.0",
"body-parser": "^1.17.0",
"cfenv": "^1.0.3",
"cloudant": "^1.7.1",
"express": "^4.14.0",
"express-session": "^1.15.0",
"mongodb": "^2.2.26"
}
}
1 change: 1 addition & 0 deletions public/swagger-ui/css/print.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/swagger-ui/css/reset.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/swagger-ui/css/screen.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/swagger-ui/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Binary file added public/swagger-ui/fonts/DroidSans-Bold.ttf
Binary file not shown.
Binary file added public/swagger-ui/fonts/DroidSans.ttf
Binary file not shown.
Binary file added public/swagger-ui/images/collapse.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/swagger-ui/images/expand.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/swagger-ui/images/explorer_icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/swagger-ui/images/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/swagger-ui/images/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/swagger-ui/images/favicon.ico
Binary file not shown.
Binary file added public/swagger-ui/images/logo_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/swagger-ui/images/pet_store_api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/swagger-ui/images/throbber.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/swagger-ui/images/wordnik_api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading