Deployment automation with ShipIt

Automatic deployment is an essential part of continuous integration (CI). But sometimes full-fledged CI tools/services — like Jenkins, Gitlab-CI, or Travis-CI — are overkill for simple or personal projects. That’s where deployment automation tools like ShipIt shines.

ShipIt is not the only automation tool. There are Capistrano (Ruby), Envoy (PHP), Fabric (Python), and, Gradle + SSH Plugin (Java). But if you are working on a node.js project, choosing ShipIt requires less software dependency as it only needs node.js. You just need to run npm install --save-dev shipit-cli shipit-deploy to install it.

Below is a sample of ShipIt script shipitfile.js to build & deploy simple vue-cli app to an Linux remote server:

module.exports = shipit => {
    require('shipit-deploy')(shipit)

    shipit.initConfig({
        // Default config for all environment
        default: {
            deployTo: '/home/user/project/dist',
            repositoryUrl: 'https://github.com/user/project.git',
        },
        // Environment-specific config
        production: {
            deployTo: '/home/user/lab',
            distDir: './dist',
            servers: 'user@server',
            build: 'npm run build',
        }
    })

    // Deploy task
    shipit.task('deploy', async () => {
        // Run "build" value for given environment (in this case "npm run build")
        await shipit.local(shipit.config.build)
        // Delete existing deployment directory
        await shipit.remote(`rm -rf ${shipit.config.deployTo}`)
        // Copy build result from local to remote directory
        await shipit.start('copy-dist')
    })

    shipit.task('copy-dist', async () => {
        await shipit.copyToRemote(
          shipit.config.distDir,
          shipit.config.deployTo,
        )
    })
}

Assuming that you have setup SSH public key authentication for user to server, you can execute deploy task on production environment by running: npx shipit production deploy.

Since we can run basically any Linux command available on the remote server, we can do almost everything we need to deploy our applications. For example, assuming there is sufficient privilege, one can utilize symbolic links to have zero-downtime deployment.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments