tdd_deploy 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,3 +7,6 @@ gem 'autotest-fsevent'
7
7
 
8
8
  gem 'capistrano'
9
9
  gem 'net-ping'
10
+
11
+ # gem 'rack', "~> 1.2.1"
12
+ gem 'rack'
@@ -51,7 +51,7 @@ class TddDeployEnv
51
51
  end
52
52
 
53
53
  def save
54
- if self.modified?
54
+ if self.modified? || !File.exists?(TddDeploy::Environ::ENV_FNAME)
55
55
  self.flash = 'Updates Saved'
56
56
  self.save_env
57
57
  end
@@ -60,13 +60,13 @@ class TddDeployEnv
60
60
 
61
61
  def parse_cmd(cmd)
62
62
  puts cmd
63
- unless cmd =~ /^\s*(\w+)(\s+.*?)\s*$/i
63
+ unless cmd =~ /^\s*(\w+)(\s+.*?)?\s*$/i
64
64
  self.flash = "unable to parse command: '#{cmd}'" unless cmd.strip.empty?
65
65
  return
66
66
  end
67
67
 
68
68
  key_prefix = $1
69
- param_value = $2.strip
69
+ param_value = $2.nil? ? '' : $2.strip
70
70
 
71
71
  key_regx = Regexp.new('^' + key_prefix, Regexp::IGNORECASE)
72
72
  matching_keys = self.env_types.keys.select { |k| key_regx.match(k) }
@@ -74,6 +74,7 @@ module TddDeploy
74
74
 
75
75
  #single host methods
76
76
 
77
+ # options are passed to Net::SFTP process. :permissions default to 0755
77
78
  def mkdir_on_remote_as userid, host, dir, options = {}
78
79
  result = nil
79
80
  options[:permissions] = 0755 unless options.include? :permissions
@@ -96,7 +97,7 @@ module TddDeploy
96
97
  sftp.close! handle
97
98
  end
98
99
  end
99
- result
100
+ ! result.nil?
100
101
  end
101
102
 
102
103
  def copy_string_to_remote_file_as userid, host, str, dst
@@ -106,21 +107,35 @@ module TddDeploy
106
107
  f.write str
107
108
  end
108
109
  end
109
- result
110
+ ! result.nil?
110
111
  end
111
112
 
112
113
  def append_file_to_remote_file_as(userid, host, src, dst)
113
114
  raise ::ArgumentError.new("file name cannot be empty") if src.empty?
114
115
  raise ::RuntimeError.new("unable to copy #{src} to #{userid}@#{host}: #{src} not found") unless File.exists? src
116
+
117
+ f = File.new(src)
118
+ file_mode = f.stat.mode & 0777
115
119
 
116
- append_string_to_remote_file_as userid, host, File.new(src).read, dst
120
+ if (result = append_string_to_remote_file_as(userid, host, f.read, dst))
121
+ stdout, stderr, cmd = run_on_a_host_as(userid, host, "chmod 0#{sprintf('%o', file_mode)} #{dst}")
122
+ result &= stderr.nil?
123
+ end
124
+ result
117
125
  end
118
126
 
119
127
  def copy_file_to_remote_as(userid, host, src, dst)
120
128
  raise ::ArgumentError.new("file name cannot be empty") if src.empty?
121
129
  raise ::RuntimeError.new("unable to copy #{src} to #{userid}@#{host}: #{src} not found") unless File.exists? src
122
130
 
123
- copy_string_to_remote_file_as userid, host, File.new(src).read, dst
131
+ f = File.new(src)
132
+ file_mode = f.stat.mode & 0777
133
+
134
+ if (result = copy_string_to_remote_file_as(userid, host, f.read, dst))
135
+ stdout, stderr, cmd = run_on_a_host_as(userid, host, "chmod 0#{sprintf('%o', file_mode)} #{dst}")
136
+ result &= stderr.nil?
137
+ end
138
+ result
124
139
  end
125
140
  end
126
141
  end
@@ -22,7 +22,7 @@ module TddDeploy
22
22
  def deploy_test_process_running_on_hosts_as(userid, host_list, pid_file_path, success_msg = nil)
23
23
  host_list = rationalize_host_list(host_list)
24
24
  success_msg ||= "Process associated with #{pid_file_path} should be running"
25
- ret = deploy_test_file_exists_on_hosts_as(userid, host_list, pid_file_path, success_msg + " no such pid file: #{pid_file_path}") ||
25
+ ret = deploy_test_file_exists_on_hosts_as(userid, host_list, pid_file_path, success_msg + " based on pid file: #{pid_file_path}") ||
26
26
  ret &= deploy_test_on_hosts_as(userid, host_list, /.+\n\s*\d+.*?\d\d:\d\d:\d\d/, "Process for #{pid_file_path} is running") do
27
27
  "ps -p `cat #{pid_file_path} | awk '{ print $1 ; exit }'`"
28
28
  end
@@ -31,6 +31,7 @@ module TddDeploy
31
31
  # * 'local_admin' - user name of on local hosts which can ssh into remote hosts via public key authentication
32
32
  # * 'local_admin_email' - email of local admin who should receive monitoring emails
33
33
  # * 'site' - name of site This should satisfy /[a-z][a-z0-9_]*.
34
+ # * 'site_app_root' - the absolute path to DocumentRoot for the site
34
35
  # * 'site_doc_root' - the absolute path to DocumentRoot for the site
35
36
  # * 'site_special_dir' - absolute path to site special directory - for system configuration fragments, commands, etc
36
37
  # * 'site_url' - the url for the site (w/o scheme - as in 'www.foo.com')
@@ -48,7 +49,7 @@ module TddDeploy
48
49
  # * 'capfile_paths' - relative paths to capistrano recipe files. Defaults to './config/deploy.rb'
49
50
  #
50
51
  # === Pseudo Variables
51
- # * 'hosts' - list of all hosts - always returns balance_hosts + db_hosts + web_hosts.
52
+ # * 'hosts' - list of all hosts - always returns app_hosts + balance_hosts + db_hosts + web_hosts.
52
53
  #may be assigned to if all three host lists are identical, otherwise raises an exception.
53
54
  #'tdd_deploy_context' hides it from view unless it can be assigned
54
55
  # * 'app' - list of all hosts in the :app role of the Capistrano recipes
@@ -113,6 +114,7 @@ module TddDeploy
113
114
  'site' => :string,
114
115
  'site_url' => :string,
115
116
  'site_aliases' => :string,
117
+ 'site_app_root' => :string,
116
118
  'site_doc_root' => :string,
117
119
  'site_special_dir' => :string,
118
120
  'site_user' => :string,
@@ -142,7 +144,8 @@ module TddDeploy
142
144
  'site' => 'name of site - will be the name of the deployment directory - as in /home/user/site/',
143
145
  'site_url' => 'the site url - www.foo.com',
144
146
  'site_aliases' => 'all the site aliases we need to put in nginx/apache configuration fragments',
145
- 'site_doc_root' => 'this is DocumentRoot for the site. probably /home/site_user/site/current',
147
+ 'site_app_root' => 'this is the root of the current app. probably /home/site_user/site/current',
148
+ 'site_doc_root' => 'this is DocumentRoot for the site. probably /home/site_user/site/current/public',
146
149
  'site_special_dir' => 'directory for monitrc, nginx config fragments, monit commands, etc',
147
150
  'site_user' => 'userid that the app lives in. This need not be host_admin. It\' separate so multiple sites can live on the same host',
148
151
 
@@ -171,7 +174,8 @@ module TddDeploy
171
174
  'site' => "site",
172
175
  'site_url' => 'www.site.com', # don't include the scheme
173
176
  'site_aliases' => '',
174
- 'site_doc_root' => '/home/site_user/site/current', # default for Capistrano
177
+ 'site_app_root' => '/home/site_user/site/current',
178
+ 'site_doc_root' => '/home/site_user/site/current/public', # default for Capistrano
175
179
  'site_special_dir' => '/home/site_user/site_special',
176
180
  'site_user' => "site_user",
177
181
 
@@ -179,7 +183,7 @@ module TddDeploy
179
183
 
180
184
  # 'hosts' => "bar,foo",
181
185
  'app_hosts' => 'arch',
182
- 'balance_hosts' => 'arch',
186
+ 'balance_hosts' => '',
183
187
  'db_hosts' => 'arch',
184
188
  'web_hosts' => 'arch',
185
189
  }
@@ -211,12 +215,12 @@ module TddDeploy
211
215
  when :pseudo then
212
216
  if k == 'hosts'
213
217
  if (tmp = DataCache.env_hash['web_hosts']) == DataCache.env_hash['db_hosts'] \
214
- && tmp == DataCache.env_hash['balance_hosts'] \
218
+ && [] == DataCache.env_hash['balance_hosts'] \
215
219
  && tmp == DataCache.env_hash['app_hosts']
216
220
  DataCache.env_hash['web_hosts'] =
217
221
  DataCache.env_hash['db_hosts'] =
218
- DataCache.env_hash['balance_hosts'] =
219
- DataCache.env_hash['app_hosts'] = self.str_to_list(v)
222
+ DataCache.env_hash['app_hosts'] = self.str_to_list(v)
223
+ DataCache.env_hash['balance_hosts'] = []
220
224
  else
221
225
  raise ::RuntimeError.new("#{self}#reset_env(): Cannot assign value to 'hosts' if web_hosts &/or db_hosts already set.\n web_hosts: #{DataCache.env_hash['web_hosts']}\n db_hosts: #{DataCache.env_hash['db_hosts']}")
222
226
  # raise RuntimeError.new("Cannot change hosts key if web_hosts != db_hosts")
@@ -382,8 +386,8 @@ module TddDeploy
382
386
  if (self.web_hosts.nil? && self.db_hosts.nil?) || self.web_hosts == self.db_hosts
383
387
  self.web_hosts =
384
388
  self.db_hosts =
385
- self.balance_hosts =
386
- self.app_hosts = self.str_to_list(list)
389
+ self.app_hosts = self.str_to_list(list)
390
+ self.balance_hosts = []
387
391
  else
388
392
  raise ::RuntimeError.new("Cannot assign value to 'hosts' if web_hosts &/or db_hosts already set.\n web_hosts: #{self.web_hosts}\n db_hosts: #{self.db_hosts}")
389
393
  end
@@ -9,14 +9,19 @@ module TddDeploy
9
9
  class RemoteIpTables < TddDeploy::TestBase
10
10
  # tcp_some_blocked_ports - checks TCP ports
11
11
  def tcp_some_blocked_ports
12
+ @port_to_check ||= [20, 23, 25, 53, 5432, 2812]
12
13
  self.hosts.each do |host|
14
+ result = true
13
15
  # Linode seems to refuse to block 21 - FTP control
14
16
  # [20, 21, 23, 25, 53, 5432, 2812].each do |port|
15
17
  if self.ping_host(host)
16
- [20, 23, 25, 53, 5432, 2812].each do |port|
18
+ @port_to_check.each do |port|
17
19
  tcp_socket = TCPSocket.new(host, port) rescue 'failed'
18
- assert_equal host, 'failed', tcp_socket, "Host: #{host}: Should not be able to connect via tcp to port #{port}"
20
+ unless tcp_socket == 'failed'
21
+ result &= fail host, "Host: #{host}: iptables test: Should not be able to connect via tcp to port #{port}"
22
+ end
19
23
  end
24
+ pass host, "tcp ports #{@port_to_check.join(',')} blocked"
20
25
  else
21
26
  fail host, "Host: #{host}: iptables cannot be tested - host does not respond to ping"
22
27
  end
@@ -31,7 +31,7 @@ module TddDeploy
31
31
 
32
32
  def run_cap_deploy
33
33
  stdout, stderr, cmd = run_locally { 'cap deploy:update' }
34
- return fail if stderr =~ /failed|rolling back/
34
+ return false if stderr =~ /failed|rolling back/
35
35
  return true
36
36
  end
37
37
  end
@@ -109,10 +109,10 @@ end
109
109
  <td><a href="/?install_special">Site Specials</a></td>
110
110
  <td><a href="/?install_configs">Site Config</a></td>
111
111
  </tr>
112
- <tr class="<%= even_odd %>">
112
+ <!-- <tr class="<%= even_odd %>">
113
113
  <th>Capistrano</th>
114
114
  <td><a href="/?run_cap_deploy">run cap deploy:update</a></td>
115
- </tr>
115
+ </tr> -->
116
116
  </table>
117
117
  </div> <!-- test summary -->
118
118
 
@@ -1,10 +1,8 @@
1
1
  ---
2
- chdir: <%= site_doc_root %>
2
+ chdir: <%= site_app_root %>
3
3
  environment: production
4
4
  address: 127.0.0.1
5
5
  timeout: 30
6
- log: log/thin.log
7
- pid: <%= site_doc_root %>/tmp/pids/thin.pid
8
6
  max_conns: 1024
9
7
  max_persistent_conns: 512
10
8
  require: []
@@ -1,10 +1,10 @@
1
- chdir: <%= site_doc_root %>
1
+ chdir: <%= site_app_root %>
2
2
  environment: production
3
3
  address: 127.0.0.1
4
4
  port: <%= site_base_port %>
5
5
  timeout: 30
6
6
  log: log/thin.log
7
- pid: <%= site_doc_root %>/tmp/pids/thin.pid
7
+ pid: <%= site_app_root %>/tmp/pids/thin.pid
8
8
  max_conns: 1024
9
9
  max_persistent_conns: 512
10
10
  require: []
@@ -1,11 +1,11 @@
1
1
  <% ((site_base_port)...(site_base_port+site_num_servers)).each do |port| %>
2
- check process <%= site %>_server_<%= port %> with pidfile <%= "#{site_doc_root}/tmp/pids/thin.#{port}.pid" %>
3
- start process = "<%= "#{site_doc_root}/site/thin_one_server start #{port}" %>" with timeout 60 seconds
4
- stop process = "<%= "#{site_doc_root}/site/thin_one_server stop #{port}" %>"
2
+ check process <%= site %>_server_<%= port %> with pidfile <%= "#{site_app_root}/tmp/pids/thin.#{port}.pid" %>
3
+ start program = "/bin/su -c '<%= "#{site_special_dir}/one_thin_server start #{port}" %>' -l <%= site_user %>" with timeout 60 seconds
4
+ stop program = "/bin/su -c '<%= "#{site_special_dir}/one_thin_server stop #{port}" %>' -l <%= site_user %>"
5
5
  if failed host localhost port <%= port %> protocol http
6
6
  and request "/"
7
7
  then restart
8
8
  if 3 restarts within 5 cycles then timeout
9
9
  group server
10
10
 
11
- <% end %>
11
+ <% end %>
@@ -1,6 +1,30 @@
1
1
  #! /bin/sh
2
+ # must have perms 0755
2
3
 
3
- PORT=$1
4
+ USEAGE="Usage: `basename $0` <stop | start> <port>"
4
5
 
5
- cd <%= site_doc_root %>
6
- bundle exec thin --config ./config/thin_one_server.config --port $PORT start
6
+ source "$HOME/.rvm/scripts/rvm"
7
+
8
+ case $# in
9
+ 2) CMD=$1 ; PORT=$2 ;;
10
+ *) echo $USEAGE ; exit 1;;
11
+ esac
12
+
13
+ cd <%= site_app_root %>
14
+ case $CMD in
15
+ start)
16
+ bundle exec thin \
17
+ --config <%= site_app_root %>/config/one_thin_server.conf \
18
+ --environment production \
19
+ --log <%= site_app_root %>/log/thin.${PORT}.log \
20
+ --pid <%= site_app_root %>/tmp/pids/thin.${PORT}.pid \
21
+ --port $PORT \
22
+ start
23
+ ;;
24
+ stop)
25
+ test -s ./tmp/pids/thin.${PORT}.pid && /bin/kill `cat ./tmp/pids/thin.${PORT}.pid`
26
+ ;;
27
+ *)
28
+ echo $USAGE ; exit 1
29
+ ;;
30
+ esac
@@ -1,11 +1 @@
1
- <% ((site_base_port)...(site_base_port+site_num_servers)).each do |port| %>
2
- check process <%= site %>_server_<%= port %> with pidfile <%= "#{site_doc_root}/tmp/pids/thin.#{port}.pid" %>
3
- start process = "<%= "#{site_doc_root}/site/thin_one_server start #{port}" %>" with timeout 60 seconds
4
- stop process = "<%= "#{site_doc_root}/site/thin_one_server stop #{port}" %>"
5
- if failed host localhost port <%= port %> protocol http
6
- and request "/"
7
- then restart
8
- if 3 restarts within 5 cycles then timeout
9
- group server
10
-
11
- <% end %>
1
+ # Empty monitrc fragment
@@ -1,29 +1,27 @@
1
- host {
2
-
3
- }
1
+ #
2
+ # balance_host config fragment for <%= site %>
3
+ #
4
4
  upstream <%= site %> {
5
- <% ((site_base_port)...(site_base_port+site_num_servers)).each do |port| %>
6
- server 127.0.0.1:<%= port %>;
5
+ <% web_hosts.each do |host| %>
6
+ server <%= host %>;
7
7
  <% end %>
8
8
  }
9
9
  server {
10
10
  listen 80;
11
- server_name <%= site_url %>;
12
- root <%= site_doc_root %>/current;
11
+ server_name <%= site_url %> <%= site_aliases %>;
13
12
  location / {
13
+ # proxy configuration - customarily offloaded to an include file
14
14
  proxy_set_header X-Real-IP $remote_addr;
15
15
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16
16
  proxy_set_header Host $http_host;
17
17
  proxy_redirect false;
18
- try_files $uri $uri/index.html $uri.html @thin;
19
- location / {
20
- include proxy.conf;
21
- proxy_pass http://<%= site %>;
22
- }
23
- }
18
+ client_max_body_size 10m;
19
+ client_body_buffer_size 128k;
20
+ proxy_connect_timeout 90;
21
+ proxy_send_timeout 90;
22
+ proxy_read_timeout 90;
23
+ proxy_buffers 32 4k;
24
24
 
25
- error_page 500 502 503 504 /500.html;
26
- location = /500.html {
27
- root html;
25
+ proxy_pass http://<%= site %>;
28
26
  }
29
27
  }
@@ -1,11 +1 @@
1
- <% ((site_base_port)...(site_base_port+site_num_servers)).each do |port| %>
2
- check process <%= site %>_server_<%= port %> with pidfile <%= "#{site_doc_root}/tmp/pids/thin.#{port}.pid" %>
3
- start process = "<%= "#{site_doc_root}/site/thin_one_server start #{port}" %>" with timeout 60 seconds
4
- stop process = "<%= "#{site_doc_root}/site/thin_one_server stop #{port}" %>"
5
- if failed host localhost port <%= port %> protocol http
6
- and request "/"
7
- then restart
8
- if 3 restarts within 5 cycles then timeout
9
- group server
10
-
11
- <% end %>
1
+ # Empty monitrc config fragment
@@ -1,29 +1,44 @@
1
- host {
2
-
3
- }
1
+ #
2
+ # web_host config fragment for <%= site %>
3
+ #
4
4
  upstream <%= site %> {
5
+ # backend servers
5
6
  <% ((site_base_port)...(site_base_port+site_num_servers)).each do |port| %>
6
7
  server 127.0.0.1:<%= port %>;
7
8
  <% end %>
8
9
  }
9
10
  server {
10
11
  listen 80;
11
- server_name <%= site_url %>;
12
- root <%= site_doc_root %>/current;
12
+ server_name <%= site_url %> <%= site_aliases %>;
13
+
14
+ root <%= site_doc_root %>;
15
+
16
+ access_log <%= site_app_root %>/log/<%= site %>.access.log;
17
+ error_log <%= site_app_root %>/log/<%= site %>.error.log debug;
18
+ # access_log /etc/nginx/logs/<%= site %>.access.log;
19
+ # error_log /etc/nginx/logs/<%= site %>.error.log debug;
20
+
13
21
  location / {
14
- proxy_set_header X-Real-IP $remote_addr;
15
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16
- proxy_set_header Host $http_host;
17
- proxy_redirect false;
18
- try_files $uri $uri/index.html $uri.html @thin;
19
- location / {
20
- include proxy.conf;
21
- proxy_pass http://<%= site %>;
22
- }
22
+ # proxy configuration - customarily offloaded to an include file
23
+ proxy_redirect off;
24
+ proxy_set_header Host $host;
25
+ proxy_set_header X-Real-IP $remote_addr;
26
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27
+
28
+ try_files $uri $uri/index.html $uri.html @thin-<%= site %>;
23
29
  }
24
30
 
25
- error_page 500 502 503 504 /500.html;
26
- location = /500.html {
27
- root html;
31
+ location @thin-<%= site %> {
32
+ # proxy configuration - customarily offloaded to an include file
33
+ client_max_body_size 10m;
34
+ client_body_buffer_size 128k;
35
+ proxy_connect_timeout 90;
36
+ proxy_send_timeout 90;
37
+ proxy_read_timeout 90;
38
+ proxy_buffers 32 4k;
39
+
40
+ proxy_pass http://<%= site %>;
28
41
  }
42
+
43
+ error_page 500 502 503 504 /500.html;
29
44
  }
@@ -8,6 +8,7 @@ module TddDeploy
8
8
  #
9
9
  # The sub directories tested for are:
10
10
  #
11
+ # * 'site_app_root' - application root (current installed version)
11
12
  # * 'site_doc_root' - DocumentRoot
12
13
  # * 'site_doc_root'/../releases - a standard directory used by Capistrano
13
14
  # * 'site_doc_root'/config/thin.conf - config file for 'thin' server
@@ -16,12 +17,16 @@ module TddDeploy
16
17
  # * ~/site/monitrc - a monit configuration fragment which tells monit how to monitor the site's *thin* servers.
17
18
  # * ~/site/one_thin_server - shell script to start a single server instance
18
19
  class SiteLayout < TddDeploy::TestBase
19
- def test_site_subdir
20
+ def test_site_app_root
21
+ deploy_test_file_exists_on_hosts_as self.site_user, self.app_hosts, "#{self.site_app_root}"
22
+ end
23
+
24
+ def test_site_doc_root
20
25
  deploy_test_file_exists_on_hosts_as self.site_user, self.app_hosts, "#{self.site_doc_root}"
21
26
  end
22
27
 
23
28
  def test_releases_subdir
24
- deploy_test_file_exists_on_hosts_as self.site_user, self.app_hosts, "#{self.site_doc_root}/../../../releases"
29
+ deploy_test_file_exists_on_hosts_as self.site_user, self.app_hosts, "#{self.site_app_root}/../../releases"
25
30
  end
26
31
 
27
32
  def test_special_dir
@@ -29,11 +34,11 @@ module TddDeploy
29
34
  end
30
35
 
31
36
  def test_thin_conf
32
- deploy_test_file_exists_on_hosts_as self.site_user, self.app_hosts, "#{site_doc_root}/../config/thin.conf"
37
+ deploy_test_file_exists_on_hosts_as self.site_user, self.app_hosts, "#{site_app_root}/config/thin.conf"
33
38
  end
34
39
 
35
40
  def test_one_thin_server_conf
36
- deploy_test_file_exists_on_hosts_as self.site_user, self.app_hosts, "#{site_doc_root}/../config/one_thin_server.conf"
41
+ deploy_test_file_exists_on_hosts_as self.site_user, self.app_hosts, "#{site_app_root}/config/one_thin_server.conf"
37
42
  end
38
43
 
39
44
  def test_site_dir_exists
@@ -1,3 +1,3 @@
1
1
  module TddDeploy
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
@@ -23,10 +23,12 @@ class RunMethodsTestCase < Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_mkdir_on_remote_as
26
- result = mkdir_on_remote_as 'site_user', 'arch', 'test-dir'
26
+ result = mkdir_on_remote_as 'site_user', 'arch', 'test-dir', :permissions => 0555
27
27
  assert result, "mkdir_on_remote_as site_user on arch returns true"
28
28
  stdout, stderr, cmd = run_on_a_host_as 'site_user', 'arch', 'test -d test-dir && echo "success"'
29
29
  assert_equal "success\n", stdout, "deploy_test_file_exists_on_hosts_as says 'test-dir' exists"
30
+ stdout, stderr, cmd = run_on_a_host_as 'site_user', 'arch', 'ls -ld test-dir'
31
+ assert_match /^dr-xr-xr-x/, stdout, "deploy_test_file_exists_on_hosts_as says 'test-dir' exists"
30
32
 
31
33
  stdout, stderr, cmd = run_on_a_host_as 'site_user', 'arch', 'rmdir test-dir ; test -d test-dir || echo "success"'
32
34
  assert_equal "success\n", stdout, "deploy_test_file_exists_on_hosts_as says 'test-dir' removed"
@@ -64,6 +66,7 @@ class RunMethodsTestCase < Test::Unit::TestCase
64
66
  require 'tempfile'
65
67
  tmp_file = Tempfile.new('foo')
66
68
  begin
69
+ tmp_file_perms = tmp_file.stat.mode
67
70
  input_text = "line one\nline two\nline 3\n"
68
71
  tmp_file.write input_text
69
72
  tmp_file.close
@@ -71,6 +74,8 @@ class RunMethodsTestCase < Test::Unit::TestCase
71
74
 
72
75
  stdout, stderr, cmd = run_on_a_host_as 'site_user', 'arch', 'cat test-file'
73
76
  assert_equal input_text, stdout, "remote file should contain input_text"
77
+ stdout, stderr, cmd = run_on_a_host_as 'site_user', 'arch', 'ls -ld test-file'
78
+ assert_match /^-rw-------/, stdout, "test-file should have correct permissions"
74
79
 
75
80
  assert result, "copy should return true"
76
81
  ensure
@@ -97,6 +102,9 @@ class RunMethodsTestCase < Test::Unit::TestCase
97
102
  assert append_file_to_remote_file_as('site_user', 'arch', tmp2_file.path, 'test-file'), 'append should return true'
98
103
  stdout, stderr, cmd = run_on_a_host_as 'site_user', 'arch', 'cat test-file'
99
104
  assert_equal input_text + input2_text, stdout, "remote file should contain input_text + input2_text"
105
+
106
+ stdout, stderr, cmd = run_on_a_host_as 'site_user', 'arch', 'ls -ld test-file'
107
+ assert_match /^-rw-------/, stdout, "test-file should have correct permissions"
100
108
  ensure
101
109
  tmp_file.unlink
102
110
  tmp2_file.unlink
@@ -61,7 +61,7 @@ class TestEnvironTestCase < Test::Unit::TestCase
61
61
  def test_resonse_to_instance_assessors
62
62
  [:env_hash, :ssh_timeout, :site_base_port, :site_num_servers,
63
63
  :host_admin, :local_admin, :local_admin_email,
64
- :site, :site_user, :site_doc_root, :site_special_dir, :site_url,
64
+ :site, :site_user, :site_app_root, :site_doc_root, :site_special_dir, :site_url,
65
65
  :capfile_paths, :app, :db, :migration_hosts, :web,
66
66
  :hosts, :app_hosts, :balance_hosts, :db_hosts, :web_hosts].each do |meth|
67
67
  assert @foo.respond_to?(meth), "@foo should respond to #{meth}"
@@ -71,13 +71,14 @@ class TestEnvironTestCase < Test::Unit::TestCase
71
71
 
72
72
  def test_env_type
73
73
  ["ssh_timeout", "site_base_port", "site_num_servers", "host_admin", "local_admin", "local_admin_email",
74
- "site", "site_user", "site_doc_root", "site_special_dir", "site_url", 'app_hosts', "balance_hosts", "db_hosts", "web_hosts"].each do |sym|
74
+ "site", "site_user", "site_app_root", "site_doc_root", "site_special_dir", "site_url", 'app_hosts', "balance_hosts", "db_hosts", "web_hosts"].each do |sym|
75
75
  assert @foo.env_types.keys.include?(sym.to_s), "@foo.env_types.keys includes #{sym}"
76
76
  end
77
77
  ["ssh_timeout", "site_base_port", "site_num_servers"].each do |key|
78
78
  assert_equal :int, @foo.env_types[key], "@foo.env_types[#{key}] should be :int"
79
79
  end
80
- ["host_admin", "local_admin", "local_admin_email", "site", "site_user", "site_doc_root", "site_special_dir", "site_special_dir", "site_url"].each do |key|
80
+ ["host_admin", "local_admin", "local_admin_email", "site", "site_user", "site_app_root",
81
+ "site_doc_root", "site_special_dir", "site_special_dir", "site_url"].each do |key|
81
82
  assert_equal :string, @foo.env_types[key], "@foo.env_types[#{key}] should be :string"
82
83
  end
83
84
  ['app_hosts', "balance_hosts", "capfile_paths", "db_hosts", "web_hosts"].each do |key|
@@ -93,21 +94,22 @@ class TestEnvironTestCase < Test::Unit::TestCase
93
94
  assert_equal [], @foo.app_hosts, "assigning '' to app_hosts should create empty list"
94
95
  @foo.set_env :hosts => 'foo,bar'
95
96
  assert_equal ['bar', 'foo'], @foo.hosts, "assigning foo,bar to hosts should create ['bar', 'foo']"
96
- ['app_hosts', 'web_hosts', 'db_hosts', 'balance_hosts'].each do |hst|
97
+ ['app_hosts', 'web_hosts', 'db_hosts'].each do |hst|
97
98
  assert_equal @foo.send(hst.to_sym), @foo.hosts, "hosts should be same as @foo.#{hst}"
