0.2.3 • Published 6 years ago

simple-deployer v0.2.3

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Simple Deployer

npm version

Simple-deployer enables you to execute a series of commands both locally and remotely via SSH. Deploy your application, backup a database or simply get the status of your server with a simple array of commands.

Installation

$ npm install simple-deployer --save-dev

Usage

// Require simple deployer
const Deployer = require('simple-deployer')

// Server configuration
const config = {
      host: 'github.com',
      port: 22,
  username: 'david'
}

// New deployer
const deployer = new Deployer(config)

// Array of commands
const commands = []

// Push a local command
commands.push({
  command: 'cd ~/pictures && ls -l',
    local: true
})

// Push a remote command
commands.push({
  command: 'cd ~/server_pictures && ls -l',
})

// Deploy
deployer.deploy(commands)

Server configuration

OptionDefaultDescription
hostundefineddomain or ip to be used in the ssh connection
usernameundefinedusername to be used in the ssh connection
port22port number to be used in the ssh connection
privateKeyPath~/.ssh/id_rsapath to the private key file to be used in the ssh connection
passwordundefinedserver user password to be used in the ssh connection
showDeployMessagesfalseShow extra deployment information

Command architecture

OptionTypeDescription
headerStringIf present it just print the header string and group the commands after it
commandStringCommand to be executed
dynamicfunction(lastResult: String, lastCode: Number): {command: String, options: Array}Function to dynamically generate the next command based on results during the deploy
optionsArrayArray of command options like '-v'
localBooleanThe command must be executed locally
showResultsBooleanPrint the stdout generated by the command after executing it
messageStringCustom message to print while executing the command
continueOnErrorCodeBooleanDon't stop the deploy if this command returns an error code

Examples

Get nginx status

const deployer = new Deployer(config)
const commands = []

commands.push({
  command: 'service nginx status',
  message: 'nginx status:',
  showResults: true
})

deployer.deploy(commands)

Will show:

      01 service nginx status 
      01 nginx status:
       ● nginx.service - A high performance web server and a reverse proxy server
          Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
          Active: active (running) since Tue 2017-08-08 06:44:16 UTC; 1 weeks 0 days ago
         Process: 1551 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
         Process: 1351 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
        Main PID: 1605 (nginx)
           Tasks: 28
          Memory: 145.1M
             CPU: 29min 8.372s
          CGroup: /system.slice/nginx.service
                  ├─ 1578 Passenger watchdog                                                      
                  ├─ 1586 Passenger core                                                      
                  ├─ 1592 Passenger ust-router                                                      
                  ├─ 1605 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
                  ├─ 1611 nginx: worker process                           
                  └─11046 Passenger RubyApp: /home/deploy/rdi-brinson/current/public (production
       
    ✔ 01 david@github.com 0.299s

Deploy a static site

const deployer = new Deployer(config)
const commands = []

commands.push({
  header: 'StaticPage:Create'
})

commands.push({
  command: 'echo "<htlm><body>Test Page</body></html>" > index.html',
  local: true
})

commands.push({
  header: 'StaticPage:Transfer'
})

commands.push({
  command: 'mkdir -p sites/github',
})

commands.push({
  command: 'scp index.html david@github.com:~/sites/github/',
  local: true
})

commands.push({
  header: 'StaticPage:CleanUp'
})

commands.push({
  command: 'rm index.html',
  local: true
})

deployer.deploy(commands)

Will show:

00:00 StaticPage:Create
      01 echo "<htlm><body>Test Page</body></html>" > index.html 
    ✔ 01 local 0.215s
00:00 StaticPage:Transfer
      01 mkdir -p sites/github 
    ✔ 01 david@github.com 0.297s
      02 scp index.html david@github:~/sites/github/ 
    ✔ 02 local 1.789s
00:02 StaticPage:CleanUp
      01 rm index.html 
    ✔ 01 local 0.165s

Remove the oldest file in a folder

const deployer = new Deployer(config)
const commands = []

releases_path = '/home/deploy/apps/github/releases'

commands.push({
  header: 'Deploy:Remove oldest'
})

commands.push({
  command: ['ls', '-dtr', releases_path + '/*'].join(' '),
  showResults: true
})

commands.push({
  dynamic: function(lastResult, code) {
    var oldestDirectory = lastResult.split('\n')[0]

    return { command: ['rm -rf', oldestDirectory].join(' ') }
  }
})

deployer.deploy(commands)

Will show:

00:00 Deploy:Remove oldest
      01 ls -dtr /home/deploy/apps/github/releases/* 
       /home/deploy/apps/github/releases/20170808-01
       /home/deploy/apps/github/releases/20170808-02
       /home/deploy/apps/github/releases/20170809-01
       /home/deploy/apps/github/releases/20170809-02
       /home/deploy/apps/github/releases/20170809-03
       
    ✔ 01 david@github,com 0.341s
      02 rm -rf /home/deploy/apps/github/releases/20170808-01 
    ✔ 02 david@github.com 0.299s

Licence

MIT

0.2.3

6 years ago

0.2.2

6 years ago

0.1.9

6 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago