Created
June 25, 2012 11:48
-
-
Save sapegin/2988147 to your computer and use it in GitHub Desktop.
Simple script for sites deployment
This file contains hidden or 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
| # Simple script for site deployment | |
| # | |
| # Required environment variables: | |
| # * HUBOT_DEPLOY_DIR - Directory with projects | |
| # | |
| # Project directory structure: | |
| # * HUBOT_DEPLOY_DIR/ | |
| # * site | |
| # * deploy.sh | |
| # * htdocs, etc. | |
| # | |
| # deploy.sh template: | |
| # | |
| # default() { | |
| # git pull && swe | |
| # } | |
| # | |
| # upgrade() { | |
| # npm update | |
| # } | |
| # | |
| # if [ "$1" = "upgrade" ] | |
| # then upgrade | |
| # else default | |
| # fi | |
| # | |
| # deploy me <site> - Deploys <site> to production. | |
| # upgrade me <site> - Upgrade <site>'s environment. | |
| path = require "path" | |
| {exec} = require "child_process" | |
| deployDir = process.env.HUBOT_DEPLOY_DIR | |
| module.exports = (robot) -> | |
| robot.respond /(deploy|upgrade)(?: me)? (.+)/i, (msg) -> | |
| upgrade = msg.match[1] is "upgrade" | |
| project = msg.match[2] | |
| if not deployDir | |
| msg.send "HUBOT_DEPLOY_DIR environment variable should be defined." | |
| return | |
| if project | |
| projectDir = path.join deployDir, project | |
| deployScript = path.join projectDir, 'deploy.sh' | |
| if not path.existsSync deployScript | |
| msg.send "Project not found or doesn’t have deploy.sh file." | |
| return | |
| if upgrade | |
| msg.send "Upgrading…" | |
| else | |
| msg.send "Deploying…" | |
| cmd = "sh " + deployScript | |
| if upgrade then cmd += " upgrade" | |
| process.chdir projectDir | |
| exec cmd, (err, stdout, stderr) -> | |
| if err | |
| msg.send "Can’t deploy." | |
| msg.send err.message | |
| return | |
| else if stderr | |
| msg.send "Can’t deploy." | |
| msg.send stderr | |
| return | |
| else if stdout | |
| msg.send stdout | |
| msg.send "Done, sir!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment