producer-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4ffdb392f9f8bec2527ee9069c9784d39fded5b
4
+ data.tar.gz: ba6bff23838c42212ca604515947028c881e9571
5
+ SHA512:
6
+ metadata.gz: 1c0fb325ea97d9a9bbe6f868956a895fd4e480d597468fbd45e48628e61a1579986249bdf30dfd819d61f309243c3472fe6d9405cc547f781665f9d79e7d9939
7
+ data.tar.gz: 8ecdcff66fd2d4693d6093a8ced55fb3856e2d10c38a1791c6787ec3a6e44dd1fe44506b99346f33fb0b708d9ba96500baeeace180c939d1ffa2013e9e6477f0
data/.gitignore ADDED
File without changes
@@ -0,0 +1,164 @@
1
+ module Producer
2
+ module Rails
3
+ require 'producer/stdlib'
4
+ require 'securerandom'
5
+
6
+ class << self
7
+ def define_macro(name, &block)
8
+ ::Producer::Core::Recipe.define_macro(name, block)
9
+ end
10
+
11
+ def define_test(name, &block)
12
+ ::Producer::Core::Condition.define_test(name, block)
13
+ end
14
+ end
15
+
16
+ define_macro :deploy do
17
+ app_path = get :app_path
18
+ $app_path = app_path
19
+
20
+ if ENV.key? 'DEPLOY_INIT'
21
+ ensure_dir app_path, 0701
22
+ git_clone get(:repository), app_path
23
+ app_init app_path, get(:app_mkdir)
24
+ bundle_install app_path
25
+ db_config app_path
26
+ db_init app_path
27
+ secrets_init app_path
28
+ www_config app_path
29
+ else
30
+ git_update app_path
31
+ bundle_install app_path
32
+ db_migrate app_path
33
+ end
34
+
35
+ assets_update app_path
36
+
37
+
38
+ www_pid_path = get :www_pid_path
39
+ queue_workers = get :queue_workers
40
+
41
+ if ENV.key? 'DEPLOY_INIT'
42
+ www_start app_path, www_pid_path
43
+ app_start app_path, queue_workers
44
+ 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
49
+ end
50
+ end
51
+
52
+ define_test :bundle_installed? do |gemfile|
53
+ no_sh "bundle check #{gemfile}"
54
+ end
55
+
56
+ define_macro :bundle_install do |path|
57
+ gemfile = "--gemfile #{path}/Gemfile"
58
+
59
+ condition { bundle_installed? gemfile }
60
+
61
+ sh "bundle install --without development test #{gemfile}"
62
+ end
63
+
64
+ define_macro :app_init do |path, dirs: []|
65
+ directories = (%w[tmp tmp/run] + dirs).map do |e|
66
+ File.join(path, e)
67
+ end
68
+
69
+ condition { no_dir? directories.first }
70
+
71
+ directories.each { |e| mkdir e, 0700 }
72
+ sh "cd #{path} && chmod 701 tmp tmp/run"
73
+ end
74
+
75
+ define_macro :db_config do |path|
76
+ path = "#{path}/config/database.yml"
77
+ conf = <<-eoh
78
+ default: &default
79
+ adapter: postgresql
80
+ encoding: unicode
81
+ pool: 5
82
+
83
+ production:
84
+ <<: *default
85
+ database: #{target}
86
+ eoh
87
+
88
+ condition { no_file? path }
89
+
90
+ file_write path, conf
91
+ end
92
+
93
+ define_macro :db_init do |path|
94
+ condition { no_sh 'psql -l | grep -E "^ +%s"' % target }
95
+
96
+ sh "cd #{path} && bundle exec rake db:create db:migrate"
97
+ end
98
+
99
+ define_macro :db_migrate do |path|
100
+ condition { sh "cd #{path} && bundle exec rake db:migrate:status | grep -E '^ +down'" }
101
+
102
+ sh "cd #{path} && bundle exec rake db:migrate"
103
+ end
104
+
105
+ define_macro :secrets_init do |path|
106
+ path = "#{path}/config/secrets.yml"
107
+ conf = <<-eoh
108
+ production:
109
+ secret_key_base: #{SecureRandom.hex(64)}
110
+ eoh
111
+
112
+ condition { no_file? path }
113
+
114
+ file_write path, conf
115
+ end
116
+
117
+ define_macro :www_config do |path|
118
+ www_config_path = File.join(path, get(:www_config_path))
119
+ conf = <<-eoh
120
+ worker_processes #{get :www_workers}
121
+ preload_app false
122
+ pid '#{get :www_pid_path}'
123
+ listen "\#{ENV['HOME']}/#{path}/#{get :www_sock_path}"
124
+ eoh
125
+
126
+ condition { no_file_contains www_config_path, conf }
127
+
128
+ file_write www_config_path, conf
129
+ end
130
+
131
+ define_macro :assets_update do |path|
132
+ sh "cd #{path} && bundle exec rake assets:precompile"
133
+ sh "cd #{path} && chmod 711 public public/assets"
134
+ sh "cd #{path} && find public/assets -type d -exec chmod 711 {} \\;"
135
+ sh "cd #{path} && find public/assets -type f -exec chmod 644 {} \\;"
136
+ end
137
+
138
+ define_macro :app_start do |app_path, queue_workers|
139
+ condition { no_sh 'tmux has-session -t app' }
140
+
141
+ sh "cd #{app_path} && tmux new -d -s app 'foreman start -c queue=1,worker=#{queue_workers}; zsh'"
142
+ end
143
+
144
+ define_macro :app_stop do
145
+ sh 'tmux kill-session -t app'
146
+ end
147
+
148
+ define_macro :www_start do |app_path, www_pid_path|
149
+ condition { no_file? [app_path, www_pid_path].join('/') }
150
+
151
+ sh "cd #{app_path} && bundle exec unicorn -c config/unicorn.rb -D"
152
+ end
153
+
154
+ define_macro :www_reload do |app_path, www_pid_path|
155
+ sh "kill -HUP $(cat #{app_path}/#{www_pid_path})"
156
+ end
157
+
158
+ define_macro :www_stop do |app_path, www_pid_path|
159
+ condition { file? [app_path, www_pid_path].join('/') }
160
+
161
+ sh "kill -QUIT $(cat #{app_path}/#{www_pid_path}); sleep 1"
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,5 @@
1
+ module Producer
2
+ module Rails
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../lib/producer/rails/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'producer-rails'
5
+ s.version = Producer::Rails::VERSION.dup
6
+ s.summary = 'producer rails addon'
7
+ s.description = <<-eoh.gsub(/^ +/, '')
8
+ Rails specific macros for producer (gem: producer-core).
9
+ eoh
10
+ s.homepage = 'https://rubygems.org/gems/producer-rails'
11
+
12
+ s.authors = 'Thibault Jouan'
13
+ s.email = 'tj@a13.fr'
14
+
15
+ s.files = `git ls-files`.split $/
16
+
17
+ s.add_dependency 'producer-core', '~> 0.3', '>= 0.3.5'
18
+ s.add_dependency 'producer-stdlib', '~> 0.0', '>= 0.0.5'
19
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: producer-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Thibault Jouan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: producer-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.5
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.5
33
+ - !ruby/object:Gem::Dependency
34
+ name: producer-stdlib
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.0.5
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.0.5
53
+ description: |
54
+ Rails specific macros for producer (gem: producer-core).
55
+ email: tj@a13.fr
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - ".gitignore"
61
+ - lib/producer/rails.rb
62
+ - lib/producer/rails/version.rb
63
+ - producer-rails.gemspec
64
+ homepage: https://rubygems.org/gems/producer-rails
65
+ licenses: []
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: producer rails addon
87
+ test_files: []
88
+ has_rdoc: