Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Fix #28: Add a post processing function to deploy
Browse files Browse the repository at this point in the history
- Let user doing stuff with file after Github download
- Will permit activation of a higher Log Level in Capistrano
  • Loading branch information
athieriot committed Jul 12, 2013
1 parent cc67748 commit 618a8d0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions .albot.json.template
Expand Up @@ -19,6 +19,7 @@
"args": [],
"branchArg": "{{branch}}",
"env": [],
"postProcessFile": "function(path, content, callback) { callback(null, content); }",
"gistId": ""
},
"changelog": {
Expand Down
5 changes: 3 additions & 2 deletions .albot.test.json
Expand Up @@ -19,9 +19,10 @@
"frequency": 6000
},
"deploy": {
"exec": "ls",
"args": ["-hR"],
"exec": "cat",
"args": ["Capfile", "app/config/deploy.rb"],
"env": ["Capfile", "app/config/deploy.rb"],
"postProcessFile": "function(path, content, callback) { callback(null, \"- PROCESSED: \" + content); }",
"gistId": "test-gist"
},
"changelog": {
Expand Down
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -116,6 +116,13 @@ You can also specify the way the branch name is passed to the script. {{branch}}

"branchArg": "-Sbranch={{branch}}",

In case you need to post process the files after the download, you can declare a function for it:

"postProcessFile": "function(path, content, callback) { callback(null, content); }",

The function gives you three arguments: The path, the content and a standard Node.js styled callback(err, content).
The Deploy command will evaluate it, so please keep it small!

If you have big project names, you can set pairs of key/value as aliases

"webapp": "client-webapp-front"
Expand Down Expand Up @@ -210,13 +217,14 @@ If you are more comfortable with env variables. You can use that too.
- __args__, A list of arguments to pass to. Default: []
- __branchArg__, Another argument with the branch name. Default: {{branch}}
- __env__, List of files do download from Github and create a directory with. Default: []
- __postProcessFile__, A function allowing you to post process the files after download. Default: ""
- __gistId__, Gist id for the execution logs
- __changelog__,
- __gistId__, Gist id for the saved changelogs
- __amazon__,
- __key__, The Amazon Key
- __secret__, Amazon Secret
- __region__, The region of your instances
- __region__, The region of your instances. Default: "eu-west-1"

## Hacking

Expand Down
16 changes: 14 additions & 2 deletions lib/configuration.coffee
@@ -1,6 +1,11 @@
Nconf = require 'nconf'
_ = require('underscore')._

Fs = require 'fs'
Path = require 'path'

Funcster = require 'funcster'

HipchatApi = require 'hipchat'
GithubApi = require 'github'
Winston = require 'winston'
Expand Down Expand Up @@ -35,12 +40,13 @@ Nconf
},
"deploy": {
"args": [],
"env": []
"env": [],
"postProcessFile": ""
},
"amazon": {
"key": "",
"secret": "",
"region": ""
"region": "eu-west-1"
}
}

Expand Down Expand Up @@ -100,4 +106,10 @@ module.exports =
initLogger: initLogger,
logger: @logger || initLogger()
},
Deploy: _.extend(Nconf.get('deploy'), {
postProcessFunction: if Nconf.get('deploy').postProcessFile then Funcster.deepDeserialize(
{ __js_function: Nconf.get('deploy').postProcessFile },
{ globals: { console: console } }
)
}),
Version: JSON.parse(Fs.readFileSync(Path.resolve(__dirname, '../package.json'), 'utf8')).version
10 changes: 8 additions & 2 deletions lib/deploy.coffee
Expand Up @@ -2,7 +2,7 @@ Configuration = require './configuration'
_ = require('underscore')._

Github = Configuration.Github
Deploy = Configuration.Nconf.get('deploy')
Deploy = Configuration.Deploy
Aliases = Configuration.Nconf.get('aliases')
Async = require 'async'
Spawn = require('child_process').spawn
Expand Down Expand Up @@ -32,7 +32,13 @@ prepareEnv = (repo, ref, callback) ->
Mkdirp Path.join(dirPath, Path.dirname(file)), waterCallback

, (made, waterCallback) ->
Fs.writeFile Path.join(dirPath, filePath), script, waterCallback
if (_.isFunction(Deploy.postProcessFunction))
Deploy.postProcessFunction filePath, script, waterCallback
else
waterCallback(null, script)

, (postProcessedScript, waterCallback) ->
Fs.writeFile Path.join(dirPath, filePath), postProcessedScript, waterCallback

], (waterr) ->
cb(waterr)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -29,7 +29,8 @@
"temp": "~0.5.0",
"aws-sdk": "~1.3.1",
"winston": "~0.7.2",
"xregexp": "~2.0.0"
"xregexp": "~2.0.0",
"funcster": "0.0.2"
},
"devDependencies": {
"chai": "~1.7.0",
Expand Down
6 changes: 3 additions & 3 deletions test/commands/deploy.coffee
Expand Up @@ -12,19 +12,19 @@ describe 'Commands', () ->
.get('/repos/testorg/test-deployable/contents/Capfile?ref=branche&access_token=testtoken')
.reply(200, {
"encoding": "base64",
"content": "Ceci est un README",
"content": new Buffer("Ceci est un README").toString('base64'),
"path": "Capfile"
})
.get('/repos/testorg/test-deployable/contents/app%2Fconfig%2Fdeploy.rb?ref=branche&access_token=testtoken')
.reply(200, {
"encoding": "base64",
"content": "Un fichier de configuration\nMouhahah",
"content": new Buffer("Un fichier de configuration\nMouhahah").toString('base64'),
"path": "app/config/deploy.rb"
})
.intercept('/gists/test-gist?access_token=testtoken', 'PATCH', {
files: {
"history": {
content: ".:\napp\nCapfile\n\n./app:\nconfig\n\n./app/config:\ndeploy.rb\n"
content: "- PROCESSED: Ceci est un README- PROCESSED: Un fichier de configuration\nMouhahah"
}
}
})
Expand Down

0 comments on commit 618a8d0

Please sign in to comment.