98
99
  end
100
+ assert_equal [], @foo.balance_hosts, "balance_hosts should still be empty"
99
101
  end
100
102
 
101
103
  def test_env_hash
102
104
  ["ssh_timeout", "site_base_port", "site_num_servers", "host_admin", "local_admin", "local_admin_email",
103
- "site", "site_user", "site_doc_root", "site_special_dir", "site_url", 'app_hosts', "balance_hosts", "db_hosts", "web_hosts"].each do |key|
105
+ "site", "site_user", "site_app_root", "site_doc_root", "site_special_dir", "site_url", 'app_hosts', "balance_hosts", "db_hosts", "web_hosts"].each do |key|
104
106
  assert_not_nil @foo.env_hash[key], "@foo.env_hash[#{key}] should not be nil"
105
107
  end
106
108
  end
107
109
 
108
110
  def test_env_defaults
109
111
  ["ssh_timeout", "site_base_port", "site_num_servers", "host_admin", "local_admin", "local_admin_email",
110
- "site", "site_user", "site_doc_root", "site_special_dir", "site_url", 'app_hosts', "balance_hosts", "db_hosts", "web_hosts"].each do |key|
112
+ "site", "site_user", "site_app_root", "site_doc_root", "site_special_dir", "site_url", 'app_hosts', "balance_hosts", "db_hosts", "web_hosts"].each do |key|
111
113
  assert_not_nil @foo.env_defaults[key], "@foo.env_defaults[#{key}] should not be nil"
112
114
  end
113
115
  end
@@ -122,7 +124,7 @@ class TestEnvironTestCase < Test::Unit::TestCase
122
124
  @foo.send "#{key}=", tmp
123
125
  assert_equal tmp, @foo.send(key.to_sym), "@foo.#{key} should now be #{tmp}"
124
126
  end
125
- ["host_admin", "local_admin", "local_admin_email", "site", "site_user", "site_doc_root", "site_special_dir", "site_url"].each do |key|
127
+ ["host_admin", "local_admin", "local_admin_email", "site", "site_user", "site_app_root", "site_doc_root", "site_special_dir", "site_url"].each do |key|
126
128
  tmp = "#{key}-changed"
127
129
  @foo.send "#{key}=", tmp
128
130
  assert_equal tmp, @foo.send(key.to_sym), "@foo.#{key} should now be #{tmp}"
@@ -20,12 +20,16 @@ class TestSiteLayoutTestCase < Test::Unit::TestCase
20
20
  @tester = nil
21
21
  end
22
22
 
23
- def test_site_home
24
- assert @tester.test_site_subdir, "Directory #{@tester.site_doc_root} should exist"
23
+ def test_site_app_root
24
+ assert @tester.test_site_app_root, "Directory #{@tester.site_app_root} should exist"
25
+ end
26
+
27
+ def test_site_doc_root
28
+ assert @tester.test_site_doc_root, "Directory #{@tester.site_doc_root} should exist"
25
29
  end
26
30
 
27
31
  def test_site_releases
28
- assert @tester.test_releases_subdir, "Directory #{@tester.site_doc_root}/../../releases should exist"
32
+ assert @tester.test_releases_subdir, "Directory #{@tester.site_app_root}/../releases should exist"
29
33
  end
30
34
 
31
35
  def test_site_configuration_dir_exists
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdd_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &2164802500 !ruby/object:Gem::Requirement
16
+ requirement: &2164627560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2164802500
24
+ version_requirements: *2164627560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: net-ping
27
- requirement: &2164801880 !ruby/object:Gem::Requirement
27
+ requirement: &2164609200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2164801880
35
+ version_requirements: *2164609200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: net-ssh
38
- requirement: &2164801380 !ruby/object:Gem::Requirement
38
+ requirement: &2164599580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2164801380
46
+ version_requirements: *2164599580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack
49
- requirement: &2164800800 !ruby/object:Gem::Requirement
49
+ requirement: &2164595860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2164800800
57
+ version_requirements: *2164595860
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ZenTest
60
- requirement: &2164800220 !ruby/object:Gem::Requirement
60
+ requirement: &2164578920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 4.5.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2164800220
68
+ version_requirements: *2164578920
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: autotest-growl
71
- requirement: &2164799700 !ruby/object:Gem::Requirement
71
+ requirement: &2164558440 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2164799700
79
+ version_requirements: *2164558440
80
80
  description: Test driven support for host provisioning & Capistrano deployment - for
81
81
  those who don't want to bother learning too much
82
82
  email: ! ' mike@clove.com '
@@ -146,11 +146,8 @@ files:
146
146
  - lib/tdd_deploy/site-erb/app_hosts/config/thin.conf.erb
147
147
  - lib/tdd_deploy/site-erb/app_hosts/site/monitrc.erb
148
148
  - lib/tdd_deploy/site-erb/app_hosts/site/one_thin_server.erb
149
- - lib/tdd_deploy/site-erb/balance_hosts/config/one_thin_server.conf.erb
150
- - lib/tdd_deploy/site-erb/balance_hosts/config/thin.conf.erb
151
149
  - lib/tdd_deploy/site-erb/balance_hosts/site/monitrc.erb
152
150
  - lib/tdd_deploy/site-erb/balance_hosts/site/nginx.conf.erb
153
- - lib/tdd_deploy/site-erb/balance_hosts/site/one_thin_server.erb
154
151
  - lib/tdd_deploy/site-erb/web_hosts/site/monitrc.erb
155
152
  - lib/tdd_deploy/site-erb/web_hosts/site/nginx.conf.erb
156
153
  homepage: https://github.com/mikehoward/tdd_deploy
@@ -1,14 +0,0 @@
1
- ---
2
- chdir: <%= site_doc_root %>
3
- environment: production
4
- address: 127.0.0.1
5
- timeout: 30
6
- log: log/thin.log
7
- pid: <%= site_doc_root %>/tmp/pids/thin.pid
8
- max_conns: 1024
9
- max_persistent_conns: 512
10
- require: []
11
-
12
- wait: 30
13
- server: 1
14
- daemonize: true
@@ -1,14 +0,0 @@
1
- chdir: <%= site_doc_root %>
2
- environment: production
3
- address: 127.0.0.1
4
- port: <%= site_base_port %>
5
- timeout: 30
6
- log: log/thin.log
7
- pid: <%= site_doc_root %>/tmp/pids/thin.pid
8
- max_conns: 1024
9
- max_persistent_conns: 512
10
- require: []
11
-
12
- wait: 30
13
- servers: <%= site_num_servers %>
14
- daemonize: true
@@ -1,6 +0,0 @@
1
- #! /bin/sh
2
-
3
- PORT=$1
4
-
5
- cd <%= site_doc_root %>
6
- bundle exec thin --config ./config/thin_one_server.config --port $PORT start