Created
January 9, 2018 17:13
-
-
Save lucassmacedo/3d1ee0f5388996f7bd2842fc192a8ae6 to your computer and use it in GitHub Desktop.
Flightplan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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