Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit af672998523cf85c2916576eb520392c2ba4c5ef @brentd committed Sep 12, 2010
Showing with 156 additions and 0 deletions.
  1. 0 README.markdown
  2. +14 −0 Rakefile
  3. +1 −0 VERSION
  4. +2 −0 bin/gitploy
  5. +38 −0 gitploy.gemspec
  6. +101 −0 lib/gitploy.rb
0 README.markdown
No changes.
14 Rakefile
@@ -0,0 +1,14 @@
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gemspec|
+ gemspec.name = "gitploy"
+ gemspec.summary = "Deployment DSL created with git in mind"
+ gemspec.description = "Dead-simple deployments. No, for real this time."
+ gemspec.email = "brentdillingham@gmail.com"
+ gemspec.homepage = "http://github.com/brentd/gitploy"
+ gemspec.authors = ["Brent Dillingham"]
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
+end
1 VERSION
@@ -0,0 +1 @@
+0.1.0
2 bin/gitploy
@@ -0,0 +1,2 @@
+#!/usr/bin/env ruby
+load('config/deploy.rb')
38 gitploy.gemspec
@@ -0,0 +1,38 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{gitploy}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Brent Dillingham"]
+ s.date = %q{2010-09-11}
+ s.default_executable = %q{gitploy}
+ s.description = %q{Dead-simple deployments. No, for real this time.}
+ s.email = %q{brentdillingham@gmail.com}
+ s.executables = ["gitploy"]
+ s.files = [
+ "Rakefile",
+ "VERSION",
+ "lib/gitploy.rb"
+ ]
+ s.homepage = %q{http://github.com/brentd/gitploy}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{Deployment DSL created with git in mind}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
+
101 lib/gitploy.rb
@@ -0,0 +1,101 @@
+module Gitploy
+ extend self
+ attr_accessor :config
+
+ class Config
+ REQUIRED_OPTIONS = [:repo, :path, :user, :host]
+ attr_accessor *REQUIRED_OPTIONS
+
+ def check!
+ unless missing_options.empty?
+ raise "The following configuration options are missing for the '#{Gitploy.current_stage}' stage: #{missing_options.join(', ')}"
+ end
+ end
+
+ def missing_options
+ REQUIRED_OPTIONS.select {|m| send(m) == nil }
+ end
+ end
+
+ def configure
+ config = Config.new
+ yield config; config.check!
+ self.config = config
+ end
+
+ def current_stage
+ ARGV[0]
+ end
+
+ def stage(name)
+ yield if name.to_s == current_stage
+ end
+
+ def deploy
+ yield if ARGV[1].nil?
+ end
+
+ def setup
+ yield if ARGV[1] == 'setup'
+ end
+
+ def remote
+ yield
+ pretty_run(config.host, "ssh #{config.user}@#{config.host} '#{flush_run_queue}'")
+ end
+
+ def local
+ yield
+ pretty_run("LOCAL", flush_run_queue)
+ end
+
+ def run(cmd)
+ run_queue << cmd
+ end
+
+ def sudo(cmd)
+ run("sudo #{cmd}")
+ end
+
+ def rake(task)
+ run("rake #{task}")
+ end
+
+ def push
+ local { run "git push #{config.user}@#{config.host}:#{config.path}/.git master" }
+ end
+
+ private
+
+ def pretty_run(title, cmd)
+ puts
+ print_bar(100, title)
+ puts "> #{cmd}"
+ puts
+ Kernel.system(cmd)
+ print_bar(100)
+ end
+
+ def print_bar(width, title=nil)
+ if title
+ half_width = (width / 2) - (title.length / 2) - 2
+ left_bar = '=' * half_width
+ right_bar = '=' * (title.length % 2 == 0 ? half_width : half_width - 1)
+ puts "#{left_bar}( #{title} )#{right_bar}"
+ else
+ puts "=" * width
+ end
+ end
+
+ def run_queue
+ @run_queue ||= []
+ end
+
+ def flush_run_queue
+ cmd = run_queue.join(' && ')
+ @run_queue = []
+ cmd
+ end
+end
+
+include Gitploy

0 comments on commit af67299

Please sign in to comment.