Skip to content

Commit

Permalink
Support git repo on local filesystem
Browse files Browse the repository at this point in the history
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
Mat Brown committed Jan 5, 2010
1 parent 965e146 commit 7e899e4
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 36 deletions.
16 changes: 10 additions & 6 deletions README.mkd
Expand Up @@ -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 * 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). copy of your source checked out (e.g. product managers, QA engineers).
* You deploy using environment tasks (e.g. `cap qa deploy`) * 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 ## Installation and Configuration


Expand All @@ -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. Clickistrano is configured with a `config.yml` file in the root directory.
It requires the following keys: It requires the following keys:


<dt>adapter</dt>
<dd>Either "github" or "local"</dd>
<dt>account</dt> <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> <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> <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> <dt>environment</dt>
<dd>The environment you want to deploy to (i.e., cap &lt;environment&gt; deploy)</dd> <dd>The environment you want to deploy to (i.e., cap &lt;environment&gt; deploy)</dd>
<dt>cap</dt> <dt>cap</dt>
<dd>Path to the cap executable on your system</dd> <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 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 ## Running it


Expand All @@ -41,7 +44,7 @@ directory:


There is also a sample init script in `example/clickistrano.sh` There is also a sample init script in `example/clickistrano.sh`


## Dependencies (all available on RubyForge) ## Dependencies (all available on Gemcutter)


* capistrano * capistrano
* escape * escape
Expand All @@ -50,6 +53,7 @@ There is also a sample init script in `example/clickistrano.sh`
* rack * rack
* sinatra * sinatra
* thin * thin
* grit (local adapter only)


## How it works ## How it works


Expand Down
2 changes: 1 addition & 1 deletion clickistrano.rb
Expand Up @@ -24,7 +24,7 @@
branch = params[:branch] branch = params[:branch]
File.open('state/last_branch', 'w') { |f| f << branch } File.open('state/last_branch', 'w') { |f| f << branch }
config = File.open('config.yml') { |f| YAML.load(f) } 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 pid = fork do
DeployRunner.new(config).run DeployRunner.new(config).run
exit exit
Expand Down
46 changes: 17 additions & 29 deletions lib/config_puller.rb
@@ -1,40 +1,28 @@
require 'fileutils' require 'fileutils'


class ConfigPuller module ConfigPuller
ConfigRequestError = Class.new(StandardError) autoload :Github, File.join(File.dirname(__FILE__), 'config_puller', 'github')
autoload :Local, File.join(File.dirname(__FILE__), 'config_puller', 'local')


def initialize(config) class <<self
@config = config def [](name)
end const_get(name.split("_").map { |part| part.capitalize }.join)

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
end end
end end


private class Abstract
ConfigRequestError = Class.new(StandardError)


def repository def initialize(config)
@config['repository'] @config = config
end end


def account private
@config['account']
end


def token def write_file(path, contents)
@config['token'] file_path = File.join('caproot', path)
FileUtils.mkdir_p(File.dirname(file_path))
File.open(file_path, 'w') { |f| f << contents }
end
end end
end end
32 changes: 32 additions & 0 deletions 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
26 changes: 26 additions & 0 deletions 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.