Skip to content

Instantly share code, notes, and snippets.

@lucassmacedo
Created January 9, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucassmacedo/3d1ee0f5388996f7bd2842fc192a8ae6 to your computer and use it in GitHub Desktop.
Save lucassmacedo/3d1ee0f5388996f7bd2842fc192a8ae6 to your computer and use it in GitHub Desktop.
Flightplan
const plan = require('flightplan')
const moment = require('moment')
const username = 'forge'
const currentTime = new Date().getTime()
const tmpDir = 'releases/build-' + moment(currentTime).format('DD-MM-YYYY_HH-mm')
plan.target('production', {
host: '000.000.00.00',
username: username,
webRoot: '/home/app.myapp.com.br',
privateKey: `${process.env.HOME}/.ssh/id_rsa`,
agent: process.env.SSH_AUTH_SOCK
})
plan.target('develop', {
host: '000.000.00.00',
username: username,
webRoot: '/home/develop.myapp.com.br',
privateKey: `${process.env.HOME}/.ssh/id_rsa`,
agent: process.env.SSH_AUTH_SOCK
})
// run commands on localhost
plan.local((local) => {
const folderTo = local._context.hosts[0].webRoot
local.log('Copy files to remote hosts')
const filesToCopy = local.find('dist/ -type f', {silent: true}).stdout.split('\n')
// rsync files to all the destination's hosts
local.transfer(filesToCopy, folderTo + '/' + tmpDir)
})
plan.remote(function (remote) {
const webRoot = remote.runtime.webRoot // fly staging -> '/usr/local/www'
remote.log('Reload application')
remote.sudo('ln -snf ' + webRoot + '/' + tmpDir + ' ' + webRoot + '/build', {user: username})
remote.log('Finish deploy application')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment