sabre 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deploy.gemspec
4
+ gemspec
5
+
6
+ gem "voke", :path => "../voke"
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Luke Curley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Sabre
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sabre'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sabre
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+
4
+ require "sabre"
5
+ require "voke"
6
+
7
+ class SabreCLI
8
+ include Voke
9
+
10
+ def run(script = nil, options)
11
+ puts script.inspect
12
+ puts options.inspect
13
+ end
14
+ end
15
+
16
+ cli = SabreCLI.new
17
+ cli.voke("run", *ARGV)
@@ -0,0 +1,13 @@
1
+ require "bundler/setup"
2
+ require "sabre"
3
+
4
+ deployment = Sabre::Command.new do
5
+ git.update(repository: "https://github.com/qpingu/sabre.git",
6
+ directory: "test_deploy/shared")
7
+
8
+ release.create("test_deploy") do
9
+ cp("test_deploy/shared", "$RELEASE")
10
+ end
11
+ end
12
+
13
+ puts deployment
@@ -0,0 +1,24 @@
1
+ require "bundler/setup"
2
+ require "sabre"
3
+
4
+ errors = Sabre::Command.new do
5
+ run do
6
+ echo "step 1"
7
+ synchronize
8
+
9
+ on_error { echo "step 1 failed" }
10
+ end
11
+
12
+ run do
13
+ echo "step 2"
14
+ synchronize
15
+
16
+ on_error { echo "step 2 failed" }
17
+ end
18
+
19
+ echo "finished"
20
+
21
+ on_error { echo "something failed" }
22
+ end
23
+
24
+ puts errors
@@ -0,0 +1,7 @@
1
+ require "sabre/version"
2
+ require "sabre/command"
3
+
4
+ require "sabre/base"
5
+ require "sabre/bundler"
6
+ require "sabre/git"
7
+ require "sabre/release"
@@ -0,0 +1,29 @@
1
+ module Sabre::Base
2
+ def echo(string)
3
+ run %{ echo "#{ string }" }
4
+ end
5
+
6
+ def cd(directory)
7
+ run %{ cd "#{ directory }" }
8
+ end
9
+
10
+ def cp(source, target)
11
+ run %{ cp -R "#{ source }" "#{ target }" }
12
+ end
13
+
14
+ def mv(source, target)
15
+ run %{ mv "#{ source }" "#{ target }" }
16
+ end
17
+
18
+ def set(name, value)
19
+ run %{ #{ name }="#{ value }" }
20
+ end
21
+
22
+ def synchronize
23
+ run %{
24
+ read -n1 -p "Continue? (y/n) " &&
25
+ echo &&
26
+ [[ $REPLY == "y" ]]
27
+ }
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ require 'sabre/command'
2
+
3
+ class Sabre::Bundler < Sabre::Command
4
+ def install(options)
5
+ directory = options[:directory]
6
+ without = options[:without]
7
+
8
+ cd directory
9
+ run "bundle install --deployment --quiet --without #{ without.join(" ") }"
10
+ echo "Bundle installed"
11
+ end
12
+ end
@@ -0,0 +1,111 @@
1
+ require 'blockenspiel'
2
+
3
+ require 'sabre/base'
4
+
5
+ class Sabre::Command
6
+ include Blockenspiel::DSL
7
+ include Sabre::Base
8
+
9
+ def initialize(&block)
10
+ @commands = Array.new
11
+ @error_commands = Array.new
12
+ @conditions = Array.new
13
+
14
+ Blockenspiel.invoke(block, self) if block
15
+ end
16
+
17
+ def run(command = nil, &block)
18
+ if block
19
+ command = Sabre::Command.new(&block)
20
+ elsif command.is_a?(String)
21
+ command = unindent(command)
22
+ end
23
+
24
+ @commands << command
25
+ command
26
+ end
27
+
28
+ def on(conditions, &block)
29
+ if block
30
+ command = Sabre::Command.new(&block)
31
+ command.on(conditions)
32
+
33
+ run(command)
34
+ else
35
+ conditions = Array(conditions)
36
+ @conditions += conditions
37
+ end
38
+ end
39
+
40
+ def on_host(*hosts, &block)
41
+ conditions = hosts.collect do |h|
42
+ if h.is_a?(Regexp)
43
+ "[[ `hostname -f` =~ \"#{ h.source }\" ]]"
44
+ else
45
+ "[[ `hostname -f` == \"#{ h }\" ]]"
46
+ end
47
+ end
48
+
49
+ condition = conditions.join(" || ")
50
+ on(condition, &block)
51
+ end
52
+
53
+ def on_error(command = nil, &block)
54
+ if block
55
+ command = Sabre::Command.new(&block)
56
+ elsif command.is_a?(String)
57
+ command = unindent(command)
58
+ end
59
+
60
+ @error_commands << command
61
+ command
62
+ end
63
+
64
+ def indent(command)
65
+ command.to_s.gsub(/^/, " ")
66
+ end
67
+
68
+ def unindent(command)
69
+ command = command.to_s
70
+
71
+ if command =~ /^\n([ \t]+)/
72
+ command = command.gsub(/^#{ $1 }/, '')
73
+ end
74
+
75
+ command.strip
76
+ end
77
+
78
+ def to_s
79
+ command = @commands.join(" &&\n")
80
+
81
+ unless @error_commands.empty?
82
+ error_command = @error_commands.join(" &&\n")
83
+ command = "{\n#{ indent(command) };\n} || {\n#{ indent(error_command) } && false;\n}"
84
+ end
85
+
86
+ unless @conditions.empty?
87
+ condition = @conditions.join(" &&\n")
88
+
89
+ command = unindent %{
90
+ if #{ condition }; then
91
+ #{ indent(command) };
92
+ fi
93
+ }
94
+ end
95
+
96
+ command
97
+ end
98
+
99
+ def method_missing(sym, *args, &block)
100
+ # provides "undef.method" -> "run Undef.new.method"
101
+ klass_name = sym.to_s.capitalize
102
+ klass = Sabre.const_get(klass_name) rescue nil
103
+
104
+ super unless klass
105
+
106
+ command = klass.new(&block)
107
+ run command # note: this object will be modified later!
108
+
109
+ command
110
+ end
111
+ end
@@ -0,0 +1,49 @@
1
+ require 'sabre/command'
2
+
3
+ class Sabre::Git < Sabre::Command
4
+ def clone(options)
5
+ repository = options[:repository]
6
+ directory = options[:directory]
7
+
8
+ branch = options[:branch] || "publish"
9
+ remote = options[:remote] || "origin"
10
+
11
+ revision = options[:revision] || "#{ remote }/#{ branch }"
12
+
13
+ run "mkdir -p #{ directory }"
14
+ run "git clone -o #{ remote } -b #{ branch } #{ repository } #{ directory }"
15
+ end
16
+
17
+ def fetch(options)
18
+ repository = options[:repository]
19
+ directory = options[:directory]
20
+
21
+ branch = options[:branch] || "publish"
22
+ remote = options[:remote] || "origin"
23
+
24
+ revision = options[:revision] || "#{ remote }/#{ branch }"
25
+
26
+ cd directory
27
+ run "git config remote.#{ remote }.url #{ repository }"
28
+ run "git config remote.#{ remote }.fetch +refs/heads/*:refs/remotes/#{ remote }/*"
29
+ run "git fetch #{ remote }"
30
+ run "git fetch --tags #{ remote }"
31
+ run "git checkout -f -q #{ branch }"
32
+ run "git reset --hard #{ revision }"
33
+ end
34
+
35
+ def update(options)
36
+ directory = options[:directory]
37
+
38
+ fetch_command = Sabre::Git.new { fetch(options) }
39
+ clone_command = Sabre::Git.new { clone(options) }
40
+
41
+ run %{
42
+ if [ -d "#{ directory }/.git" ]; then
43
+ #{ indent fetch_command }
44
+ else
45
+ #{ indent clone_command }
46
+ fi
47
+ }
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ require 'sabre/command'
2
+
3
+ class Sabre::Release < Sabre::Command
4
+ def create(directory, options = Hash.new, &block)
5
+ current = options[:current] || "#{ directory }/current"
6
+ releases = options[:releases] || "#{ directory }/releases"
7
+
8
+ set "RELEASE", "#{ releases }/`date +%s`"
9
+ run %{ mkdir -p "$RELEASE" }
10
+
11
+ run(&block)
12
+
13
+ run %{ rm -f "#{ current }" }
14
+ run %{ ln -s "$RELEASE" "#{ current }" }
15
+
16
+ on_error do
17
+ run %{ rm -rf "$RELEASE" }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Sabre
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sabre/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sabre"
8
+ gem.version = Sabre::VERSION
9
+ gem.authors = ["Luke Curley"]
10
+ gem.email = ["qpingu@gmail.com"]
11
+ gem.description = %q{Deployment DSL that translates into bash}
12
+ gem.summary = %q{Deployment DSL that translates into bash}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "blockenspiel"
21
+ gem.add_dependency "voke"
22
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sabre
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Luke Curley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: blockenspiel
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: voke
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Deployment DSL that translates into bash
47
+ email:
48
+ - qpingu@gmail.com
49
+ executables:
50
+ - sabre
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/sabre
60
+ - examples/deployment.rb
61
+ - examples/errors.rb
62
+ - lib/sabre.rb
63
+ - lib/sabre/base.rb
64
+ - lib/sabre/bundler.rb
65
+ - lib/sabre/command.rb
66
+ - lib/sabre/git.rb
67
+ - lib/sabre/release.rb
68
+ - lib/sabre/version.rb
69
+ - sabre.gemspec
70
+ homepage: ''
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.23
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Deployment DSL that translates into bash
94
+ test_files: []