-
-
Save dejanr/3690941 to your computer and use it in GitHub Desktop.
A CoffeeScript Cakefile to generate a control deploy.coffee file for your application
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
fs = require 'fs' | |
control = require 'control' | |
task = control.task | |
task "deploy_script", "Creates a deployment script for your application", -> | |
appName = "appName" | |
serverEnvironment = "staging" | |
serverAddress = "myserver.com" | |
sshUsername = "app" | |
startCommand = "/etc/init.d/#{appName} start" | |
stopCommand = "/etc/init.d/#{appName} stop" | |
restartCommand = "/etc/init.d/#{appName} restart" | |
deployCommand = "cd /var/www/#{appName} && git pull origin master && npm install" | |
content = [] | |
content.push "####################################" | |
content.push "# Deploy Script - Paul Jensen 2011 #" | |
content.push "####################################" | |
content.push "#" | |
content.push "###### Installation ######" | |
content.push "#" | |
content.push "# npm install control" | |
content.push "#" | |
content.push "###### Usage ######" | |
content.push "#" | |
content.push "# e.g. coffee deploy.coffee #{serverEnvironment} deploy" | |
content.push "#" | |
content.push "" | |
content.push "control = require 'control'" | |
content.push "task = control.task" | |
content.push "perform = control.perform" | |
content.push "" | |
content.push "task '#{serverEnvironment}', 'config got my server', ->" | |
content.push "config = user: '#{sshUsername}'" | |
content.push " addresses = ['#{serverAddress}']" | |
content.push " control.hosts config, addresses" | |
content.push "" | |
content.push "task 'stop', 'stop the application', (host) ->" | |
content.push " host.ssh '#{stopCommand}'" | |
content.push "" | |
content.push "task 'start', 'start the application', (host) ->" | |
content.push " host.ssh '#{startCommand}'" | |
content.push "" | |
content.push "task 'restart', 'restart the application', (host) ->" | |
content.push " host.ssh '#{restartCommand}'" | |
content.push "" | |
content.push "task 'deploy', 'deploy the latest version of the app', (host) ->" | |
content.push " host.ssh '#{deployCommand}', ->" | |
content.push " perform 'restart', host" | |
content.push "" | |
fs.writeFile "deploy.coffee", content.join("\n"), (err) -> | |
if err | |
throw err | |
process.exit 1 | |
else | |
console.log "deploy.coffee has been created for you. Enjoy." | |
process.exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment