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
8 changes: 8 additions & 0 deletions nodejs-app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.dockerignore
.gitignore
.git
infra
CODE_OF_CONDUCT.md
README.md
Dockerfile
Jenkinsfile
10 changes: 10 additions & 0 deletions nodejs-app/.ebextensions/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
option_settings:
aws:elasticbeanstalk:application:environment:
PARSE_MOUNT: "/parse"
APP_ID: "ReplaceWithAppID"
MASTER_KEY: "ReplaceWithMasterKey"
DATABASE_URI: "ReplaceWithDatabaseURI"
NODE_ENV: "production"
SERVER_URL: "http://myappname.elasticbeanstalk.com/parse"
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
20 changes: 20 additions & 0 deletions nodejs-app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"env": {
"node": true
},
"rules": {
"linebreak-style": ["error", "unix"],
"eol-last": 2,
"space-in-parens": ["error", "never"],
"no-multiple-empty-lines": 1,
"prefer-const": "error",
"space-infix-ops": "error",
"no-useless-escape": "off",
"require-atomic-updates": "off",
"no-invalid-regexp": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-debugger": 2
}
}
30 changes: 30 additions & 0 deletions nodejs-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Emacs
*~
76 changes: 76 additions & 0 deletions nodejs-app/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at codeofconduct@parseplatform.org. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
17 changes: 17 additions & 0 deletions nodejs-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:10.16.3-alpine AS base
RUN npm install eslint@6.8.0 -g
WORKDIR /parse
COPY ./package.json .
RUN npm set progress=false && npm config set depth 0
RUN npm install --only=production && npm audit fix


FROM node:10.16.3-alpine AS release
WORKDIR /node-app
RUN chown -R node:node /node-app
COPY --from=base /parse/node_modules ./node_modules
COPY . .
RUN rm -f .eslintrc.json
USER node
EXPOSE 1337
CMD [ "npm", "start" ]
60 changes: 60 additions & 0 deletions nodejs-app/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env groovy

properties([
parameters([
string(defaultValue: "master", description: 'Which Git Branch to clone?', name: 'GIT_BRANCH'),
string(defaultValue: "parse-server-example", description: 'Which Git Repo to clone?', name: 'GIT_APP_REPO'),
string(defaultValue: "viksharma001", description: 'Which docker account?', name: 'ACCOUNT'),
string(defaultValue: "parse-server", description: 'Which name of the docker image?', name: 'IMAGE_NAME'),
string(defaultValue: "v1", description: 'Which image tag?', name: 'IMAGE_TAG'),
string(defaultValue: "/Users/vikasdeepsharma/.kube/config", description: 'Which path of ~/.kube/config', name: 'CONFIGPATH'),
string(defaultValue: "parse-server-namespace", description: 'Namepsace for parse-server resources', name: 'NAMESPACE'),
string(defaultValue: "parse-server", description: 'Root passphrase of DCTs', name: 'DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE'),
string(defaultValue: "parse-server", description: 'Repository passphrase of DCTs', name: 'DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE'),

])
])

registry = "${ACCOUNT}/parse-server"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove hardcoded repository name.

registryCredential = 'dockerhub'

stage('Clone Repo'){
node('master'){
cleanWs()
checkout([$class: 'GitSCM', branches: [[name: '$GIT_BRANCH']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/vikas-prabhakar/${GIT_APP_REPO}.git']]])
}
}


stage ('Package') {
node('master'){
finalImage = docker.build("${registry}:${IMAGE_TAG}",'.')

}

}
stage ('Push to Dockerhub') {

withEnv(['DOCKER_CONTENT_TRUST=1','DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE=$DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE','DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE=$DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE']){
docker.withRegistry('',registryCredential) {
finalImage.push()
}
}
}


stage('Remove Unused docker image') {
node('master'){
sh "docker rmi $registry:$IMAGE_TAG"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use rmi -f

}
}

stage('Deploy App') {
node('master'){
withEnv(["KUBECONFIG=$CONFIGPATH"]){
sh "helm upgrade mongo-db ./helm-chart/mongo-db --install --namespace=$NAMESPACE"
sh "helm upgrade parse-server ./helm-chart/parse-server --install --namespace=$NAMESPACE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the mongo-dB part you can use dependency in helm chart for MongoDB.
And please remove the hardcoded chart name parse-server as well.
and add atomic and time to wait for application deployment to make sure application successfully deployed or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add provide replication count as parameterised option

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and helm chart is missing

}

}
}
36 changes: 36 additions & 0 deletions nodejs-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# parse-server-example

It contain parse-server app on kubernetes cluster using helm chart.
## Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

### Prerequisites

```
Docker
helm chart
k8s
jenkins
Docker registry hub
```

### Installing
```
Configure the Dockerfile to build node app.
Configure Jenkinsfile pipeline script to build,deploy app on k8s using helm chart
Add credential of docker hub registry
```
<div align="center">
<img src="./credential.png" width="580px"</img>
</div>

## Authors

* **Vikas Sharma** - *work* - [github](https://github.com/vikas-prabhakar)


## Acknowledgments

* Hat tip to anyone whose code was used
* Inspiration
* etc
27 changes: 27 additions & 0 deletions nodejs-app/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Parse Server Example",
"description": "An example Parse API server using the parse-server module",
"repository": "https://github.com/ParsePlatform/parse-server-example",
"logo": "https://avatars0.githubusercontent.com/u/1294580?v=3&s=200",
"keywords": ["node", "express", "parse"],
"env": {
"PARSE_MOUNT": {
"description": "Configure Parse API route.",
"value": "/parse"
},
"APP_ID": {
"description": "A unique identifier for your app.",
"value": "myAppId"
},
"MASTER_KEY": {
"description": "A key that overrides all permissions. Keep this secret.",
"value": "myMasterKey"
},
"SERVER_URL": {
"description": "URL to connect to your Heroku instance (update with your app's name + PARSE_MOUNT)",
"value": "http://yourappname.herokuapp.com/parse"
}
},
"image": "heroku/nodejs",
"addons": ["mongolab"]
}
13 changes: 13 additions & 0 deletions nodejs-app/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
runtime: nodejs
env: flex

env_variables:
# --REQUIRED--
DATABASE_URI: mongodb://localhost:27017/dev
APP_ID: <your-app-id>
MASTER_KEY: <your-master-key>
SERVER_URL: https://your-project-id.appspot.com/parse
# --OPTIONAL--
# FILE_KEY: <your-file-key>
# PARSE_MOUNT: /parse
# CLOUD_CODE_MAIN:
3 changes: 3 additions & 0 deletions nodejs-app/cloud/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Parse.Cloud.define('hello', function(req, res) {
return 'Hi';
});
Binary file added nodejs-app/credential.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions nodejs-app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Example express application adding the parse-server module to expose Parse
// compatible API routes.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!');
});

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
});

var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});

// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
Loading