deprec 0.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. data/bin/deprec +35 -0
  2. data/bin/deprec_dotfiles +6 -0
  3. data/docs/building_edge_capistrano.txt +9 -0
  4. data/lib/deprec/generators/deprec/USAGE +11 -0
  5. data/lib/deprec/generators/deprec/deprec_generator.rb +24 -0
  6. data/lib/deprec/generators/deprec/templates/deploy.rb +71 -0
  7. data/lib/deprec/generators/loader.rb +20 -0
  8. data/lib/deprec/recipes.rb +227 -0
  9. data/lib/deprec/recipes/slicehost.rb +18 -0
  10. data/lib/deprec/recipes/ssh.rb +13 -0
  11. data/lib/deprec/recipes/svn.rb +18 -0
  12. data/lib/deprec/recipes/templates/test_template.rhtml +1 -0
  13. data/lib/deprec/recipes/ubuntu.rb +38 -0
  14. data/lib/deprec/third_party/THIRD_PARTY_README +12 -0
  15. data/lib/deprec/third_party/mongrel_cluster/LICENSE +506 -0
  16. data/lib/deprec/third_party/mongrel_cluster/recipes.rb +95 -0
  17. data/lib/deprec/third_party/mongrel_cluster/resources/mongrel_cluster +41 -0
  18. data/lib/deprec/third_party/railsmachine/LICENSE +506 -0
  19. data/lib/deprec/third_party/railsmachine/recipes/apache.rb +84 -0
  20. data/lib/deprec/third_party/railsmachine/recipes/mysql.rb +58 -0
  21. data/lib/deprec/third_party/railsmachine/recipes/svn.rb +42 -0
  22. data/lib/deprec/third_party/railsmachine/recipes/templates/httpd-ssl.conf +74 -0
  23. data/lib/deprec/third_party/railsmachine/recipes/templates/httpd.conf +63 -0
  24. data/lib/deprec/third_party/vmbuilder/LICENSE +506 -0
  25. data/lib/deprec/third_party/vmbuilder/plugins.rb +8 -0
  26. data/lib/deprec/third_party/vmbuilder/plugins/apt.rb +144 -0
  27. data/lib/deprec/third_party/vmbuilder/plugins/gem.rb +97 -0
  28. data/lib/deprec/third_party/vmbuilder/plugins/std.rb +153 -0
  29. data/resources/capistrano_include_dotfiles.patch +17 -0
  30. metadata +58 -6
  31. data/lib/deprec.rb +0 -9
data/bin/deprec ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ # no rubygems to load, so we fail silently
7
+ end
8
+
9
+ require 'optparse'
10
+
11
+ @options = {}
12
+ OptionParser.new do |opts|
13
+ opts.banner = "Usage: #{$0} [options] [args]"
14
+
15
+ opts.on("-A", "--apply-to DIRECTORY",
16
+ "Create a minimal set of scripts and recipes",
17
+ "for use with capistrano to configure servers."
18
+ ) { |value| @options[:apply_to] = value }
19
+ opts.on("-n", "--name APPLICATION_NAME",
20
+ "Name of application."
21
+ ) { |value| @options[:application] = value }
22
+ opts.on("-d", "--domain DOMAIN_NAME",
23
+ "Domain name for application."
24
+ ) { |value| @options[:domain] = value }
25
+
26
+ if ARGV.empty?
27
+ puts opts
28
+ exit
29
+ else
30
+ opts.parse!(ARGV)
31
+ end
32
+ end
33
+
34
+ require 'deprec/generators/loader'
35
+ Deprec::Generators::RailsLoader.load! @options
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ patch_target=File.dirname(`gemwhich capistrano`) + '/capistrano/cli.rb'
3
+ patch_file = File.join(File.dirname(__FILE__), '..', 'resources','capistrano_include_dotfiles.patch')
4
+ system "sudo patch -p0 #{patch_target} < #{patch_file}"
5
+ req_statement = "require 'deprec/recipes'"
6
+ system "grep '#{req_statement}' ~/.caprc > /dev/null 2>&1 || echo \"#{req_statement}\" >> ~/.caprc"
@@ -0,0 +1,9 @@
1
+ You can build an edge gem by cd'ing to that directory and doing:
2
+
3
+ 1. svn info. Find the line that says "Revision:" and mark the revision number.
4
+
5
+ 2. rake PKG_BUILD=<rev> gem. Replace <rev> with the revision number.
6
+
7
+ 3. Look in the pkg subdirectory. Install that gem file via "gem install pkg/<gem file>"
8
+
9
+ - Jamis
@@ -0,0 +1,11 @@
1
+ NAME
2
+ deprec - creates configuration and Capistrano tasks for server configuration.
3
+
4
+ SYNOPSIS
5
+ deprec --apply-to /path/to/app --name application_name --domain domain_name
6
+
7
+ DESCRIPTION
8
+ This generator creates deployment recipes.
9
+
10
+ EXAMPLE
11
+ deprec --apply-to . --name bailey --domain www.bailey.net.au
@@ -0,0 +1,24 @@
1
+ class DeprecGenerator < Rails::Generator::NamedBase
2
+ attr_reader :application_name
3
+ attr_reader :domain_name
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ @application_name = self.file_name
8
+ @domain_name = @args[0]
9
+ end
10
+
11
+ def manifest
12
+ record do |m|
13
+ m.directory "config"
14
+ m.template "deploy.rb", File.join("config", "deploy.rb")
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ # Override with your own usage banner.
21
+ def banner
22
+ "Usage: #{$0} --apply-to /path/to/app --name ApplicationName --domain DomainName"
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ require 'deprec/recipes'
2
+
3
+ # =============================================================================
4
+ # ROLES
5
+ # =============================================================================
6
+ # You can define any number of roles, each of which contains any number of
7
+ # machines. Roles might include such things as :web, or :app, or :db, defining
8
+ # what the purpose of each machine is. You can also specify options that can
9
+ # be used to single out a specific subset of boxes in a particular role, like
10
+ # :primary => true.
11
+
12
+ set :domain, "<%= domain_name %>"
13
+ role :web, domain
14
+ role :app, domain
15
+ role :db, domain, :primary => true
16
+
17
+ # =============================================================================
18
+ # REQUIRED VARIABLES
19
+ # =============================================================================
20
+ # You must always specify the application and repository for every recipe. The
21
+ # repository must be the URL of the repository you want this recipe to
22
+ # correspond to. The deploy_to path must be the path on each machine that will
23
+ # form the root of the application path.
24
+
25
+ set :application, "<%= singular_name %>"
26
+ set :deploy_to, "/var/www/apps/#{application}"
27
+
28
+ set :user, ENV['USER']
29
+ set :repository, "svn+ssh://#{user}@#{domain}#{deploy_to}/repos/trunk"
30
+ set :rails_env, "production"
31
+
32
+ # Automatically symlink these directories from current/public to shared/public.
33
+ # set :app_symlinks, %w{photo, document, asset}
34
+
35
+ # =============================================================================
36
+ # APACHE OPTIONS
37
+ # =============================================================================
38
+ set :apache_server_name, domain
39
+ # set :apache_server_aliases, %w{alias1 alias2}
40
+ # set :apache_default_vhost, true # force use of apache_default_vhost_config
41
+ # set :apache_default_vhost_conf, "/etc/httpd/conf/default.conf"
42
+ # set :apache_conf, "/etc/httpd/conf/apps/#{application}.conf"
43
+ # set :apache_ctl, "/etc/init.d/httpd"
44
+ # set :apache_proxy_port, 8000
45
+ # set :apache_proxy_servers, 2
46
+ # set :apache_proxy_address, "127.0.0.1"
47
+ # set :apache_ssl_enabled, false
48
+ # set :apache_ssl_ip, "127.0.0.1"
49
+ # set :apache_ssl_forward_all, false
50
+
51
+ # =============================================================================
52
+ # MONGREL OPTIONS
53
+ # =============================================================================
54
+ # set :mongrel_servers, apache_proxy_servers
55
+ # set :mongrel_port, apache_proxy_port
56
+ set :mongrel_address, apache_proxy_address
57
+ # set :mongrel_environment, "production"
58
+ # set :mongrel_config, "/etc/mongrel_cluster/#{application}.conf"
59
+ # set :mongrel_user, user
60
+ # set :mongrel_group, group
61
+
62
+ # =============================================================================
63
+ # MYSQL OPTIONS
64
+ # =============================================================================
65
+
66
+
67
+ # =============================================================================
68
+ # SSH OPTIONS
69
+ # =============================================================================
70
+ # ssh_options[:keys] = %w(/path/to/my/key /path/to/another/key)
71
+ # ssh_options[:port] = 25
@@ -0,0 +1,20 @@
1
+ module Deprec
2
+ module Generators
3
+ class RailsLoader
4
+ def self.load!(options)
5
+ require "#{options[:apply_to]}/config/environment"
6
+ require "rails_generator"
7
+ require "rails_generator/scripts/generate"
8
+
9
+ Rails::Generator::Base.sources << Rails::Generator::PathSource.new(
10
+ :deprec, File.dirname(__FILE__))
11
+
12
+ args = ["deprec"]
13
+ args << (options[:application] || "Application")
14
+ args << (options[:domain] || "www.mynewsite.com")
15
+
16
+ Rails::Generator::Scripts::Generate.new.run(args)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,227 @@
1
+ require 'deprec/recipes/ssh'
2
+ require 'deprec/recipes/svn'
3
+ require 'deprec/recipes/ubuntu'
4
+ require 'deprec/third_party/mongrel_cluster/recipes'
5
+ require 'deprec/third_party/vmbuilder/plugins'
6
+ require 'deprec/third_party/railsmachine/recipes/svn'
7
+ require 'deprec/third_party/railsmachine/recipes/apache'
8
+ require 'deprec/third_party/railsmachine/recipes/mysql'
9
+
10
+ Capistrano.configuration(:must_exist).load do
11
+ set :user, (defined?(user) ? user : ENV['USER']) # user who is deploying
12
+ set :group, 'deploy' # deployment group
13
+ set :src_dir, (defined?(src_dir) ? src_dir : '/usr/local/src') # 3rd party src on servers
14
+ set :app_symlinks, nil
15
+
16
+ desc <<-DESC
17
+ setup_rails_host takes a stock standard ubuntu 'dapper' 6.06.1 server
18
+ and installs everything needed to be a rails machine
19
+ DESC
20
+ task :install_rails_stack do
21
+ setup_user_perms
22
+ enable_universe # we'll need some packages from the 'universe' repository
23
+ disable_cdrom_install # we don't want to have to insert cdrom
24
+ install_packages_for_rails # install packages that come with distribution
25
+ install_rubygems
26
+ install_gems
27
+ install_apache
28
+ end
29
+
30
+ desc "Set up the expected application directory structure on all boxes"
31
+ task :setup, :except => { :no_release => true } do
32
+ setup_paths
33
+ run <<-CMD
34
+ mkdir -p -m 775 #{releases_path} #{shared_path}/system &&
35
+ mkdir -p -m 777 #{shared_path}/log &&
36
+ mkdir -p -m 777 #{shared_path}/pids
37
+ CMD
38
+ setup_servers
39
+ end
40
+
41
+ desc "setup and configure servers"
42
+ task :setup_servers do
43
+ setup_web
44
+ setup_paths
45
+ setup_app
46
+ setup_symlinks
47
+ setup_db
48
+ end
49
+
50
+ desc "Setup web server."
51
+ task :setup_web, :roles => :web do
52
+ set :apache_server_name, domain unless apache_server_name
53
+ setup_apache
54
+ configure_apache
55
+ end
56
+
57
+ desc "Setup application server."
58
+ task :setup_app, :roles => :app do
59
+ set :mongrel_environment, rails_env
60
+ set :mongrel_port, apache_proxy_port
61
+ set :mongrel_servers, apache_proxy_servers
62
+ install_mongrel_start_script
63
+ setup_mongrel_cluster_path
64
+ configure_mongrel_cluster
65
+ end
66
+
67
+ desc "Restart application server."
68
+ task :restart_app, :roles => :app do
69
+ restart_mongrel_cluster
70
+ end
71
+
72
+ desc "Start application server."
73
+ task :start_app, :roles => :app do
74
+ start_mongrel_cluster
75
+ end
76
+
77
+ desc "Start the processes on the application server by calling start_app."
78
+ task :spinner, :roles => :app do
79
+ start_app
80
+ end
81
+
82
+ desc "Setup public symlink directories"
83
+ task :setup_symlinks, :roles => [:app, :web] do
84
+ if app_symlinks
85
+ app_symlinks.each { |link| run "mkdir -p #{shared_path}/public/#{link}" }
86
+ end
87
+ end
88
+
89
+ desc "Setup database server."
90
+ task :setup_db, :roles => :db, :only => { :primary => true } do
91
+ setup_mysql
92
+ end
93
+
94
+ desc "Setup source control server."
95
+ task :setup_scm, :roles => :scm do
96
+ setup_svn
97
+ import_svn
98
+ end
99
+
100
+ desc "setup extra paths required for deployment"
101
+ task :setup_paths, :roles => :app do
102
+ # XXX make a function to create a group writable dir
103
+ sudo "test -d #{shared_path}/config || sudo mkdir -p #{shared_path}/config"
104
+ sudo "chgrp -R #{group} #{deploy_to}"
105
+ sudo "chmod -R g+w #{deploy_to}"
106
+ end
107
+
108
+ task :create_user do
109
+ newuser=user
110
+ user='root'
111
+ # run "useradd -m #{newuser}"
112
+ run "ls"
113
+ user=newuser
114
+ end
115
+
116
+ task :install_gems do
117
+ gem.install 'rails' # gem lib makes installing gems fun
118
+ gem.select 'mongrel' # mongrel requires we select a version
119
+ gem.install 'mongrel_cluster'
120
+ end
121
+
122
+ desc "create deployment group and add current user to it"
123
+ task :setup_user_perms do
124
+ sudo "grep #{group} /etc/group || sudo groupadd #{group}"
125
+ sudo "groups #{user} | grep #{group} || sudo usermod --groups #{group} -a #{user}"
126
+ end
127
+
128
+ task :install_rubygems do
129
+ # ??? is this an OK way to pass values around to the functions?
130
+ version = 'rubygems-0.9.0'
131
+ set :file_to_get, {
132
+ :file => version + '.tgz',
133
+ :dir => version,
134
+ :url => "http://rubyforge.org/frs/download.php/11289/#{version}.tgz",
135
+ :unpack => "tar zxf #{version}.tgz;",
136
+ :configure => nil,
137
+ :make => nil,
138
+ :install => '/usr/bin/ruby1.8 setup.rb;'
139
+ }
140
+ download_src
141
+ install_from_src
142
+ gem.update_system
143
+ end
144
+
145
+ task :install_apache do
146
+ # ??? is this an OK way to pass values around to the functions?
147
+ version = 'httpd-2.2.3'
148
+ set :file_to_get, {
149
+ :file => version + '.tar.gz',
150
+ :dir => version,
151
+ :url => "http://www.apache.org/dist/httpd/#{version}.tar.gz",
152
+ :unpack => "tar zxf #{version}.tar.gz;",
153
+ :configure => './configure --enable-proxy --enable-proxy-balancer --enable-proxy-http --enable-rewrite --enable-cache --enable-headers --enable-ssl --enable-deflate;',
154
+ :make => 'make;',
155
+ :install => 'make install;',
156
+ :post_install => 'cp support/apachectl /etc/init.d/httpd && chmod 0777 /etc/init.d/httpd;'
157
+ }
158
+ download_src
159
+ install_from_src
160
+ end
161
+
162
+ # XXX move into cap extensions
163
+ desc "install package from source"
164
+ task :install_from_src do
165
+ package_dir = File.join(src_dir, file_to_get[:dir])
166
+ unpack_src
167
+ # XXX we need run_sh and sudo_sh functions to make 'cd' cmd work
168
+ sudo <<-SUDO
169
+ sh -c '
170
+ cd #{package_dir};
171
+ #{file_to_get[:configure]}
172
+ #{file_to_get[:make]}
173
+ #{file_to_get[:install]}
174
+ #{file_to_get[:post_install]}
175
+ '
176
+ SUDO
177
+ end
178
+
179
+ desc "unpack src and make it writable by the group"
180
+ task :unpack_src do
181
+ package_dir = File.join(src_dir, file_to_get[:dir])
182
+ sudo <<-SUDO
183
+ sh -c '
184
+ cd #{src_dir};
185
+ test -d #{package_dir}.old && rm -fr #{package_dir}.old;
186
+ test -d #{package_dir} && mv #{package_dir} #{package_dir}.old;
187
+ #{file_to_get[:unpack]}
188
+ chgrp -R #{group} #{package_dir};
189
+ chmod -R g+w #{package_dir};
190
+ '
191
+ SUDO
192
+ end
193
+
194
+ desc "Setup public symlink directories"
195
+ task :setup_symlinks, :roles => [:app, :web] do
196
+ if app_symlinks
197
+ app_symlinks.each { |link| run "mkdir -p #{shared_path}/public/#{link}" }
198
+ end
199
+ end
200
+
201
+ desc "Link up any public directories."
202
+ task :symlink_public, :roles => [:app, :web] do
203
+ if app_symlinks
204
+ app_symlinks.each { |link| run "ln -nfs #{shared_path}/public/#{link} #{current_path}/public/#{link}" }
205
+ end
206
+ end
207
+
208
+ # something for later...
209
+ # desc "render a template"
210
+ # task :z_template do
211
+ # file = File.join(File.dirname(__FILE__), 'recipes', 'templates', 'test_goo.rhtml')
212
+ # msg = render :template => File.read(file), :foo => 'good', :bar => 'night'
213
+ # run "echo #{msg}"
214
+ # end
215
+
216
+ "will be moved to capistrano extension"
217
+ task :download_src do
218
+ # move this into cap extension
219
+ # XXX should make this group writable
220
+ # XXX so we don't need to sudo to compile
221
+ sudo "test -d #{src_dir} || sudo mkdir #{src_dir}"
222
+ sudo "chgrp -R #{group} #{src_dir}"
223
+ sudo "chmod -R g+w #{src_dir}"
224
+ sudo "sh -c 'cd #{src_dir} && test -f #{file_to_get[:file]} || wget #{file_to_get[:url]}'"
225
+ end
226
+
227
+ end
@@ -0,0 +1,18 @@
1
+
2
+ Capistrano.configuration(:must_exist).load do
3
+
4
+ task :install_rails_stack_slicehost do
5
+ # create user account
6
+
7
+ end
8
+
9
+ end
10
+ #
11
+ # # set editor to vim
12
+ #
13
+ # # create user account
14
+ # mkdir -m mbailey
15
+ # # set password for user
16
+ # passwd mbailey
17
+ # # setup sudo
18
+ # echo "mbailey ALL=(ALL) ALL" >> /etc/sudoers
@@ -0,0 +1,13 @@
1
+ Capistrano.configuration(:must_exist).load do
2
+
3
+ # set :user, (defined?(user) ? user : ENV['USER'])
4
+ desc "Copies contents of ssh public keys into authorized_keys file"
5
+ task :setup_ssh_keys do
6
+ sudo "test -d ~/.ssh || mkdir ~/.ssh"
7
+ sudo "chmod 0700 ~/.ssh"
8
+ put(ssh_options[:keys].collect{|key| File.read(key+'.pub')}.join("\n"),
9
+ File.join('/home', user, '.ssh/authorized_keys'),
10
+ :mode => 0600 )
11
+ end
12
+
13
+ end