Introduction to Shipit CLI
Shipit CLI is a powerful release automation tool that helps developers deploy code swiftly and efficiently. It offers an array of helpful APIs to simplify the deployment process. Here’s a guide to some of the most useful APIs in Shipit CLI, along with examples on how to integrate them into your application.
1. Initializing Shipit
const shipit = require('shipit-cli'); shipit.initConfig({ default: { workspace: '/tmp/deploy', deployTo: '/var/www/project', repositoryUrl: 'https://github.com/user/project.git', branch: 'main' } });
2. Remote Task Execution
Run tasks on remote servers using shipit.remote()
:
shipit.remote('uptime', function(err, stdout, stderr) { if (err) { throw err; } console.log(stdout); });
3. Local Task Execution
Run tasks on the local machine using shipit.local()
:
shipit.local('ls -lah', function(err, stdout, stderr) { if (err) { throw err; } console.log(stdout); });
4. Copy Files
Use shipit.copyToRemote()
to copy files to the remote server:
shipit.copyToRemote('local/path/to/file', 'remote/path/to/destination', function(err) { if (err) { throw err; } console.log('File copied successfully'); });
5. Checking Out Git Branch
shipit.task('checkout', function() { return shipit.local('git checkout ' + shipit.config.branch); });
Application Example Using The APIs
Below is an example application utilizing several Shipit APIs for a complete workflow:
const shipit = require('shipit-cli'); shipit.initConfig({ default: { workspace: '/tmp/deploy', deployTo: '/var/www/project', repositoryUrl: 'https://github.com/user/project.git', branch: 'main' } }); shipit.task('deploy', function() { return shipit.remote('echo "Starting deployment"') .then(() => shipit.local('npm run build')) .then(() => shipit.copyToRemote('dist/', '/var/www/project')) .then(() => shipit.remote('pm2 reload all')); });
This script initializes the deployment configuration, runs a series of tasks including building the project locally, copying the build to the remote server, and finally reloading the server application.
By incorporating Shipit CLI into your deployment workflow, you can significantly reduce the complexity and time required for effectively deploying your projects.
Hash: a0a0ecc199ac616bdc66e168a99c8b8b68a0f9d0717d627964f029ad58166d12