-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Deploying on Heroku
Choose between:
- Manual deployment with Heroku Toolbelt or
- Automatic deployment with GitLab CI
Register with Heroku and create an app: http://heroku.com/
Download the Heroku Toolbelt: https://toolbelt.heroku.com/
You also need an accessible MongoDB instance - you can try MongoHQ which has an easy setup.
Add your db to the production env file in server/config/env/production.js
:
db: 'mongodb://' + (process.env.DB_PORT_27017_TCP_ADDR || 'localhost') + '/my-awesome-demo',
We will add your connection string and other environment variables next
git init #if no git yet
git add .
git commit -m "initial version"
heroku apps:create
heroku config:add NODE_ENV=production
heroku config:add DB_PORT_27017_TCP_ADDR=user:pass@dbhost.example:31426
# install devDependencies too, ugly hack
heroku config:set NPM_CONFIG_PRODUCTION=false
Then push your mean app to Heroku.
$ git push heroku master
$ heroku config:set NODE_ENV=production
Create a GitLab account and project and enable shared runner (if not enabled by default). Register on Heroku and create an app.
npm install --save cross-env
"scripts": {
"start:dev": "gulp",
"start": "node server",
"mocha": "node tools/test/run-mocha.js",
"karma": "node node_modules/karma/bin/karma start karma.conf.js",
"test": "gulp test",
"test-e2e": "gulp e2e.test",
"build:production": "cross-env NODE_ENV=production webpack",
"postinstall": "node tools/scripts/postinstall.js",
"snyk-protect": "snyk protect",
"prepublish": "npm run snyk-protect"
}
image: mwallasch/docker-ruby-node # required, because we need ruby, node and npm
variables:
NODE_ENV: "development" # required, because we need to install devDependencies
stages:
- deploy
deploy_job:
stage: deploy
script:
- npm -v
- npm install -qs # install all dependencies (and devDependencies)
- npm run build:production # run webpack, set NODE_ENV=production
- gem install dpl # install dpl...
- dpl --skip_cleanup --provider=heroku --app=<app-name> --api-key=$HEROKU_API_KEY #...and deploy (skip_cleanup prevents deleting the previous generated bundled assets)
only:
- master
'HEROKU_API_KEY' is the API key you get from Heroku. Set this as project variable in GitLab.
...
/node_modules
This ensures that Heroku re-installs all dependencies with config production.
This is necessary, because if you use a Heroku Add-on (like mLab) you'll get a connection string instead of seperate params.
/config
/env
default.js
production.js
Modify this line:
db: 'mongodb://' + (process.env.DB_PORT_27017_TCP_ADDR || 'localhost') + '/mean-prod',
to
db: process.env.MONGODB_URI,
Now when you push to your repository, an automatic build process is started resulting in a deployment to Heroku.
- Getting Started Guides
- Deployment
- Testing
- System Deep Dives
Aggregation- Packages
- Database
- Menus
- Circles (roles/permissions) High Level Overview
- Circles code examples
- User Auth withJWT
- Contributing