Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Support Deploying MEANJS To Cloud Foundry #681

Closed
wants to merge 11 commits into from
10 changes: 10 additions & 0 deletions .cfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# List of files and directories to ignore when deploying to Cloud Foundry
.DS_Store
.nodemonignore
.sass-cache/
npm-debug.log
node_modules/
public/lib
app/tests/coverage/
.bower-*/
.idea/
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,85 @@ $
$ docker run -p 3000:3000 -p 35729:35729 -v /Users/mdl/workspace/mean-stack/mean/public:/home/mean/public -v /Users/mdl/workspace/mean-stack/mean/app:/home/mean/app --link db:db_1 mean
```

## Deploying To Cloud Foundry
Copy link
Member

Choose a reason for hiding this comment

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

I think up until line 188 the info is ok, but beyond it's quite specific to the CF configuration and that's not the place to put it. I suggest that we try one of:

  1. We create a Wiki entry and refer to it
  2. We create documentation for it on the 0.4.0 gh-pages branch and refer to it.

Also please place the CF README section in the bottom part and definitely not before the core MEANJS items like Getting Started area.

Copy link
Member

Choose a reason for hiding this comment

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

Here's a barebone structure right now for the documentation:
https://github.com/meanjs/mean/blob/gh-pages/_includes/docs/0.4.x/overview.html

If you make another file with that structure with instructions on Deploying to CloudFoundry, I will get the link worked out in the documentation for it to show up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@codydaig is it best to create a separate pull request for that branch with the documentation in it?


Cloud Foundry is an open source platform-as-a-service (PaaS). The MEANJS project
can easily be deployed to any Cloud Foundry instance. The easiest way to deploy the
MEANJS project to Cloud Foundry is to use a public hosted instance. The two most popular
instances are [Pivotal Web Services](https://run.pivotal.io/) and
[IBM Bluemix](https://bluemix.net). Both provide free trials and support pay-as-you-go models
for hosting applications in the cloud. After you have an account follow the below steps to
deploy MEANJS.

* Install the [Cloud Foundry command line tools](http://docs.cloudfoundry.org/devguide/installcf/install-go-cli.html).
* Now you need to log into Cloud Foundry from the Cloud Foundry command line.
* If you are using Pivotal Web Services run `$ cf login -a api.run.pivotal.io`.
* If you are using IBM Bluemix run `$ cf login -a api.ng.bluemix.net`.
* Create a Mongo DB service, IBM Bluemix and Pivotal Web Services offer a free MongoLabs service.
* `$ cf create-service mongolab sandbox mean-mongo`
* Clone the GitHub repo for MEANJS if you have not already done so
* `$ git clone https://github.com/meanjs/mean.git && cd mean`
* Run the Grunt Build task to build the optimized JavaScript and CSS files
* `$ grunt build`
* Deploy MEANJS to Cloud Foundry
* `$ cf push`

After `cf push` completes you will see the URL to your running MEANJS application
(your URL will be different).

requested state: started
instances: 1/1
usage: 128M x 1 instances
urls: mean-humbler-frappa.mybluemix.net

Open your browser and go to that URL and your should see your MEANJS app running!

### Configuring Social Services

The MEANJS application allows you to login via a number of social services. In other
deployments of MEANJS you need to configure environment variables with the various
keys and secrets to enable these social services. While this is possible in Cloud
Foundry, it is not the preferred method. Credentials like this are usually surfaced
through services an application can bind to. For this reason, when you deploy
MEANJS to Cloud Foundry you must configure and bind services to your application
in order to login with the various social services. To do this we will use
what is called
[user provided services](http://docs.cloudfoundry.org/devguide/services/user-provided.html).

Once your application is deployed to Cloud Foundry run the following command for the social
services you would like to use. Make sure you insert the correct credentials for the service.

#### Facebook
`$ cf cups mean-facebook -p '{"id":"facebookId","secret":"facebookSecret"}'`
`$ cf bind-service mean mean-facebook`

#### Twitter
`$ cf cups mean-twitter -p '{"key":"twitterKey","secret":"twitterSecret"}'`
`$ cf bind-service mean mean-twitter`

#### Google
`$ cf cups mean-google -p '{"id":"googleId","secret":"googleSecret"}'`
`$ cf bind-service mean mean-google`

#### LinkedIn
`$ cf cups mean-linkedin -p '{"id":"linkedinId","secret":"linkedinSecret"}'`
`$ cf bind-service mean mean-linkedin`

#### GitHub
`$ cf cups mean-github -p '{"id":"githubId","secret":"githubSecret"}'`
`$ cf bind-service mean mean-github`

#### Email
`$ cf cups mean-mail -p '{"from":"fromEmail","service":"emailService","username":"emailServiceUsername","password":"emailServicePassword"}'`
`$ cf bind-service mean mean-mail`

#### Paypal
`$ cf cups mean-paypal -p '{"id":"paypalId","secret":"paypalSecret"}'`
`$ cf bind-service mean mean-paypal`

After you have bound the services your want to your MEANJS application run
`$ cf restage mean` to restage your application and your social services should now work.

## Getting Started With MEAN.JS
You have your application running, but there is a lot of stuff to understand. We recommend you go over the [Official Documentation](http://meanjs.org/docs.html).
In the docs we'll try to explain both general concepts of MEAN components and give you some guidelines to help you improve your development process. We tried covering as many aspects as possible, and will keep it updated by your request. You can also help us develop and improve the documentation by checking out the *gh-pages* branch of this repository.
Expand Down
23 changes: 23 additions & 0 deletions config/assets/cloud-foundry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

module.exports = {
client: {
lib: {
css: [
'public/lib/bootstrap/dist/css/bootstrap.min.css',
'public/lib/bootstrap/dist/css/bootstrap-theme.min.css',
],
js: [
'public/lib/angular/angular.min.js',
'public/lib/angular-resource/angular-resource.min.js',
'public/lib/angular-animate/angular-animate.min.js',
'public/lib/angular-ui-router/release/angular-ui-router.min.js',
'public/lib/angular-ui-utils/ui-utils.min.js',
'public/lib/angular-bootstrap/ui-bootstrap-tpls.min.js',
'public/lib/angular-file-upload/angular-file-upload.min.js'
]
},
css: 'public/dist/application.min.css',
js: 'public/dist/application.min.js'
}
};
71 changes: 71 additions & 0 deletions config/env/cloud-foundry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict';

var cfenv = require('cfenv'),
appEnv = cfenv.getAppEnv(),
cfMongoUrl = appEnv.getService('mean-mongo') ?
appEnv.getService('mean-mongo').credentials.uri : undefined;

var getCred = function(serviceName, credProp) {
return appEnv.getService(serviceName) ?
appEnv.getService(serviceName).credentials[credProp] : undefined;
};

module.exports = {
port: appEnv.port,
db: {
uri: cfMongoUrl,
options: {
user: '',
pass: ''
}
},
log: {
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
format: 'combined',
// Stream defaults to process.stdout
// By default we want logs to go to process.out so the Cloud Foundry Loggregator will collect them
options: {
}
},
facebook: {
clientID: getCred('mean-facebook', 'id') || 'APP_ID',
clientSecret: getCred('mean-facebook', 'secret') || 'APP_SECRET',
callbackURL: '/api/auth/facebook/callback'
},
twitter: {
clientID: getCred('mean-twitter', 'key') || 'CONSUMER_KEY',
clientSecret: getCred('mean-twitter', 'secret') || 'CONSUMER_SECRET',
callbackURL: '/api/auth/twitter/callback'
},
google: {
clientID: getCred('mean-google', 'id') || 'APP_ID',
clientSecret: getCred('mean-google', 'secret') || 'APP_SECRET',
callbackURL: '/api/auth/google/callback'
},
linkedin: {
clientID: getCred('mean-linkedin', 'id') || 'APP_ID',
clientSecret: getCred('mean-linkedin', 'secret') || 'APP_SECRET',
callbackURL: '/api/auth/linkedin/callback'
},
github: {
clientID: getCred('mean-github', 'id') || 'APP_ID',
clientSecret: getCred('mean-github', 'secret') || 'APP_SECRET',
callbackURL: '/api/auth/github/callback'
},
paypal: {
clientID: getCred('mean-paypal', 'id') || 'CLIENT_ID',
clientSecret: getCred('mean-paypal', 'secret') || 'CLIENT_SECRET',
callbackURL: '/api/auth/paypal/callback',
sandbox: false
},
mailer: {
from: getCred('mean-mail', 'from') || 'MAILER_FROM',
options: {
service: getCred('mean-mail', 'service') || 'MAILER_SERVICE_PROVIDER',
auth: {
user: getCred('mean-mail', 'username') || 'MAILER_EMAIL_ID',
pass: getCred('mean-mail', 'password') || 'MAILER_PASSWORD'
}
}
}
};
8 changes: 8 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
applications:
- name: mean
host: mean-${random-word}
memory: 128M
services:
- mean-mongo
env:
NODE_ENV: cloud-foundry
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"serve-favicon": "^2.3.0",
"socket.io": "^1.3.5",
"swig": "^1.4.2",
"validator": "^3.41.2"
"validator": "^3.41.2",
"cfenv": "~1.0.0"
},
"devDependencies": {
"grunt-concurrent": "^2.0.0",
Expand Down