Skip to content
Browse files

Support git repo on local filesystem

Instead of using GitHub, you can now point Clickistrano at a git repo in
the local filesystem. This is only particularly useful if you use your
own private server for Git shared repo hosting, and can also practically
use that server to run Clickistrano.
  • Loading branch information...
1 parent 965e146 commit 7e899e49a6d88e4445f88474b228b7e477925693 Mat Brown committed Jan 5, 2010
Showing with 86 additions and 36 deletions.
  1. +10 −6 README.mkd
  2. +1 −1 clickistrano.rb
  3. +17 −29 lib/config_puller.rb
  4. +32 −0 lib/config_puller/github.rb
  5. +26 −0 lib/config_puller/local.rb
View
16 README.mkd
@@ -6,7 +6,7 @@ using a simple web interface. Clickistrano might be useful for you if:
* You have members of your team who need to run deployments, but don't keep a
copy of your source checked out (e.g. product managers, QA engineers).
* You deploy using environment tasks (e.g. `cap qa deploy`)
-* You use Github for source control hosting.
+* You use Github or your own private server for source control hosting.
## Installation and Configuration
@@ -18,19 +18,22 @@ doing so. Just pick a good directory for the server, and check it out:
Clickistrano is configured with a `config.yml` file in the root directory.
It requires the following keys:
+<dt>adapter</dt>
+<dd>Either "github" or "local"</dd>
<dt>account</dt>
-<dd>The github account that hosts your repository</dd>
+<dd>The github account that hosts your repository (GitHub adapter only)</dd>
<dt>repository</dt>
-<dd>The name of the repository on github</dd>
+<dd>The name of the repository on github, or the path to the local git repo</dd>
<dt>token</dt>
-<dd>Your github API token. Go to the 'account' screen on GitHub to get this</dd>
+<dd>Your github API token. Go to the 'account' screen on GitHub to get this
+(GitHub adapter only)</dd>
<dt>environment</dt>
<dd>The environment you want to deploy to (i.e., cap &lt;environment&gt; deploy)</dd>
<dt>cap</dt>
<dd>Path to the cap executable on your system</dd>
If you're running this on a new machine, you will need to add the machine's SSH
-public key to your EngineYard account.
+public key to your deployment environment.
## Running it
@@ -41,7 +44,7 @@ directory:
There is also a sample init script in `example/clickistrano.sh`
-## Dependencies (all available on RubyForge)
+## Dependencies (all available on Gemcutter)
* capistrano
* escape
@@ -50,6 +53,7 @@ There is also a sample init script in `example/clickistrano.sh`
* rack
* sinatra
* thin
+* grit (local adapter only)
## How it works
View
2 clickistrano.rb
@@ -24,7 +24,7 @@
branch = params[:branch]
File.open('state/last_branch', 'w') { |f| f << branch }
config = File.open('config.yml') { |f| YAML.load(f) }
- ConfigPuller.new(config).pull(%w(config/deploy.rb Capfile), branch)
+ ConfigPuller[config['adapter'] || 'github'].new(config).pull(%w(config/deploy.rb Capfile), branch)
pid = fork do
DeployRunner.new(config).run
exit
View
46 lib/config_puller.rb
@@ -1,40 +1,28 @@
require 'fileutils'
-class ConfigPuller
- ConfigRequestError = Class.new(StandardError)
+module ConfigPuller
+ autoload :Github, File.join(File.dirname(__FILE__), 'config_puller', 'github')
+ autoload :Local, File.join(File.dirname(__FILE__), 'config_puller', 'local')
- def initialize(config)
- @config = config
- end
-
- def pull(files, branch)
- http = Net::HTTP.new('github.com', 443)
- http.use_ssl = true
- files.each do |path|
- request_path = "/#{account}/#{repository}/raw/#{branch}/#{path}?login=#{account}&token=#{token}"
- puts request_path
- response = http.get(request_path)
- if response.code == '200'
- file_path = "caproot/#{path}"
- FileUtils.mkdir_p(File.dirname(file_path))
- File.open(file_path, 'w') { |f| f << response.body }
- else
- raise ConfigRequestError, "Got response code #{response.code} when requesting #{request_path}"
- end
+ class <<self
+ def [](name)
+ const_get(name.split("_").map { |part| part.capitalize }.join)
end
end
- private
+ class Abstract
+ ConfigRequestError = Class.new(StandardError)
- def repository
- @config['repository']
- end
+ def initialize(config)
+ @config = config
+ end
- def account
- @config['account']
- end
+ private
- def token
- @config['token']
+ def write_file(path, contents)
+ file_path = File.join('caproot', path)
+ FileUtils.mkdir_p(File.dirname(file_path))
+ File.open(file_path, 'w') { |f| f << contents }
+ end
end
end
View
32 lib/config_puller/github.rb
@@ -0,0 +1,32 @@
+module ConfigPuller
+ class Github < Abstract
+ def pull(files, branch)
+ http = Net::HTTP.new('github.com', 443)
+ http.use_ssl = true
+ files.each do |path|
+ request_path = "/#{account}/#{repository}/raw/#{branch}/#{path}?login=#{account}&token=#{token}"
+ puts request_path
+ response = http.get(request_path)
+ if response.code == '200'
+ write_file(response.body)
+ else
+ raise ConfigRequestError, "Got response code #{response.code} when requesting #{request_path}"
+ end
+ end
+ end
+
+ private
+
+ def repository
+ @config['repository']
+ end
+
+ def account
+ @config['account']
+ end
+
+ def token
+ @config['token']
+ end
+ end
+end
View
26 lib/config_puller/local.rb
@@ -0,0 +1,26 @@
+using_gems = false
+begin
+ require 'grit'
+rescue LoadError => e
+ raise(e) if using_gems
+ using_gems = true
+ retry
+end
+
+module ConfigPuller
+ class Local < Abstract
+ def pull(files, branch)
+ repo = Grit::Repo.new(repository)
+ commit = repo.get_head(branch).commit
+ files.each do |path|
+ write_file(path, (repo.tree(commit.id) / path).data)
+ end
+ end
+
+ private
+
+ def repository
+ @config['repository']
+ end
+ end
+end

0 comments on commit 7e899e4

Please sign in to comment.
Something went wrong with that request. Please try again.