Deploy releases over SSH with rsync, archive ZIP / TAR, symlinks, SCP ...
Example :
/deployPath
|
├── www --> symlink to ./releases/<currentRelease>
|
├── releases
| ├── 2017-02-08-17-14-21-867-UTC
| ├── ...
| └── 2017-02-09-18-01-10-765-UTC
| ├── ...
| └── logs --> symlink to shared/logs
|
├── synchronized --> folder synchronized with rsync
|
└── shared
└── logs
npm install ssh-deploy-release
const Deployer = require('ssh-deploy-release');
const options = {
localPath: 'src',
host: 'my.server.com',
username: 'username',
password: 'password',
deployPath: '/var/www/vhost/path/to/project'
};
const deployer = new Deployer(options);
deployer.deployRelease(() => {
console.log('Ok !')
});
const Deployer = require('ssh-deploy-release');
const options = {
localPath: 'src',
host: 'my.server.com',
username: 'username',
password: 'password',
deployPath: '/var/www/vhost/path/to/project',
allowRemove: true
};
const deployer = new Deployer(options);
deployer.removeRelease(() => {
console.log('Ok !')
});
ssh-deploy-release uses ssh2 to handle SSH connections.
The options
object is forwarded to ssh2
methods,
which means you can set all ssh2
options:
If true
, will display all commands.
Default : false
Port used to connect to the remote server.
Default : 22
Remote server hostname.
Username used to connect to the remote server.
Password used to connect to the remote server.
For an encrypted private key, this is the passphrase used to decrypt it.
Default: null
Default: null
archive
: Deploy an archive and decompress it on the remote server.
synchronize
: Use rsync. Files are synchronized in the options.synchronized
folder on the remote server.
Default : archive
zip
: Use zip compression (unzip
command on remote)
tar
: Use tar gz compression (tar
command on remote)
Default : tar
Name of the archive.
Default : release.tar.gz
Delete the local archive after the deployment.
Default : true
SCP connection timeout duration.
Default : 20000
Name of the current release symbolic link. Relative to deployPath
.
Defaut : www
Name of the folder containing shared folders. Relative to deployPath
.
Default : shared
Name of the folder containing releases. Relative to deployPath
.
Default : releases
Name of the local folder to deploy.
Default : www
Absolute path on the remote server where releases will be deployed. Do not specify currentReleaseLink (or www folder) in this path.
Name of the remote folder where rsync synchronize release.
Used when mode
is 'synchronize'.
Default : www
Additional options for rsync process.
Default : '''
rsyncOptions : '--exclude-from="exclude.txt" --delete-excluded'
Number of releases to keep on the remote server.
Default : 3
Name of the release. Must be different for each release.
Default : Use current timestamp.
List of paths (glob format) to not deploy. Paths must be relative to localPath
.
Not compatible with mode: 'synchronize'
, use rsyncOptions
instead to exclude some files.
Default : []
List of folders to "share" between releases. A symlink will be created for each item.
Item can be either a string or an object (to specify the mode to set to the symlink target).
share: {
'images': 'assets/images',
'upload': {
symlink: 'app/upload',
mode: '777' // Will chmod 777 shared/upload
}
}
Keys = Folder to share (relative to sharedFolder
)
Values = Symlink path (relative to release folder)
Default : {}
List of folders to create on the remote server.
Default : []
List of files to make writable on the remote server. (chmod ugo+w)
Default : []
List of files to make executable on the remote server. (chmod ugo+x)
Default : []
If true, the remote release folder can be deleted with removeRelease
method.
Default: false
The following object is passed to onXXXDeploy
functions :
{
// Loaded configuration
options: { },
// Release
release: {
// Current release name
tag: '2017-01-25-08-40-15-138-UTC',
// Current release path on the remote server
path: '/opt/.../releases/2017-01-25-08-40-15-138-UTC',
},
// Logger methods
logger: {
// Log fatal error and stop process
fatal: (message) => {},
// Log 'subhead' message
subhead: (message) => {},
// Log 'ok' message
ok: (message) => {},
// Log 'error' message and continue process
error: (message) => {},
// Log message, only if options.debug is true
debug: (message) => {},
// Log message
log: (message) => {},
// Start a spinner and display message
// return a stop()
startSpinner: (message) => { return {stop: () => {}}},
},
// Remote server methods
remote: {
// Excute command on the remote server
exec: (command, done, showLog) => {},
// Excute multiple commands (array) on the remote server
execMultiple: (commands, done, showLog) => {},
// Upload local src file to target on the remote server
upload: (src, target, done) => {},
// Create a symbolic link on the remote server
createSymboliclink: (target, link, done) => {},
// Chmod path on the remote server
chmod: (path, mode, done) => {},
// Create folder on the remote server
createFolder: (path, done) => {},
}
}
onBeforeDeploy, onBeforeLink, onAfterDeploy options.
You have to call done
function to continue deployment process.
onAfterDeploy: (context, done) => {
context.logger.subhead('Do something');
const spinner = context.logger.startSpinner('Doing something');
const command = 'ls -la';
const showLog = true;
deployer.remote.exec(
command,
() => {
spinner.stop();
done();
},
showLog
);
}
onBeforeDeployExecute, onBeforeLinkExecute, onAfterDeployExecute options.
onAfterDeployExecute: [
'do something on the remote server',
'and another thing'
]
Or with a function :
onAfterDeployExecute: (context) => {
context.logger.subhead('Doing something');
return [
'do something on the remote server',
'and another thing'
];
}
Function called before deployment. Call done
to continue;
Type: function(context, done)
Array (or function returning array) of commands to execute on the remote server.
Type: function(context) | []
Function called before symlink creation. Call done
to continue;
Type: function(context, done)
Array (or function returning array) of commands to execute on the remote server.
Type: function(context) | []
Function called after deployment. Call done
to continue;
Type: function(context, done)
Array (or function returning array) of commands to execute on the remote server.
Type: function(context) | []
A command on a callback method is not executed or not found.
Try to add set -i && source ~/.bashrc &&
before your commmand :
onAfterDeployExecute:[
'set -i && source ~/.bashrc && my command'
]
See this issue : mscdex/ssh2#77
# Build (with Babel)
npm run build
# Build + watch (with Babel)
npm run build -- --watch
# Launch tests (Mocha + SinonJS)
npm test
# Launch tests + watch (Mocha + SinonJS)
npm test -- --watch