Skip to content

Instantly share code, notes, and snippets.

@Termina1
Created April 7, 2014 13:40
Show Gist options
  • Save Termina1/10020494 to your computer and use it in GitHub Desktop.
Save Termina1/10020494 to your computer and use it in GitHub Desktop.
fs = require('fs')
Flightplan = require("./.node_modules/flightplan") # we need to install flightplane to .node_modules for meteor to ignore it
path = require('path')
plan = new Flightplan()
releaseFile = "release.tar.tgz" # name of the bundle generated by meteor
workPath = '/home/user/path' # path to the project folder
releaseFolder = 'rel' + Date.now()
releasePath = path.join(workPath, releaseFolder)
passengerIntegration = (remote) ->
bundle = path.join(releasePath, 'bundle')
remote.log 'Creating additional dirs for Passenger'
remote.exec "cd #{bundle} && mkdir public"
remote.exec "cd #{bundle} && mkdir tmp"
remote.exec "cd #{bundle} && touch tmp/restart.txt"
# configuration
plan.briefing
debug: false
destinations:
production: [
{
host: "destination.com"
username: "user"
agent: process.env.SSH_AUTH_SOCK
}
]
# run commands on localhost
plan.remote (remote) ->
remote.exec "cd #{workPath} && mkdir #{releaseFolder}"
plan.local (local) ->
local.log "Run meteor bundle"
local.exec "meteor bundle #{releaseFile}"
local.log "Copy files to remote hosts"
local.transfer [releaseFile], releasePath
# run commands on remote hosts (destinations)
plan.remote (remote) ->
remote.log "Extracting package"
remote.exec "cd #{releasePath} && tar -xzf #{releaseFile}"
remote.exec "cd #{releasePath} && rm #{releaseFile}"
remote.log "Installing fibers"
remote.exec "cd #{releasePath}/bundle/programs/server && npm install fibers"
passengerIntegration(remote) # some phusion passenger integration steps
remote.log "Relink current release dir to new directory"
remote.exec "cd #{workPath} && if [ -d current ] ; then rm current ; fi && ln -s #{releaseFolder} current"
remote.log "Remove all old releases"
remote.exec "cd #{workPath} && find . -maxdepth 1 -type d -not -name '#{releaseFolder}' -not -name '.' | xargs rm -rf"
plan.debriefing ->
fs.unlink releaseFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment