deprec-core 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,7 +1,16 @@
1
1
  deprec-core changelog
2
2
  =====================
3
3
 
4
+ = 3.1.6 (Jul 22, 2011)
5
+
6
+ * Added TEMPLATE_LOAD_PATH
7
+
8
+ deprec-core will search this path for the template it's asked
9
+ to render.
10
+
11
+ * Did some reorganization of files.
12
+
4
13
  = 3.1.5 (Jul 17, 2011)
5
14
 
6
- * Extracted the guts of deprec into this gem
15
+ * Extracted the guts of deprec into this gem
7
16
 
@@ -8,6 +8,46 @@
8
8
  # stubs are so they'll be included in the output of "cap -T"
9
9
  #
10
10
  Capistrano::Configuration.instance(:must_exist).load do
11
+
12
+ # deprec defines some generic recipes for common services
13
+ # including ruby interpreter, web, app and database servers
14
+ #
15
+ # They default to my current favourites which you can over ride
16
+ #
17
+ # Service options
18
+ CHOICES_RUBY_VM = [:mri, :ree]
19
+ CHOICES_WEBSERVER = [:apache, :none] # :nginx not recipes out of date
20
+ CHOICES_APPSERVER = [:passenger, :none] # any colour you like guys
21
+ CHOICES_DATABASE = [:mysql, :postgresql, :sqlite, :none]
22
+ #
23
+ # Service defaults
24
+ _cset :ruby_vm_type, :mri
25
+ _cset :web_server_type, :apache
26
+ _cset :app_server_type, :passenger
27
+ _cset :db_server_type, :mysql
28
+
29
+ # Connect deprec:db to deprec:mysql, deprec:web to deprec:apache, etc
30
+ on :load, 'deprec:connect_canonical_tasks'
31
+
32
+ namespace :deprec do
33
+ task :connect_canonical_tasks do
34
+ # link application specific recipes into canonical task names
35
+ # e.g. deprec:web:restart => deprec:nginx:restart
36
+
37
+
38
+ namespaces_to_connect = { :web => :web_server_type,
39
+ :app => :app_server_type,
40
+ :db => :db_server_type,
41
+ :ruby => :ruby_vm_type
42
+ }
43
+ namespaces_to_connect.each do |server, choice|
44
+ server_type = send(choice).to_sym
45
+ if server_type != :none && deprec.respond_to?(server_type)
46
+ namespaces[server] = deprec.send(server_type)
47
+ end
48
+ end
49
+ end
50
+ end
11
51
 
12
52
  %w(ruby).each do |package|
13
53
  namespace "deprec:#{package}" do
@@ -3,6 +3,11 @@ require 'capistrano'
3
3
  require 'fileutils'
4
4
 
5
5
  module Deprec2
6
+
7
+ # Run rake task on remote server(s)
8
+ def rake_remote(task_name)
9
+ run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} #{task_name}"
10
+ end
6
11
 
7
12
  # Temporarily modify ROLES if HOSTS not set
8
13
  # Capistrano's default behaviour is for HOSTS to override ROLES
@@ -12,10 +17,6 @@ module Deprec2
12
17
  yield
13
18
  ENV['ROLES'] = old_roles.to_s unless ENV['HOSTS']
14
19
  end
15
-
16
- def rake_remote(task_name)
17
- run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} #{task_name}"
18
- end
19
20
 
20
21
  # Temporarily ignore ROLES and HOSTS
21
22
  def ignoring_roles_and_hosts
@@ -28,7 +29,6 @@ module Deprec2
28
29
  ENV['HOSTS'] = old_hosts
29
30
  end
30
31
 
31
- DEPREC_TEMPLATES_BASE = File.join(File.dirname(__FILE__), 'templates')
32
32
 
33
33
  # Render template (usually a config file)
34
34
  #
@@ -61,15 +61,16 @@ module Deprec2
61
61
  # If you don't specify the location with the local_template_dir option
62
62
  # it defaults to config/templates.
63
63
  # e.g. config/templates/nginx/nginx.conf.erb
64
- local_template = File.join(local_template_dir, app.to_s, template)
65
- if File.exists?(local_template)
66
- puts
67
- puts "Using local template (#{local_template})"
68
- template = ERB.new(IO.read(local_template), nil, '-')
69
- else
70
- template = ERB.new(IO.read(File.join(DEPREC_TEMPLATES_BASE, app.to_s, template)), nil, '-')
64
+ template_path = ''
65
+ TEMPLATE_LOAD_PATH.each do |dir|
66
+ template_path = File.join(dir, app.to_s, template)
67
+ if File.exists?(template_path)
68
+ template = ERB.new(IO.read(template_path), nil, '-')
69
+ break
70
+ end
71
71
  end
72
72
  rendered_template = template.result(binding)
73
+ puts "Using #{template_path}"
73
74
 
74
75
  if remote
75
76
  # render to remote machine
@@ -209,35 +210,29 @@ module Deprec2
209
210
  switches += " --shell=#{options[:shell]} " if options[:shell]
210
211
  switches += ' --create-home ' unless options[:homedir] == false
211
212
  switches += " --gid #{options[:group]} " unless options[:group].nil?
212
- invoke_command "grep '^#{user}:' /etc/passwd || #{sudo} /usr/sbin/useradd #{switches} #{user}",
213
- :via => run_method
213
+ run "grep '^#{user}:' /etc/passwd || #{sudo} /usr/sbin/useradd #{switches} #{user}"
214
214
  end
215
215
 
216
216
  # create a new group on target system
217
217
  def groupadd(group, options={})
218
- via = options.delete(:via) || run_method
219
218
  # XXX I don't like specifying the path to groupadd - need to sort out paths before long
220
- invoke_command "grep '#{group}:' /etc/group || #{sudo} /usr/sbin/groupadd #{group}", :via => via
219
+ run "grep '#{group}:' /etc/group || #{sudo} /usr/sbin/groupadd #{group}"
221
220
  end
222
221
 
223
222
  # add group to the list of groups this user belongs to
224
223
  def add_user_to_group(user, group)
225
- invoke_command "groups #{user} | grep ' #{group} ' || #{sudo} /usr/sbin/usermod -G #{group} -a #{user}",
226
- :via => run_method
224
+ run "groups #{user} | grep ' #{group} ' || #{sudo} /usr/sbin/usermod -G #{group} -a #{user}"
227
225
  end
228
226
 
229
227
  # create directory if it doesn't already exist
230
228
  # set permissions and ownership
231
229
  # XXX move mode, path and
232
230
  def mkdir(path, options={})
233
- via = options.delete(:via) || :run
234
- # XXX need to make sudo commands wrap the whole command (sh -c ?)
235
- # XXX removed the extra 'sudo' from after the '||' - need something else
236
- invoke_command "test -d #{path} || #{sudo if via == :sudo} mkdir -p #{path}"
237
- invoke_command "chmod #{sprintf("%3o",options[:mode]||0755)} #{path}", :via => via if options[:mode]
238
- invoke_command "chown -R #{options[:owner]} #{path}", :via => via if options[:owner]
239
- groupadd(options[:group], :via => via) if options[:group]
240
- invoke_command "chgrp -R #{options[:group]} #{path}", :via => via if options[:group]
231
+ run "test -d #{path} || #{sudo} mkdir -p #{path}"
232
+ run "chmod #{sprintf("%3o",options[:mode]||0755)} #{path}" if options[:mode]
233
+ run "chown -R #{options[:owner]} #{path}" if options[:owner]
234
+ groupadd(options[:group]) if options[:group]
235
+ run "chgrp -R #{options[:group]} #{path}" if options[:group]
241
236
  end
242
237
 
243
238
  def create_src_dir
@@ -270,7 +265,6 @@ module Deprec2
270
265
  when :http
271
266
  # ensure wget is installed
272
267
  apt.install( {:base => %w(wget)}, :stable )
273
- # XXX replace with invoke_command
274
268
  run "cd #{src_dir} && test -f #{src_pkg[:filename]} #{md5_clause} || #{sudo} wget --quiet --timestamping #{src_pkg[:url]}"
275
269
 
276
270
  when :deb
@@ -375,7 +369,7 @@ module Deprec2
375
369
  end
376
370
 
377
371
  def invoke_with_input(shell_command, input_query=/^Password/, response=nil)
378
- handle_command_with_input(run_method, shell_command, input_query, response)
372
+ handle_command_with_input(:sudo, shell_command, input_query, response)
379
373
  end
380
374
 
381
375
  ##
@@ -0,0 +1,60 @@
1
+ # Copyright 2006-2011 by Mike Bailey. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+
4
+ # Bundler's Capistrano tasks update this
5
+ # Call rake within tasks using #{rake}
6
+ _cset :rake, 'rake'
7
+
8
+ # Deprec checks here for local versions of config templates before it's own
9
+ _cset :local_template_dir, File.join('config','templates')
10
+
11
+ # Prompt user for missing values if not supplied
12
+ _cset(:application) do
13
+ Capistrano::CLI.ui.ask "Enter name of project(no spaces)" do |q|
14
+ q.validate = /^[0-9a-z_]*$/
15
+ end
16
+ end
17
+
18
+ _cset(:domain) do
19
+ Capistrano::CLI.ui.ask "Enter domain name for project" do |q|
20
+ q.validate = /^[0-9a-z_\.]*$/
21
+ end
22
+ end
23
+
24
+ _cset(:repository) do
25
+ Capistrano::CLI.ui.ask "Enter repository URL for project" do |q|
26
+ # q.validate = //
27
+ end
28
+ end
29
+
30
+ _cset :backup_dir, '/var/backups'
31
+
32
+ # XXX We *probably* want these set
33
+ # Must be set for the password prompt from git to work
34
+ # default_run_options[:pty] = true
35
+ # ssh_options[:forward_agent] = true
36
+
37
+ # SCM
38
+ _cset :scm, "git"
39
+ _cset :user, "deploy"
40
+ _cset :deploy_via, :remote_cache
41
+ _cset :branch, "master"
42
+
43
+ # XXX rails deploy stuff
44
+ _cset :apps_root, '/srv' # parent dir for apps
45
+ _cset(:deploy_to) { File.join(apps_root, application) } # dir for current app
46
+ _cset(:current_path) { File.join(deploy_to, "current") }
47
+ _cset(:shared_path) { File.join(deploy_to, "shared") }
48
+
49
+ # XXX more rails deploy stuff?
50
+
51
+ _cset :group, 'deploy' # deployment group
52
+ _cset(:group_src) { group } # group ownership for src dir
53
+ _cset :src_dir, '/usr/local/src' # 3rd party src on servers lives here
54
+ _cset(:web_server_aliases) { domain.match(/^www/) ? [] : ["www.#{domain}"] }
55
+
56
+ # It can be useful to know the user running this command
57
+ # even when USER is set to someone else. Sorry windows!
58
+ _cset :current_user, `whoami`.chomp
59
+
60
+ end
@@ -1,9 +1,6 @@
1
1
  # Copyright 2006-2011 by Mike Bailey. All rights reserved.
2
2
  Capistrano::Configuration.instance(:must_exist).load do
3
3
 
4
- # Connect deprec:db to deprec:mysql, deprec:web to deprec:apache, etc
5
- on :load, 'deprec:connect_canonical_tasks'
6
-
7
4
  # Set the value if not already set
8
5
  # This method is accessible to all recipe files
9
6
  # Defined and used by capistrano/deploy tasks
@@ -16,11 +13,6 @@ Capistrano::Configuration.instance(:must_exist).load do
16
13
  # deprecated
17
14
  alias :default :_cset
18
15
 
19
- _cset :rake, 'rake'
20
-
21
- # Deprec checks here for local versions of config templates before it's own
22
- _cset :local_template_dir, File.join('config','templates')
23
-
24
16
  # The following two Constants contain details of the configuration
25
17
  # files used by each service. They're used when generating config
26
18
  # files from templates and when configs files are pushed out to servers.
@@ -34,159 +26,4 @@ Capistrano::Configuration.instance(:must_exist).load do
34
26
  # to configure, build and install the service
35
27
  SRC_PACKAGES = {} unless defined?(SRC_PACKAGES)
36
28
 
37
- # deprec defines some generic recipes for common services
38
- # including ruby interpreter, web, app and database servers
39
- #
40
- # They default to my current favourites which you can over ride
41
- #
42
- # Service options
43
- CHOICES_RUBY_VM = [:mri, :ree]
44
- CHOICES_WEBSERVER = [:apache, :none] # :nginx not recipes out of date
45
- CHOICES_APPSERVER = [:passenger, :none] # any colour you like guys
46
- CHOICES_DATABASE = [:mysql, :postgresql, :sqlite, :none]
47
- #
48
- # Service defaults
49
- _cset :ruby_vm_type, :mri
50
- _cset :web_server_type, :apache
51
- _cset :app_server_type, :passenger
52
- _cset :db_server_type, :mysql
53
-
54
- # Prompt user for missing values if not supplied
55
- _cset(:application) do
56
- Capistrano::CLI.ui.ask "Enter name of project(no spaces)" do |q|
57
- q.validate = /^[0-9a-z_]*$/
58
- end
59
- end
60
-
61
- _cset(:domain) do
62
- Capistrano::CLI.ui.ask "Enter domain name for project" do |q|
63
- q.validate = /^[0-9a-z_\.]*$/
64
- end
65
- end
66
-
67
- _cset(:repository) do
68
- Capistrano::CLI.ui.ask "Enter repository URL for project" do |q|
69
- # q.validate = //
70
- end
71
- end
72
-
73
- _cset :backup_dir, '/var/backups'
74
-
75
- # XXX We *probably* want these set
76
- # Must be set for the password prompt from git to work
77
- # default_run_options[:pty] = true
78
- # ssh_options[:forward_agent] = true
79
-
80
- # SCM
81
- _cset :scm, "git"
82
- _cset :user, "deploy"
83
- _cset :deploy_via, :remote_cache
84
- _cset :branch, "master"
85
-
86
- # XXX rails deploy stuff
87
- _cset :apps_root, '/srv' # parent dir for apps
88
- _cset(:deploy_to) { File.join(apps_root, application) } # dir for current app
89
- _cset(:current_path) { File.join(deploy_to, "current") }
90
- _cset(:shared_path) { File.join(deploy_to, "shared") }
91
-
92
- # XXX more rails deploy stuff?
93
-
94
- _cset :group, 'deploy' # deployment group
95
- _cset(:group_src) { group } # group ownership for src dir
96
- _cset :src_dir, '/usr/local/src' # 3rd party src on servers lives here
97
- _cset(:web_server_aliases) { domain.match(/^www/) ? [] : ["www.#{domain}"] }
98
-
99
- # It can be useful to know the user running this command
100
- # even when USER is set to someone else. Sorry windows!
101
- _cset :current_user, `whoami`.chomp
102
-
103
- namespace :deprec do
104
-
105
- task :connect_canonical_tasks do
106
- # link application specific recipes into canonical task names
107
- # e.g. deprec:web:restart => deprec:nginx:restart
108
-
109
-
110
- namespaces_to_connect = { :web => :web_server_type,
111
- :app => :app_server_type,
112
- :db => :db_server_type,
113
- :ruby => :ruby_vm_type
114
- }
115
- namespaces_to_connect.each do |server, choice|
116
- server_type = send(choice).to_sym
117
- if server_type != :none
118
- namespaces[server] = deprec.send(server_type)
119
- end
120
- end
121
- end
122
-
123
- task :dump do
124
- require 'yaml'
125
- y variables
126
- end
127
-
128
- task :setup_src_dir do
129
- deprec2.groupadd(group_src)
130
- deprec2.add_user_to_group(user, group_src)
131
- deprec2.create_src_dir
132
- end
133
-
134
- # Download all packages used by deprec to your local host.
135
- # You can then push them to /usr/local/src on target hosts
136
- # to save time and bandwidth rather than repeatedly downloading
137
- # from the distribution sites.
138
- task :update_src do
139
- SRC_PACKAGES.each{|key, src_package|
140
- current_dir = Dir.pwd
141
- system "cd src/ && test -f #{src_package[:filename]} || wget --quiet --timestamping #{src_package[:url]}"
142
- system "cd #{current_dir}"
143
- }
144
- end
145
-
146
- # todo
147
- #
148
- # Copy files from src/ to /usr/local/src/ on remote hosts
149
- task :push_src do
150
- SRC_PACKAGES.each do |key, src_package|
151
- deprec2.set_package_defaults(src_package)
152
- file = File.join('src', src_package[:filename])
153
- if File.exists?(file)
154
- std.su_put(File.read(file), "#{src_dir}/#{src_package[:filename]}", '/tmp/')
155
- end
156
- end
157
- end
158
-
159
- task :list_src do
160
- # XXX ugly line - look away
161
- max_key_size = SRC_PACKAGES.keys.max{|a,b| a.to_s.size <=> b.to_s.size}.to_s.size
162
- SRC_PACKAGES.each{|key, src_package|
163
- deprec2.set_package_defaults(src_package)
164
- puts "#{key}#{' '*(max_key_size+1-key.to_s.size)}: #{src_package[:url]}"
165
- }
166
- end
167
-
168
- task :find_src do
169
- # XXX ugly line - look away
170
- max_key_size = SRC_PACKAGES.keys.max{|a,b| a.to_s.size <=> b.to_s.size}.to_s.size
171
- SRC_PACKAGES.each{|key, src_package|
172
- deprec2.set_package_defaults(src_package)
173
- puts "#{key}#{' '*(max_key_size+1-key.to_s.size)}: #{src_package[:url]}"
174
- puts `find . -name #{src_package[:filename]}`
175
- puts
176
- }
177
- end
178
-
179
- task :recover_src do
180
- # XXX ugly line - look away
181
- max_key_size = SRC_PACKAGES.keys.max{|a,b| a.to_s.size <=> b.to_s.size}.to_s.size
182
- SRC_PACKAGES.each{|key, src_package|
183
- puts "#{key}#{' '*(max_key_size+1-key.to_s.size)}: #{src_package[:url]}"
184
- file = `find . -name #{src_package[:filename]}`.split[0]
185
- `cp #{file} src/` if file
186
- puts
187
- }
188
- end
189
-
190
- end
191
-
192
29
  end
@@ -1,5 +1,5 @@
1
1
  module Deprec
2
2
  module Core
3
- VERSION = "3.1.5"
3
+ VERSION = "3.1.6"
4
4
  end
5
5
  end
data/lib/deprec-core.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require "deprec-core/version"
2
2
 
3
3
  if defined?(Capistrano)
4
- require "deprec-core/capistrano_extensions"
5
4
  require "vmbuilder_plugins/all"
6
- require "deprec-core/canonical"
7
5
  require "deprec-core/deprec"
6
+ require "deprec-core/defaults"
7
+ require "deprec-core/capistrano_extensions"
8
+ require "deprec-core/canonical"
8
9
  elsif defined?(rake)
9
10
  # pass
10
11
  end
metadata CHANGED
@@ -1,28 +1,25 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: deprec-core
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.1.6
4
5
  prerelease:
5
- version: 3.1.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Mike Bailey
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-16 00:00:00 Z
12
+ date: 2011-07-22 00:00:00.000000000 +10:00
13
+ default_executable:
14
14
  dependencies: []
15
-
16
- description: deprec-core was extracted from the popular deprec gem to make it easier for people to publish Capistrano and Rake task gems
17
- email:
15
+ description: deprec-core was extracted from the popular deprec gem to make it easier
16
+ for people to publish Capistrano and Rake task gems
17
+ email:
18
18
  - mike@bailey.net.au
19
19
  executables: []
20
-
21
20
  extensions: []
22
-
23
21
  extra_rdoc_files: []
24
-
25
- files:
22
+ files:
26
23
  - .gitignore
27
24
  - CHANGELOG
28
25
  - Gemfile
@@ -32,6 +29,7 @@ files:
32
29
  - lib/deprec-core.rb
33
30
  - lib/deprec-core/canonical.rb
34
31
  - lib/deprec-core/capistrano_extensions.rb
32
+ - lib/deprec-core/defaults.rb
35
33
  - lib/deprec-core/deprec.rb
36
34
  - lib/deprec-core/version.rb
37
35
  - lib/vmbuilder_plugins/all.rb
@@ -39,32 +37,29 @@ files:
39
37
  - lib/vmbuilder_plugins/emerge.rb
40
38
  - lib/vmbuilder_plugins/gem.rb
41
39
  - lib/vmbuilder_plugins/std.rb
42
- homepage: ""
40
+ has_rdoc: true
41
+ homepage: ''
43
42
  licenses: []
44
-
45
43
  post_install_message:
46
44
  rdoc_options: []
47
-
48
- require_paths:
45
+ require_paths:
49
46
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
47
+ required_ruby_version: !ruby/object:Gem::Requirement
51
48
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
56
- required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
54
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: "0"
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
62
59
  requirements: []
63
-
64
60
  rubyforge_project: deprec-core
65
- rubygems_version: 1.8.5
61
+ rubygems_version: 1.6.2
66
62
  signing_key:
67
63
  specification_version: 3
68
64
  summary: deprec-core provides extensions to Capistrano
69
65
  test_files: []
70
-