dragon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ .DS_Store
19
+ Depfile
data/Dragfile ADDED
@@ -0,0 +1,33 @@
1
+ default: &default
2
+ # main settings [REQUIRED]
3
+ # Note, "local_upload_dir" overrides the use of GIT to deploy
4
+ # local_upload_dir: "/Users/isheridan/Documents/personalspace/dragon/files"
5
+ git_url: "git@github.com:USERNAME/repo.git"
6
+ destination_root: "/app/root/path/on/remote/server"
7
+ destination_symlink: "/app/root/path/on/remote/server/current" # web server points to this
8
+ servers:
9
+ - "server1.example.com"
10
+ - "server2.example.com"
11
+ servers_username: "username"
12
+ servers_key_location: "~/.ssh/example.pem"
13
+ # sample commands [OPTIONAL]
14
+ # uncomment this setting if you do not want the default commands to run
15
+ # commands_run_default: no
16
+ commands:
17
+ cd: "{{release_dir}}/ && pwd"
18
+ rm: "-rf {{release_dir}}/log"
19
+ ls: "-nfs {{destination_root}}/shared/log {{release_dir}}"
20
+
21
+ staging:
22
+ <<: *default
23
+ git_branch: "staging"
24
+
25
+ production:
26
+ <<: *default
27
+ git_branch: "production"
28
+ servers:
29
+ - "prodserver1.example.com"
30
+ - "prodserver2.example.com"
31
+ - "prodserver3.example.com"
32
+ - "prodserver4.example.com"
33
+ - "prodserver5.example.com"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Dragon
2
+
3
+ A deployment tool inspired by and is using [Rye][1].
4
+
5
+ ## Install
6
+
7
+ gem install dragon
8
+
9
+ ## Usage
10
+
11
+ ### Dragon
12
+
13
+ Dragon version 0.1.0
14
+
15
+ -h print this usage doc
16
+ -v print version
17
+
18
+ Deploy:
19
+
20
+ dragon [environment]
21
+ dragon [environment] [release]
22
+
23
+ ### Dragify
24
+
25
+ Dragify version 0.1.0
26
+
27
+ -h print this usage doc
28
+ -v print version
29
+
30
+ Deploy:
31
+
32
+ dragify [location_to_dragify]
33
+
34
+ Example
35
+
36
+ dragify .
37
+
38
+ ----
39
+
40
+ ## Copyright
41
+
42
+ Copyright (c) Ian Sheridan, 2013
43
+
44
+ ## License
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
+
52
+ [1]: https://github.com/delano/rye "Rye github"
data/bin/dragify ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'erb'
4
+
5
+
6
+ $:.unshift File.expand_path('../../lib', __FILE__)
7
+ require 'dragon/usage'
8
+ require 'dragon/version'
9
+
10
+ if $*.empty? || $*[0] == '-h'
11
+ puts Dragon.depify_usage
12
+ exit 0
13
+ end
14
+ if $*[0] == '-v'
15
+ puts Dragon::VERSION
16
+ exit 0
17
+ end
18
+
19
+ class Dragify
20
+
21
+ def initialize(root_given)
22
+ @root = root_given
23
+ end
24
+
25
+ def get_binding
26
+ binding
27
+ end
28
+
29
+ end
30
+
31
+ erb_templates_loc = File.expand_path('../../resources/templates', __FILE__)
32
+ template_string = File.join( erb_templates_loc, "dragfile.yaml.erb" )
33
+ template = ERB.new( File.read( template_string ) )
34
+
35
+ controller = Dragify.new( Dir.pwd )
36
+
37
+ # render and save Derfile
38
+ file = File.open("Dragfile","w")
39
+ file.write( template.result(controller.get_binding) )
40
+ file.close
41
+
42
+ puts "Dragfile created in #{ Dir.pwd }"
data/bin/dragon ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'deployer'
5
+ require 'deployer/usage'
6
+ require 'deployer/options'
7
+
8
+ if $*.empty? || $*[0] == '-h'
9
+ puts Deployer.usage
10
+ exit 0
11
+ end
12
+ if $*[0] == '-v'
13
+ puts Deployer::VERSION
14
+ exit 0
15
+ end
16
+
17
+ begin
18
+ options = Deployer::Options.parse( Dir.pwd, $* )
19
+ rescue Deployer::Exceptions::DepfileMissing => e
20
+ puts e.message
21
+ exit 0
22
+ end
23
+ Deployer::Deploy.new(options).run
24
+
25
+ puts
26
+ puts "Done!"
data/dragon.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dragon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dragon"
8
+ spec.version = Dragon::VERSION
9
+ spec.authors = ["Ian Sheridan"]
10
+ spec.email = ["ian.sheridan@gmail.com"]
11
+ spec.description = %q{Dragon a deployment tools inspired by Rye.}
12
+ spec.summary = %q{Deployment tool.}
13
+ spec.homepage = "https://github.com/iansheridan/dragon"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+
25
+ spec.add_dependency "pry"
26
+ spec.add_dependency "rye"
27
+ spec.add_dependency "liquid"
28
+ end
@@ -0,0 +1,23 @@
1
+ module Dragon
2
+ class CommandRunner
3
+
4
+ def initialize( boxes )
5
+ @boxes = boxes
6
+ end
7
+
8
+ def run commands
9
+ commands.each{|k,v|
10
+ puts "runnning: #{ k } #{ v }"
11
+ unless v.empty?
12
+ ran = @boxes.send( k.to_sym, v )
13
+ else
14
+ ran = @boxes.send( k.to_sym )
15
+ end
16
+ puts " output: #{ ran.stdout }" if ran.respond_to? :stdout
17
+ }
18
+ rescue Rye::Err => e
19
+ puts e.message
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ module Dragon
2
+ class Deploy
3
+
4
+ def initialize(options)
5
+ @options = options
6
+ @boxes = Dragon::ServerSet.new @options
7
+ @comrun = Dragon::CommandRunner.new @boxes.set
8
+ end
9
+
10
+ def default_commands sequence
11
+ return {} if @options.local_settings.has_key?( "commands_run_default" )
12
+ {
13
+ use_git: {
14
+ git: "clone --depth=1 --branch=#{ @options.environment } #{ @options.local_settings["git_url"] } #{ @options.release }",
15
+ },
16
+ local_upload: {
17
+ dir_upload: "#{ @options.local_settings["local_upload_dir"] }",
18
+ },
19
+ current_linking: {
20
+ ln: "-nfs #{ @options.release_dir } #{ @options.local_settings["destination_symlink"] }",
21
+ }
22
+ }[sequence]
23
+ end
24
+
25
+ def run
26
+
27
+ # before
28
+ unless @options.local_settings.has_key?( "local_upload_dir" )
29
+ @comrun.run default_commands( :use_git )
30
+ else
31
+ @comrun.run default_commands( :local_upload )
32
+ end
33
+
34
+ # user commands
35
+ @comrun.run @options.local_settings["commands"] if @options.local_settings.has_key?( "commands" )
36
+
37
+ # after
38
+ @comrun.run default_commands( :current_linking )
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Dragon
2
+ # code
3
+ end
@@ -0,0 +1,8 @@
1
+ module Dragon
2
+ module Exceptions
3
+
4
+ # Dragon::Exceptions::DragfileMissing
5
+ class DragfileMissing < Exception; end
6
+
7
+ end
8
+ end
@@ -0,0 +1,56 @@
1
+ require "yaml"
2
+ require "liquid"
3
+
4
+ module Dragon
5
+ class Options
6
+
7
+ attr_accessor :environment, :release, :local_settings
8
+
9
+ def initialize( root_given )
10
+ @root = root_given
11
+ @release = Time.now.utc.strftime("%Y%m%d%H%M%S")
12
+ @local_settings = nil
13
+ end
14
+
15
+ def self.parse( root, args )
16
+ depfile_loc = File.expand_path(File.join( root, "Depfile" ))
17
+ raise Dragon::Exceptions::DragfileMissing, "Depfile must exists in current directory, please run `depify .`." unless File.exists?( depfile_loc )
18
+ output = self.new( root )
19
+ output.environment = args[0]
20
+ output.release = args[1] if args.size > 1
21
+ output.local_settings = YAML.load_file( depfile_loc )[output.environment]
22
+ output.update_commands
23
+ output
24
+ end
25
+
26
+ def release= str
27
+ @release = "#{ Time.now.utc.strftime("%Y%m%d%H%M%S") }_#{ str }"
28
+ end
29
+
30
+ def release_dir
31
+ File.join( @local_settings['destination_root'], "releases", @release )
32
+ end
33
+
34
+ def shared_dir
35
+ File.join( @local_settings['destination_root'], "shared" )
36
+ end
37
+
38
+ def update_commands
39
+ return nil unless !@local_settings.nil? && @local_settings.has_key?( "commands" )
40
+ @local_settings['commands'].each{|k,v|
41
+ rendered_value = Liquid::Template.parse( v ).render( command_liquid_args )
42
+ @local_settings['commands'][k] = rendered_value
43
+ }
44
+ end
45
+
46
+ private
47
+
48
+ def command_liquid_args
49
+ {
50
+ "release_dir" => release_dir,
51
+ "shared_dir" => shared_dir
52
+ }.merge( @local_settings )
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,26 @@
1
+ require "rye"
2
+
3
+ module Dragon
4
+ class ServerSet
5
+
6
+ attr_reader :set
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ @set = server_set
11
+ end
12
+
13
+ def server_set
14
+ set = Rye::Set.new
15
+ @options.local_settings['servers'].each{ |s|
16
+ set.add_boxes server( s )
17
+ }
18
+ set
19
+ end
20
+
21
+ def server str
22
+ Rye::Box.new( str, { keys: [ @options.local_settings['servers_key_location'] ], user: @options.local_settings['servers_username'] } )
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ require 'dragon/version'
2
+
3
+ class << Dragon
4
+
5
+ def usage
6
+ <<USAGE
7
+
8
+ Dragon version #{Dragon::VERSION}
9
+
10
+ -h print this usage doc
11
+ -v print version
12
+
13
+ Deploy:
14
+
15
+ dragon [environment]
16
+ dragon [environment] [release]
17
+
18
+ USAGE
19
+ end
20
+
21
+ def dragify_usage
22
+ <<USAGE
23
+
24
+ Dragify version #{Dragon::VERSION}
25
+
26
+ -h print this usage doc
27
+ -v print version
28
+
29
+ Deploy:
30
+
31
+ dragify [location_to_dragify]
32
+
33
+ Example
34
+
35
+ dragify .
36
+
37
+ USAGE
38
+ end
39
+
40
+ end
@@ -0,0 +1,3 @@
1
+ module Dragon
2
+ VERSION="0.1.0"
3
+ end
data/lib/dragon.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "pry"
2
+
3
+ $:.unshift File.expand_path('../../lib', __FILE__)
4
+
5
+ require "dragon/version"
6
+ require "dragon/dragon"
7
+ require "dragon/exceptions"
8
+ require "dragon/command_runner"
9
+ require "dragon/server_set"
10
+ require "dragon/options"
11
+ require "dragon/deploy"
12
+
@@ -0,0 +1,33 @@
1
+ default: &default
2
+ # main settings [REQUIRED]
3
+ # Note, "local_upload_dir" overrides the use of GIT to deploy
4
+ # local_upload_dir: "<%= @root %>/files"
5
+ git_url: "git@github.com:USERNAME/repo.git"
6
+ destination_root: "/app/root/path/on/remote/server"
7
+ destination_symlink: "/app/root/path/on/remote/server/current" # web server points to this
8
+ servers:
9
+ - "server1.example.com"
10
+ - "server2.example.com"
11
+ servers_username: "username"
12
+ servers_key_location: "~/.ssh/example.pem"
13
+ # sample commands [OPTIONAL]
14
+ # uncomment this setting if you do not want the default commands to run
15
+ # commands_run_default: no
16
+ commands:
17
+ cd: "{{release_dir}}/ && pwd"
18
+ rm: "-rf {{release_dir}}/log"
19
+ ls: "-nfs {{destination_root}}/shared/log {{release_dir}}"
20
+
21
+ staging:
22
+ <<: *default
23
+ git_branch: "staging"
24
+
25
+ production:
26
+ <<: *default
27
+ git_branch: "production"
28
+ servers:
29
+ - "prodserver1.example.com"
30
+ - "prodserver2.example.com"
31
+ - "prodserver3.example.com"
32
+ - "prodserver4.example.com"
33
+ - "prodserver5.example.com"
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dragon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ian Sheridan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rye
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: liquid
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Dragon a deployment tools inspired by Rye.
111
+ email:
112
+ - ian.sheridan@gmail.com
113
+ executables:
114
+ - dragify
115
+ - dragon
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - Dragfile
121
+ - Gemfile
122
+ - README.md
123
+ - bin/dragify
124
+ - bin/dragon
125
+ - dragon.gemspec
126
+ - lib/dragon.rb
127
+ - lib/dragon/command_runner.rb
128
+ - lib/dragon/deploy.rb
129
+ - lib/dragon/dragon.rb
130
+ - lib/dragon/exceptions.rb
131
+ - lib/dragon/options.rb
132
+ - lib/dragon/server_set.rb
133
+ - lib/dragon/usage.rb
134
+ - lib/dragon/version.rb
135
+ - resources/templates/dragfile.yaml.erb
136
+ homepage: https://github.com/iansheridan/dragon
137
+ licenses:
138
+ - MIT
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.23
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Deployment tool.
161
+ test_files: []