A plugin to gulp that allows for deploying releases via SSH. This is very similar in nature to grunt-ssh-deploy.
- Addition of gulp tasks to deploy a set of release folders to a remote host.
npm install --save-dev gulp-ssh-deploy
gulp-ssh-deploy
is an ES6-based module, so you can use it with import
statements:
import { GulpSSHDeploy } from 'gulp-ssh-deploy';
Alternatively, you can use the CommonJS module import syntax:
var GulpSSHDeploy = require('gulp-ssh-deploy').GulpSSHDeploy;
You must set up a new instance of GulpSSHDeploy
with a set of options, and your instance of gulp
(to which tasks will be added). Once the instance of GulpSSHDeploy
is created, it takes care of adding the necessary task(s) for you! The easiest way to do this is to add the following to your gulpfile.js
(or gulpfile.babel.js
, if using babel):
new GulpSSHDeploy(
{
"host": "your-server.somewhere.com",
"port": 22,
"package_json_file_path": "package.json",
"source_files": ".",
"remote_directory": "/path/to/remote/deploy/dir",
"username": "someuser",
"ssh_key_file": "/path/to/your/local/ssh/key",
"releases_to_keep": 3,
"group": "remote-group",
"permissions": "ugo+rX",
"package_task": "someTask",
"deploy_task_name": "deploy"
}, gulp);
It's advised to add this to the end of your gulpfile.js
, because it relies on package_task
being defined. Thus, it must be defined before the constructor for GulpSSHDeploy
is invoked.
The address or domain name of the host machine where the deployment will reside.
The port to use to connect to the aforementioned host.
The location of the package.json file for the package which you are deploying. For most projects, the default is fine. For electron projects, and those with multiple package.json
files, this should be the path to the package.json
file containing the version number of your package.
The location of the source files which should be transferred to the remote server. By default, this is ".", so all files within the root project directory will be transferred. You will likely want to set this to your build directory.
The location on the remote host where the deployment should be placed. The deployment will be placed in a directory called releases/<version_number>
within this directory. The remote_directory
must exist on the remote host, but it can be empty.
The username of the user to login with on the remote host. Must have permissions to access the remote_directory
.
A private key to be used to login to the remote host over SSH with the above username
. The special character ~
will be resolved to the current user's
home directory.
If specified, this will indicate how many consecutive releases should be kept around after a deployment. If the number of subdirectories in the remote host's remote_directory/releases
exceeds this number, the version numbers that are first in order by ls
(i.e. typically the least recent deployments) will be removed until this number is reached.
If specified, the deployed release will be chgrp
'ed to this group. The group must exist on the remote host.
If specified, the deployed release folder will be chmod
'ed to this set of permissions. May be specified in human-readable format (e.g. ug+rwX
) or octal (e.g. 0777
).
The task to run prior to transferring the distribution. This task should bundle your distribution and prepare it for transfer to the remote host. This will be added as a dependency to the deploy
task.
The task name to call the 'deployment' task. This will create a task within your gulp configuration with the given name that performs the deployment.
Whether deploying should create a symbolic link to the latest deployment on the remote host. If set to true
, then a link called current
will be created in the root deployment directory that points to the directory of last release that was successfully deployed.
Setup and configuration will create up to seven gulp tasks:
Creates the remote path for the distribution, if it doesn't already exist.
Transfers the distribution from the local host to the remote directory.
Creates a current
symlink in the remote_directory
which points to the most recent release.
Sets the group for the new release, if the group
is specified in options.
Sets the permissions of the remote_directory
to the permissions specified in the options.
Removes old releases to keep a maximum of releases_to_keep
releases on the remote host.
Performs all of the above.
Note: The transferDistribution
task (and thus the release
task) depend on a gulp task called package
, which should build and package your release prior to sending it to the remote host. If this task does not exist, release
and transferDistribution
will fail.
-
The GulpSSHDeploy constructor is throwing a
DeploymentException
- When the GulpSSHDeploy constructor encounters an invalid configuration value, or a required configuration value that doesn't exist, it throws this exception. You can get more information from the exception (and have it print to the gulp logs) by wrapping the call to the constructor in a try/catch block:
try { let deployer = new GulpSSHDeploy(options, gulp); } catch (exception) { exception.printWarning(); }
-
Encounter
GulpSSHDeploy is not a constructor
when using CommonJSrequire()
.- This is an issue with the way it was suggested to use
GulpSSHDeploy
, due to the fact that it was expecting that you usedimport
and not CommonJS. To get around this issue, be sure you're setting up yourgulpfile.js
like the following:
var GulpSSHDeploy = require('gulp-ssh-deploy').GulpSSHDeploy;
- This is an issue with the way it was suggested to use