Automatic deployment of your node apps via grunt to ubuntu server using nginx and upstart.
The task connects to your server via SSH (via ssh key only) and writes nginx configuration files. Your app starts on boot a runs as a service via pm2. Application is cloned from it's remote git repository. When the app is cloned, task runs npm install together with optional commands like grunt tasks to build distribution files. Then it reloads nginx.
This grunt task requires you to have linux server (ubuntu 16 tested) running nginx, nodejs, npm, and git.
Please report all issues you may find. Do it preferably at https://github.com/petrkrulis/grunt-node-auto-deploy/issues. It'll be very helpful.
- empty aliases fix
- almost zero downtime (fetch & install in temporary folder)
- dont obtain SSL certificates every time (only when they are not present)
- now using pm2 instead upstart
- custom nginx conf file
- able to obtain letsencrypt certs
- able to use only static web (no node app)
- fixed start/stop application in apps subfolder
- updated dependencies (mainly grunt 1.x.x)
- /etc/init scripts are saved to the /etc/init/apps subfolder
- Fixed fatal bug
- Conf property
- Alias is now a redirect instead of standalone server
- Properly close SSH connection after deployment
- Removed unwanted console output
- Added support for domain alias (so you can add www subdomain easily)
- Fixed optional commands order
This plugin requires Grunt
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-node-auto-deploy --save-dev
The "node_auto_deploy" task
In your project's Gruntfile, add a section named
node_auto_deploy to the data object passed into
The URL of your app. If you don't own a domain name yet, just pass example.com to it and add that domain to your hosts file. You can test the app from the browser then.
Alias is optional. Use it to redirect for example a www subdomain to your app.
Whether to upload ngnix configuration files. Default value is true (will be uploaded). If you need to manage conf files by yourself, let the plugin know not to upload them.
Command used to start the app. Mostly it'll be something like 'node app.js' but you can use anything you need.
NodeJS application port (where the server is listening for connections).
Absolute path to the app. This task takes the options.path path, creates a folder named by the options.url in it and clone the git repository specified in options.git.
Path to ngnix sites-enabled folder. Or basicaly any folder where nginx automatically load all conf files and use them in it's configuration.
Git repository to clone. It should contain the app you want to run :)
The branch which will be cloned from the git repository.
SSH server adress. Use ssh key to login instead of password. I decided not to add support for password access. It's insecure and slow and you would need to type itevery time (you don't want to store the password in a gruntfile).
It's an optional array of commands executed before anything else. All commands in options.before & options.then are executed from application path (the app's root where package.json is stored).
It's an optional array of commands executed after successful deploy and npm install and before start command. Useful as hell if you dont want to include distribution files to git repository. You can easily build them on server, just include all necessary packages in dependecies (not only in devDependencies - this runs in production environment).
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.