Sailsjs - How to package sails application

Viewed 291

I'm working on a sails application.

Currently, to move to another server.

I have to go through 3 steps:

Step1: Checkout source code.

Step2: Run npm install to download dependentcy

Step3: Deploy sails app by cmd sails lift --prod

Is there any way to just push a .zip to server and run cmd deploy?

My purpose is:

Step1: Zip all to 1 folder

Step2: Upzip and deploy

No need to install dependency manual

Like the way of java distribution > build a war file and put into tomcat

Or Angular CLI compile all to dist folder

Thanks

1 Answers

You can make use of Jenkins pipeline and shell scripts to achieve it.

  1. Create a jenkins pipeline
  2. Build a zip file and push it to some storage. ( Amazon S3? )
  3. Execute the shell script to ssh into production server and execute another shell script which downloads the latest build from S3, installs dependency, and then launches the app.

Sample Jenkinsfile:

    pipeline {

        agent any

    stages {
        stage('Build') {
            steps {
                checkout scm
                echo 'Zipping..'
                sh 'echo "My-app-`date +"%Y-%m-%dT%H-%M-%S"`.zip" >> buildName.txt'
                sh 'if [ -d .git ]; then echo "Removing git folder"; rm -r .git/ ; fi;'
                sh 'zip -r `cat buildName.txt` .'
                archiveArtifacts artifacts: '*.zip'
            }
        }
        stage('Test') {
            steps {
                echo 'test..'
            }
        }
        stage('Upload') {
            steps {
                echo 'uploading..'
                sh 's3cmd put `cat buildName.txt` s3://my-app-builds'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying....'
                sh './deploy_to_production.sh'
            }
        }
    }
    }

Else you can dockerize the application.

Related