producer-rails 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Rails
3
- VERSION = '0.0.5'.freeze
3
+ VERSION = '0.0.6'.freeze
4
4
  end
5
5
  end
@@ -13,62 +13,105 @@ module Producer
13
13
  end
14
14
  end
15
15
 
16
+ UNICORN_CONF_PATH = 'config/unicorn.rb'.freeze
17
+ WWW_PID_PATH = 'tmp/run/www.pid'.freeze
18
+ WWW_SOCK_PATH = 'tmp/run/www.socke'.freeze
19
+ BUNDLER_UNSET_GROUPS = %w[development test].freeze
20
+
16
21
  define_macro :deploy do
17
22
  app_path = get :app_path
18
23
 
19
24
  if ENV.key? 'DEPLOY_INIT'
20
- ensure_dir app_path, 0701
21
- git_clone get(:repository), app_path
22
- app_init app_path, get(:app_mkdir)
23
- bundle_install app_path
24
- db_config app_path
25
- db_init app_path
26
- secrets_init app_path
27
- www_config app_path
25
+ deploy_init app_path
28
26
  else
29
- git_update app_path
30
- bundle_install app_path
31
- db_migrate app_path
32
- db_seed app_path if (get :db_seed rescue false)
27
+ deploy_update app_path
33
28
  end
34
29
 
35
30
  assets_update app_path
36
31
 
32
+ deploy_restart
33
+ end
34
+
35
+ define_macro :deploy_init do |app_path = get(:app_path)|
36
+ app_path ||= get :app_path
37
+
38
+ ensure_dir app_path, mode: 0701
39
+ git_clone get(:repository), app_path
40
+ app_init app_path,
41
+ dirs: (get :app_mkdir, []),
42
+ files: (get :app_mkfile, [])
43
+ db_config app_path
44
+ bundle_install app_path, (get :bundler_unset, [])
45
+ db_init app_path
46
+ secrets_init app_path
47
+ www_config app_path
48
+ end
49
+
50
+ define_macro :deploy_update do |app_path = nil|
51
+ app_path ||= get :app_path
52
+
53
+ git_update app_path
54
+ bundle_install app_path
55
+ db_migrate app_path
56
+ db_seed app_path if set? :db_seed
57
+ www_config app_path
58
+ end
37
59
 
38
- www_pid_path = get :www_pid_path
39
- queue_workers = get :queue_workers
60
+ define_macro :deploy_restart do |app_path = nil|
61
+ app_path ||= get :app_path
40
62
 
41
63
  if ENV.key?('DEPLOY_INIT') || ENV.key?('DEPLOY_START')
42
- www_start app_path, www_pid_path
43
- app_start app_path, queue_workers
64
+ deploy_start
44
65
  else
45
- app_stop
46
- www_stop app_path, www_pid_path
47
- www_start app_path, www_pid_path
48
- app_start app_path, queue_workers
66
+ deploy_stop
67
+ deploy_start
49
68
  end
50
69
  end
51
70
 
71
+ define_macro :deploy_stop do
72
+ app_path ||= get :app_path
73
+ www_pid_path = (get :www_pid_path, WWW_PID_PATH)
74
+ processes = (get :processes, nil)
75
+
76
+ app_stop if processes
77
+ www_stop app_path, www_pid_path
78
+ end
79
+
80
+ define_macro :deploy_start do
81
+ app_path ||= get :app_path
82
+ www_pid_path = (get :www_pid_path, WWW_PID_PATH)
83
+ processes = (get :processes, nil)
84
+
85
+ www_start app_path, www_pid_path
86
+ app_start app_path, processes if processes
87
+ end
88
+
52
89
  define_test :bundle_installed? do |gemfile|
53
90
  no_sh "bundle check #{gemfile}"
54
91
  end
55
92
 
56
- define_macro :bundle_install do |path|
93
+ define_macro :bundle_install do |path, remove_groups = []|
57
94
  gemfile = "--gemfile #{path}/Gemfile"
95
+ without_groups = (remove_groups + BUNDLER_UNSET_GROUPS).join ' '
58
96
 
59
97
  condition { bundle_installed? gemfile }
60
98
 
61
- sh "bundle install --without development test #{gemfile}"
99
+ sh "bundle install --without #{without_groups} #{gemfile}"
62
100
  end
63
101
 
64
- define_macro :app_init do |path, dirs: []|
102
+ define_macro :app_init do |path, dirs: [], files: {}|
65
103
  run_dir = "#{path}/tmp/run"
104
+ dirs << 'public/assets'
66
105
  dirs.map! { |e| File.join(path, e) }
106
+ files = files.each_with_object({}) do |(k, v), m|
107
+ m[File.join(path, k)] = v
108
+ end
67
109
 
68
110
  condition { no_dir? run_dir }
69
111
 
70
- mkdir run_dir, 0701
71
- dirs.each { |e| mkdir e, 0700 }
112
+ mkdir run_dir, mode: 0701
113
+ dirs.each { |e| mkdir e, mode: 0700 }
114
+ files.each { |k, v| file_write k, v, mode: 0600 }
72
115
  end
73
116
 
74
117
  define_macro :db_config do |path|
@@ -118,12 +161,16 @@ production:
118
161
  end
119
162
 
120
163
  define_macro :www_config do |path|
121
- www_config_path = File.join(path, get(:www_config_path))
164
+ www_config_path = File.join(
165
+ path,
166
+ (get :www_config_path, UNICORN_CONF_PATH)
167
+ )
122
168
  conf = <<-eoh
123
169
  worker_processes #{get :www_workers}
170
+ timeout #{get :www_timeout, 60}
124
171
  preload_app false
125
172
  pid '#{get :www_pid_path}'
126
- listen "\#{ENV['HOME']}/#{path}/#{get :www_sock_path}"
173
+ listen "\#{ENV['HOME']}/#{path}/#{(get :www_sock_path, WWW_SOCK_PATH)}"
127
174
  eoh
128
175
 
129
176
  condition { no_file_contains www_config_path, conf }
@@ -138,10 +185,10 @@ listen "\#{ENV['HOME']}/#{path}/#{get :www_sock_path}"
138
185
  sh "cd #{path} && find public/assets -type f -exec chmod 644 {} \\;"
139
186
  end
140
187
 
141
- define_macro :app_start do |app_path, queue_workers|
188
+ define_macro :app_start do |app_path, processes|
142
189
  condition { no_sh 'tmux has-session -t app' }
143
190
 
144
- sh "cd #{app_path} && tmux new -d -s app 'foreman start -c queue=1,worker=#{queue_workers}; zsh'"
191
+ sh "cd #{app_path} && tmux new -d -s app 'foreman start -c #{processes}; zsh'"
145
192
  end
146
193
 
147
194
  define_macro :app_stop do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-01 00:00:00.000000000 Z
12
+ date: 2015-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: producer-core
@@ -86,8 +86,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 1.8.29
89
+ rubygems_version: 1.8.30
90
90
  signing_key:
91
91
  specification_version: 3
92
92
  summary: producer rails addon
93
93
  test_files: []
94
+ has_rdoc: