orats 0.8.1 → 0.9.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/orats/cli.rb +1 -0
- data/lib/orats/cli_help/new +2 -0
- data/lib/orats/commands/new/rails.rb +14 -1
- data/lib/orats/postgres.rb +1 -1
- data/lib/orats/templates/base.rb +10 -0
- data/lib/orats/templates/includes/new/rails/.env +20 -4
- data/lib/orats/templates/includes/new/rails/Gemfile +1 -0
- data/lib/orats/templates/includes/new/rails/Procfile +1 -1
- data/lib/orats/templates/includes/new/rails/config/puma.rb +20 -10
- data/lib/orats/templates/includes/new/rails/config/sidekiq.yml +1 -1
- data/lib/orats/templates/includes/new/rails/config/unicorn.rb +52 -0
- data/lib/orats/version.rb +1 -1
- data/test/integration/cli_test.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06d673cccc421756a9ce6a7398c8a5953245f7c7
|
4
|
+
data.tar.gz: 9bea9a885137b89ff186287604a54bec948ff159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b6b7592f901be422559dca5b4409e9fd2db5ff579100d5e472d6d522a44cdcfc8e68614a1172ce046f3371385ad414b62a743e014ecdc9ec7691ea32a6bc55e
|
7
|
+
data.tar.gz: 52d2a71d2b084bb80a55e0f97531d3fe6d1738bad452d623452c900d74af8520d43f2f85c27d9a79e1dccee7c00893e46b734e49aa5ef02c21f001a9d1252c3e
|
data/README.md
CHANGED
@@ -104,7 +104,7 @@ All of the changes have git commits to go with them. After generating a project
|
|
104
104
|
- **Core changes**:
|
105
105
|
- Use `postgres` as the primary SQL database
|
106
106
|
- Use `redis` as the cache backend
|
107
|
-
- Use `puma` as the web
|
107
|
+
- Use `puma` or `unicorn` as the web backend
|
108
108
|
- Use `sidekiq` as a background worker
|
109
109
|
- **Features**:
|
110
110
|
- Configure scheduled jobs and tasks using `whenever`
|
data/lib/orats/cli.rb
CHANGED
@@ -50,6 +50,7 @@ module Orats
|
|
50
50
|
option :template, default: '', aliases: '-t'
|
51
51
|
option :custom, default: '', aliases: '-c'
|
52
52
|
option :skip_server_start, type: :boolean, default: false, aliases: '-S'
|
53
|
+
option :backend, default: 'puma', aliases: '-b'
|
53
54
|
option :rc, default: ''
|
54
55
|
desc 'new PATH [options]', 'Create a new orats application'
|
55
56
|
long_desc File.read(File.join(File.dirname(__FILE__), 'cli_help/new'))
|
data/lib/orats/cli_help/new
CHANGED
@@ -41,6 +41,7 @@ module Orats
|
|
41
41
|
gsub_postgres_info
|
42
42
|
gsub_redis_info
|
43
43
|
gsub_readme
|
44
|
+
gsub_unicorn if @options[:backend] == 'unicorn'
|
44
45
|
|
45
46
|
bundle_install
|
46
47
|
bundle_binstubs
|
@@ -99,6 +100,17 @@ module Orats
|
|
99
100
|
commit 'Update the readme'
|
100
101
|
end
|
101
102
|
|
103
|
+
def gsub_unicorn
|
104
|
+
task 'Update files for switching to unicorn'
|
105
|
+
|
106
|
+
gsub_file "#{@target_path}/Procfile", 'puma -C config/puma.rb',
|
107
|
+
'unicorn -c config/unicorn.rb'
|
108
|
+
gsub_file "#{@target_path}/Gemfile", "gem 'puma'", "#gem 'puma'"
|
109
|
+
gsub_file "#{@target_path}/Gemfile", "#gem 'unic", "gem 'unic"
|
110
|
+
|
111
|
+
commit 'Switch from puma to unicorn'
|
112
|
+
end
|
113
|
+
|
102
114
|
def bundle_install
|
103
115
|
task 'Run bundle install, this may take a while'
|
104
116
|
run_from @target_path, 'bundle install'
|
@@ -108,7 +120,8 @@ module Orats
|
|
108
120
|
|
109
121
|
def bundle_binstubs
|
110
122
|
task 'Run bundle binstubs for a few gems'
|
111
|
-
run_from @target_path,
|
123
|
+
run_from @target_path,
|
124
|
+
"bundle binstubs whenever #{@options[:backend]} sidekiq"
|
112
125
|
|
113
126
|
commit 'Add binstubs for the important gems'
|
114
127
|
end
|
data/lib/orats/postgres.rb
CHANGED
@@ -38,7 +38,7 @@ module Orats
|
|
38
38
|
task 'Check if the postgres database exists'
|
39
39
|
|
40
40
|
# detect if the database already exists
|
41
|
-
database = File.basename(@target_path)
|
41
|
+
database = "#{File.basename(@target_path)}_development"
|
42
42
|
return if run("#{postgres_bin} -d #{database} -l | " + \
|
43
43
|
"grep #{database} | wc -l", capture: true).chomp == '0'
|
44
44
|
|
data/lib/orats/templates/base.rb
CHANGED
@@ -195,9 +195,18 @@ def add_puma_config
|
|
195
195
|
task __method__
|
196
196
|
|
197
197
|
orats_to_local 'config/puma.rb'
|
198
|
+
gsub_file 'config/puma.rb', 'app_name', app_name
|
198
199
|
commit 'Add the puma config'
|
199
200
|
end
|
200
201
|
|
202
|
+
def add_unicorn_config
|
203
|
+
task __method__
|
204
|
+
|
205
|
+
orats_to_local 'config/unicorn.rb'
|
206
|
+
gsub_file 'config/unicorn.rb', 'app_name', app_name
|
207
|
+
commit 'Add the unicorn config'
|
208
|
+
end
|
209
|
+
|
201
210
|
def add_sidekiq_config
|
202
211
|
task __method__
|
203
212
|
|
@@ -494,6 +503,7 @@ update_app_secrets
|
|
494
503
|
update_app_config
|
495
504
|
update_database_config
|
496
505
|
add_puma_config
|
506
|
+
add_unicorn_config
|
497
507
|
add_sidekiq_config
|
498
508
|
add_sitemap_config
|
499
509
|
add_whenever_config
|
@@ -29,8 +29,24 @@ ACTION_MAILER_DEFAULT_TO: 'me@app_name.com'
|
|
29
29
|
DATABASE_URL: 'postgresql://db_user@db_location:db_port/app_name?encoding=utf8&pool=5&timeout=5000'
|
30
30
|
CACHE_URL: 'redis://cache_location:cache_port/0'
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
# try setting these to 0/16 in production and tweak from there
|
33
|
+
# in development mode you should use 0/1 ( multi-threaded + debugging = :< )
|
34
|
+
# these only apply if you're using puma
|
35
|
+
THREADS_MIN: 0
|
36
|
+
THREADS_MAX: 1
|
37
|
+
|
38
|
+
# this should equal the number of CPU cores in production
|
39
|
+
# in development mode it set to 0 so puma does not go into cluster mode, unicorn
|
40
|
+
# will also correctly function with 0 workers in development mode
|
41
|
+
WORKERS: 1
|
42
|
+
|
43
|
+
# this should equal the database pool size
|
36
44
|
SIDEKIQ_CONCURRENCY: 5
|
45
|
+
|
46
|
+
# the path where logs get written to
|
47
|
+
# in production you might consider /var/log/app_name
|
48
|
+
LOG_PATH: 'log'
|
49
|
+
|
50
|
+
# the path that will contain pids and sockets
|
51
|
+
# in production you will likely want to set this to '/var/run/app_name'
|
52
|
+
RUN_STATE_PATH: 'tmp'
|
@@ -1,3 +1,3 @@
|
|
1
|
-
web: puma -C config/puma.rb
|
1
|
+
web: puma -C config/puma.rb | grep -v --line-buffered ' 304 -'
|
2
2
|
worker: sidekiq -C config/sidekiq.yml
|
3
3
|
log: tail -f log/development.log | grep -xv --line-buffered '^[[:space:]]*' | grep -v --line-buffered '/assets/'
|
@@ -1,19 +1,29 @@
|
|
1
1
|
environment ENV['RAILS_ENV']
|
2
2
|
|
3
|
-
threads ENV['
|
4
|
-
workers ENV['
|
3
|
+
threads ENV['THREADS_MIN'].to_i, ENV['THREADS_MAX'].to_i
|
4
|
+
workers ENV['WORKERS'].to_i
|
5
5
|
|
6
|
-
|
6
|
+
if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test'
|
7
|
+
bind 'tcp://0.0.0.0:3000'
|
8
|
+
else
|
9
|
+
bind "unix:#{ENV['RUN_STATE_PATH']}/app_name"
|
10
|
+
end
|
11
|
+
|
12
|
+
pidfile "#{ENV['RUN_STATE_PATH']}/app_name.pid"
|
13
|
+
|
14
|
+
worker_timeout 30
|
15
|
+
|
16
|
+
stdout_redirect "#{ENV['LOG_PATH']}/app_name.stdout.log",
|
17
|
+
"#{ENV['LOG_PATH']}/app_name.stderr.log"
|
7
18
|
|
8
|
-
|
9
|
-
prune_bundler
|
19
|
+
preload_app!
|
10
20
|
|
11
|
-
restart_command 'bundle exec
|
21
|
+
restart_command 'bundle exec puma'
|
12
22
|
|
13
23
|
on_worker_boot do
|
14
|
-
|
24
|
+
defined?(ActiveRecord::Base) and
|
25
|
+
ActiveRecord::Base.connection.disconnect!
|
15
26
|
|
16
|
-
|
17
|
-
|
18
|
-
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || YAML.load_file(config_path)[ENV['RAILS_ENV']])
|
27
|
+
defined?(ActiveRecord::Base) and
|
28
|
+
ActiveRecord::Base.establish_connection
|
19
29
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# heavily inspired by gitlab:
|
2
|
+
# https://github.com/gitlabhq/gitlabhq/blob/master/config/unicorn.rb.example
|
3
|
+
|
4
|
+
worker_processes ENV['WORKERS'].to_i
|
5
|
+
|
6
|
+
if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test'
|
7
|
+
listen '0.0.0.0:3000'
|
8
|
+
else
|
9
|
+
listen "unix:#{ENV['RUN_STATE_PATH']}/app_name", backlog: 64
|
10
|
+
end
|
11
|
+
|
12
|
+
pid "#{ENV['RUN_STATE_PATH']}/app_name.pid"
|
13
|
+
|
14
|
+
timeout 30
|
15
|
+
|
16
|
+
stdout_path "#{ENV['LOG_PATH']}/app_name.stdout.log"
|
17
|
+
stderr_path "#{ENV['LOG_PATH']}/app_name.stderr.log"
|
18
|
+
|
19
|
+
preload_app true
|
20
|
+
|
21
|
+
GC.respond_to?(:copy_on_write_friendly=) and
|
22
|
+
GC.copy_on_write_friendly = true
|
23
|
+
|
24
|
+
check_client_connection false
|
25
|
+
|
26
|
+
before_fork do |server, worker|
|
27
|
+
defined?(ActiveRecord::Base) and
|
28
|
+
ActiveRecord::Base.connection.disconnect!
|
29
|
+
|
30
|
+
# The following is only recommended for memory/DB-constrained
|
31
|
+
# installations. It is not needed if your system can house
|
32
|
+
# twice as many worker_processes as you have configured.
|
33
|
+
#
|
34
|
+
# This allows a new master process to incrementally
|
35
|
+
# phase out the old master process with SIGTTOU to avoid a
|
36
|
+
# thundering herd (especially in the "preload_app false" case)
|
37
|
+
# when doing a transparent upgrade. The last worker spawned
|
38
|
+
# will then kill off the old master process with a SIGQUIT.
|
39
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
40
|
+
if old_pid != server.pid
|
41
|
+
begin
|
42
|
+
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
43
|
+
Process.kill(sig, File.read(old_pid).to_i)
|
44
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
after_fork do |server, worker|
|
50
|
+
defined?(ActiveRecord::Base) and
|
51
|
+
ActiveRecord::Base.establish_connection
|
52
|
+
end
|
data/lib/orats/version.rb
CHANGED
@@ -23,6 +23,10 @@ class TestCLI < Minitest::Test
|
|
23
23
|
assert_new '--template auth'
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_new_with_unicorn
|
27
|
+
assert_new '--backend unicorn'
|
28
|
+
end
|
29
|
+
|
26
30
|
def test_new_with_invalid_template
|
27
31
|
@target_path = generate_app_name
|
28
32
|
@extra_flags = "#{ORATS_NEW_FLAGS} --template foo"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Janetakis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- lib/orats/templates/includes/new/rails/config/secrets.yml
|
138
138
|
- lib/orats/templates/includes/new/rails/config/sidekiq.yml
|
139
139
|
- lib/orats/templates/includes/new/rails/config/sitemap.rb
|
140
|
+
- lib/orats/templates/includes/new/rails/config/unicorn.rb
|
140
141
|
- lib/orats/templates/includes/new/rails/lib/tasks/orats/favicon.rake
|
141
142
|
- lib/orats/templates/includes/new/rails/public/404.html
|
142
143
|
- lib/orats/templates/includes/new/rails/public/422.html
|