deploytool 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+ *.swo
16
+
17
+ ## PROJECT::GENERAL
18
+ coverage
19
+ rdoc
20
+ pkg
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jeremy Deininger
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = deploytool
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Jeremy Deininger. See LICENSE for details.
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "deploytool"
8
+ gem.summary = %Q{Deploy code from SVN or GIT repositories capastrano style}
9
+ gem.description = %Q{Command line tool for deploying code from SVN or GIT repositories using a capastrano style directory layout}
10
+ gem.email = "jeremy@rightscale.com"
11
+ gem.homepage = "http://github.com/jeremyd/deploytool"
12
+ gem.authors = ["Jeremy Deininger"]
13
+ gem.add_dependency "trollop", ">= 0"
14
+ gem.add_dependency "chef", ">= 0.9.8"
15
+ gem.add_development_dependency "rspec", ">= 1.2.9"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "deploytool #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ # Development mode path change (from local checkout)
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'rubygems'
6
+ require 'trollop'
7
+ require 'deploytool'
8
+
9
+ opts = Trollop::options do
10
+ text "This command line util can deploy a git or svn repository into a target directory with all the capistrano style bells and whistles for shared files such as logs, pids, database configs and more."
11
+ opt :git, "Use GIT (default). GIT authentication must be setup by the user if working with a private repository"
12
+ opt :svn, "Use SVN. SVN authentication is used if environment variables $OPT_SVN_USERNAME and $OPT_SVN_PASSWORD are set."
13
+ opt :destination, "Destination directory where top level of the capistrano style tree will be located", :type => :string, :required => true
14
+ opt :repository, "Repository URL (svn or git)", :type => :string, :required => true
15
+ opt :revision, "Branch (git), SHA1 (git), Tag (git/svn), or Revision (svn) to use for the clone/checkout", :type => :string, :short => 'v'
16
+ opt :rollback, "Instead of doing a deploy, do a rollback to the previous code"
17
+ opt :force, "Force the re-download of a revision. Force deploy. Warning: causes some downtime!"
18
+ end
19
+
20
+ deploy = Deploytool.new
21
+
22
+ if opts[:svn]
23
+ deploy.use_svn(opts)
24
+ else
25
+ deploy.use_git(opts)
26
+ end
27
+
28
+ deploy.run_solo
@@ -0,0 +1,98 @@
1
+ class Deploytool
2
+
3
+ # Configure Chef-solo
4
+ def initialize
5
+ if `gem list|grep chef`.empty?
6
+ STDERR.puts "WARNING: you don't appear to have chef installed"
7
+ end
8
+ end
9
+
10
+ # Many customization options are available!!!
11
+ # SEE: http://wiki.opscode.com/display/chef/Deploy+Resource
12
+ # Configure the cookbook to use svn with no extra 'shared' files (generic)
13
+ # ~<opts> is the options hash usually populated by trollop's command line opts
14
+ def use_svn(opts)
15
+ # The Deploy resources assumes you have already created the 'shared' directories
16
+ FileUtils.mkdir_p File.join(opts[:destination], 'shared', 'log')
17
+
18
+ # setup the optional action and revision
19
+ rev = ""
20
+ rev = "revision \"#{opts[:revision]}\"" if opts[:revision]
21
+ action = ""
22
+ action = "action :rollback" if opts[:rollback]
23
+ action = "action :force_deploy" if opts[:force]
24
+
25
+ # setup optional auth
26
+ suser = ""
27
+ suser = "svn_username #{ENV['OPT_SVN_USERNAME']}" if ENV['OPT_SVN_USERNAME']
28
+ spass = ""
29
+ spass = "svn_password #{ENV['OPT_SVN_USERNAME']}" if ENV['OPT_SVN_USERNAME']
30
+
31
+ @cookbook =<<EOBOOK
32
+ deploy_revision "#{opts[:destination]}" do
33
+ repo "#{opts[:repository]}"
34
+ #{rev}
35
+ symlinks Hash.new
36
+ symlink_before_migrate Hash.new
37
+ create_dirs_before_symlink Array.new
38
+ purge_before_symlink Array.new
39
+ scm_provider Chef::Provider::Subversion
40
+ #{suser}
41
+ #{spass}
42
+ #{action}
43
+ end
44
+ EOBOOK
45
+ end
46
+
47
+ # Many customization options are available!!!
48
+ # SEE: http://wiki.opscode.com/display/chef/Deploy+Resource
49
+ # Configure the cookbook to use git with no extra 'shared' files (generic)
50
+ # ~<opts> is the options hash usually populated by trollop's command line opts
51
+ def use_git(opts)
52
+ # The Deploy resources assumes you have already created the 'shared' directories
53
+ FileUtils.mkdir_p File.join(opts[:destination], 'shared', 'log')
54
+
55
+ # setup the optional action and revision
56
+ rev = ""
57
+ rev = "revision \"#{opts[:revision]}\"" if opts[:revision]
58
+ action = ""
59
+ action = "action :rollback" if opts[:rollback]
60
+ action = "action :force_deploy" if opts[:force]
61
+
62
+ @cookbook =<<EOBOOK
63
+ deploy_revision "#{opts[:destination]}" do
64
+ repo "#{opts[:repository]}"
65
+ #{rev}
66
+ shallow_clone true
67
+ symlinks Hash.new
68
+ symlink_before_migrate Hash.new
69
+ create_dirs_before_symlink Array.new
70
+ purge_before_symlink Array.new
71
+ #{action}
72
+ end
73
+ EOBOOK
74
+ end
75
+
76
+ # Run chef-solo; do the deploy.
77
+ def run_solo
78
+ gempath = `gem env`.grep(/EXECUTABLE DIRECTORY/).first.split(/:/).last.chomp
79
+ @solo = File.join(gempath, "chef-solo")
80
+ @solo_config_path = File.join(File.expand_path("~"), "chef-solo")
81
+ FileUtils.mkdir_p(@solo_config_path)
82
+ solo_config =<<EOSOLO
83
+ file_cache_path "#{@solo_config_path}"
84
+ cookbook_path "#{@solo_config_path}/cookbooks"
85
+ EOSOLO
86
+ File.open("#{@solo_config_path}/chef-solo.conf", "w") { |f| f.write solo_config }
87
+
88
+ FileUtils.mkdir_p("#{@solo_config_path}/cookbooks/app_code/recipes")
89
+ File.open("#{@solo_config_path}/cookbooks/app_code/recipes/deploy.rb", "w") { |f| f.write @cookbook }
90
+ runlist = '{ "run_list": "app_code::deploy" }'
91
+ File.open("#{@solo_config_path}/deploy_runlist.js", "w") { |f| f.write runlist }
92
+ # Run chef-solo to deploy your code!
93
+ puts "Running chef-solo"
94
+ puts `#{@solo} -c #{@solo_config_path}/chef-solo.conf -j #{@solo_config_path}/deploy_runlist.js`
95
+ exit(1) unless $?.success?
96
+ end
97
+
98
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+
5
+ describe "Deploytool" do
6
+ before(:each) do
7
+ @dir = File.join(Dir.tmpdir, Time.now.strftime("%S%H%d"))
8
+ FileUtils.mkdir_p(@dir)
9
+ end
10
+
11
+ it "runs a git deploy" do
12
+ opts = { :destination => @dir, :repository => "git://github.com/jeremyd/rest_connection.git", :revision => "master" }
13
+ deploy = Deploytool.new
14
+ deploy.use_git(opts)
15
+ deploy.run_solo
16
+ File.exists?(File.join(@dir, "current", "Rakefile")).should == true
17
+ end
18
+
19
+ it "runs an svn deploy" do
20
+ opts = { :destination => @dir, :repository => "http://svn.apache.org/repos/asf/spamassassin/trunk" }
21
+ deploy = Deploytool.new
22
+ deploy.use_svn(opts)
23
+ deploy.run_solo
24
+ File.exists?(File.join(@dir, "current", "README")).should == true
25
+ end
26
+
27
+ after(:each) do
28
+ FileUtils.rm_rf(@dir)
29
+ end
30
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'deploytool'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deploytool
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jeremy Deininger
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-14 00:00:00 -07:00
19
+ default_executable: deploy
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: trollop
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: chef
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 43
44
+ segments:
45
+ - 0
46
+ - 9
47
+ - 8
48
+ version: 0.9.8
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rspec
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 13
60
+ segments:
61
+ - 1
62
+ - 2
63
+ - 9
64
+ version: 1.2.9
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: Command line tool for deploying code from SVN or GIT repositories using a capastrano style directory layout
68
+ email: jeremy@rightscale.com
69
+ executables:
70
+ - deploy
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - LICENSE
75
+ - README.rdoc
76
+ files:
77
+ - .document
78
+ - .gitignore
79
+ - LICENSE
80
+ - README.rdoc
81
+ - Rakefile
82
+ - VERSION
83
+ - bin/deploy
84
+ - lib/deploytool.rb
85
+ - spec/deploytool_spec.rb
86
+ - spec/spec.opts
87
+ - spec/spec_helper.rb
88
+ has_rdoc: true
89
+ homepage: http://github.com/jeremyd/deploytool
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options:
94
+ - --charset=UTF-8
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Deploy code from SVN or GIT repositories capastrano style
122
+ test_files:
123
+ - spec/spec_helper.rb
124
+ - spec/deploytool_spec.rb