railman 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7dd8f9ea6008b9afb27376763c562163572b470
4
- data.tar.gz: 20e7645221bce277f9d603b159b73450908214bb
3
+ metadata.gz: acc098517b4918ee82a037121e6a507cb7bfe746
4
+ data.tar.gz: ff24ea121eadcaf6b80e4b0415b12fc513644fc4
5
5
  SHA512:
6
- metadata.gz: ee6352c4ee9f16190cd5a9fbfcb3b16dad3503a93a8bc3e8fcd5700002e5f15acc8bf7fb731fd13552eadedc980907ae20c6ecaf43e752c4f4c516a5acdad2fa
7
- data.tar.gz: 6718d82038478ca897fef10eb8e0d0869e2475980403dca45041d88bec78f622d9b6ee673e29c70992ed1071aa8416cd9070f40161b3d6eb8882dc04853427d7
6
+ metadata.gz: c23f33b06866d7f2284cb3fc11d2f1061569c3c466076989d212ef1d48302a27c2f91c0397e28277369f3f7e1b2da0a12555c9f76ad27361020795e3fa80afcf
7
+ data.tar.gz: d730ff383b32f58a3ff98e309201b36d0cc47cd3ff8de3828d60af274dc8ae61ce180c1209ae2b8abf8b65f4d067c0f63a2728bc4e2ab887fd1f0ace2f5cfd2f
data/CUSTOMIZATION.md CHANGED
@@ -47,9 +47,9 @@ The configuration of the processes that the application includes (app server, wo
47
47
 
48
48
  The eye gem is not included in the Gemfile. Eye should be installed globally on the server or your local machine and there will be only one eye process that manages multiple rails applications.
49
49
 
50
- ## .env.example
50
+ ## .env.example.development and .env.example.production
51
51
 
52
- This is a template for the application- and server-specific .env file.
52
+ These are templates for the application- and server-specific .env file (for development and production).
53
53
 
54
54
  ## config/deploy/production.rb
55
55
 
data/lib/railman/cli.rb CHANGED
@@ -38,7 +38,7 @@ module Railman
38
38
  directory "rails_app", app_name
39
39
  @rake_secret = Railman::Secret.generate_secret
40
40
  @unicorn_behind_nginx = false
41
- template "rails_app/.env.example.tt", "#{app_name}/.env"
41
+ template "rails_app/.env.example.development.tt", "#{app_name}/.env"
42
42
  Dir.chdir app_name do
43
43
  run "bundle install"
44
44
  create_local_git_repository
@@ -1,3 +1,3 @@
1
1
  module Railman
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -0,0 +1,33 @@
1
+ # Put server-specific environment variables here
2
+ # .env is loaded by the dotenv gem on startup
3
+ # Don't commit this file to Git !!! Copy from .env.example.development and modify for each machine
4
+
5
+ # Application settings
6
+ APP_NAME = '<%= app_name %>'
7
+
8
+
9
+ # Database settings
10
+ DB_USER = 'user'
11
+ DB_PASSWORD = 'password'
12
+
13
+
14
+ # Session secret - generate with: rake secret
15
+ SECRET_TOKEN = '<%= @rake_secret %>'
16
+
17
+
18
+ # Where to send exceptions and other admin emails
19
+ ADMIN_EMAIL = '<%= @admin_email %>'
20
+
21
+
22
+ # Exception notification settings
23
+ EXCEPTION_NOTIFICATION_EMAIL_PREFIX = '[<%= @class_name %>] '
24
+ EXCEPTION_NOTIFICATION_SENDER = 'server@<%= @domain %>'
25
+
26
+
27
+ # Unicorn settings
28
+ UNICORN_BEHIND_NGINX = <%= @unicorn_behind_nginx %>
29
+ # UNICORN_PORT = 3000
30
+
31
+
32
+ # Rails environment
33
+ RAILS_ENV = 'development'
@@ -1,6 +1,6 @@
1
1
  # Put server-specific environment variables here
2
2
  # .env is loaded by the dotenv gem on startup
3
- # Don't commit this file to Git !!! Copy from .env.example and modify for each machine
3
+ # Don't commit this file to Git !!! Copy from .env.example.production and modify for each machine
4
4
 
5
5
  # Application settings
6
6
  APP_NAME = '<%= app_name %>'
@@ -22,18 +22,20 @@ SMTP_PASSWORD = '*****'
22
22
  SMTP_DOMAIN = '<%= @domain %>'
23
23
  SMTP_DEFAULT_URL = '<%= @domain %>'
24
24
 
25
+
25
26
  # Where to send exceptions and other admin emails
26
27
  ADMIN_EMAIL = '<%= @admin_email %>'
27
28
 
29
+
28
30
  # Exception notification settings
29
31
  EXCEPTION_NOTIFICATION_EMAIL_PREFIX = '[<%= @class_name %>] '
30
32
  EXCEPTION_NOTIFICATION_SENDER = 'server@<%= @domain %>'
31
33
 
34
+
32
35
  # Unicorn settings
33
- UNICORN_BEHIND_NGINX = <%= @unicorn_behind_nginx %>
34
- # UNICORN_WORKERS = 1
35
- # UNICORN_PORT = 3000
36
- # UNICORN_TIMEOUT = 60
36
+ UNICORN_BEHIND_NGINX = true
37
+ UNICORN_WORKERS = 4
38
+
37
39
 
38
40
  # Rails environment
39
- RAILS_ENV = 'development'
41
+ RAILS_ENV = 'production'
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.1.5
@@ -21,9 +21,10 @@ Eye.application APP_NAME do
21
21
  trigger :flapping, times: 3, within: 1.minute, retry_in: 1.minutes, retry_times: 1
22
22
 
23
23
  process :unicorn do
24
- unicorn_env = { 'RAILS_ENV' => RAILS_ENV, 'UNICORN_WORKERS' => UNICORN_WORKERS }
24
+ unicorn_env = { 'RAILS_ENV' => RAILS_ENV, 'UNICORN_BEHIND_NGINX' => UNICORN_BEHIND_NGINX }
25
+ unicorn_env['UNICORN_WORKERS'] = UNICORN_WORKERS if defined?(UNICORN_WORKERS)
26
+ unicorn_env['UNICORN_TIMEOUT'] = UNICORN_TIMEOUT if defined?(UNICORN_TIMEOUT)
25
27
  unicorn_env['UNICORN_PORT'] = UNICORN_PORT if defined?(UNICORN_PORT)
26
- unicorn_env['UNICORN_SOCK'] = UNICORN_SOCK if defined?(UNICORN_SOCK)
27
28
  env unicorn_env
28
29
  start_command "./bin/unicorn -c #{APP_ROOT}/config/unicorn.rb -E #{RAILS_ENV} -D"
29
30
  pid_file './tmp/pids/unicorn.pid'
@@ -25,18 +25,13 @@ gem 'kgio' # gives dalli 20-30% performance boost
25
25
  gem 'unicorn', '4.8.3' # use unicorn as production server
26
26
  gem 'unicorn-rails', '1.1.0' # use unicorn as local server
27
27
 
28
- # capistrano deployment
29
- gem 'capistrano', '3.1.0'
30
- gem 'capistrano-rails', '1.1.1'
31
- gem 'capistrano-rbenv', '2.0.2'
32
- gem 'capistrano-bundler', '1.1.2'
28
+ gem 'capistrano', '3.4.1' # capistrano deployment
33
29
 
34
30
  gem 'exception_notification', '4.1.2' # exception notification per email
35
31
 
36
32
  group :development do
37
33
  gem 'better_errors' # better error pages in development
38
34
  gem 'binding_of_caller' # repl on the error page
39
- gem 'spring' # Spring speeds up development by keeping your application running in the background
40
35
  gem 'quiet_assets' # less noise in development log
41
36
  # gem 'rack-mini-profiler'
42
37
  # gem 'flamegraph' # mini-profiler flamegraph extension (?pp=flamegraph)
@@ -12,4 +12,4 @@ Try to keep all the application/server/environment specific settings, as well as
12
12
 
13
13
  ## create local database
14
14
 
15
- todo: rake tasks
15
+ Run `rake db:create`
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'cap' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('capistrano', 'cap')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'capify' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('capistrano', 'capify')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'unicorn' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('unicorn', 'unicorn')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'unicorn_rails' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('unicorn', 'unicorn_rails')
@@ -1,5 +1,5 @@
1
1
  # Capistrano deployment tasks
2
- lock '3.1.0'
2
+ lock '3.4.1'
3
3
 
4
4
  set :application, '<%= app_name %>'
5
5
  set :repo_url, '<%= @repository.origin %>'
@@ -14,30 +14,45 @@ SSHKit.config.command_map[:rake] = "#{fetch(:deploy_to)}/bin/rake"
14
14
  end
15
15
  SSHKit.config.command_map[:eye] = "#{fetch(:rbenv_home)}/shims/eye"
16
16
  SSHKit.config.command_map[:su_rm] = "sudo rm"
17
- SSHKit.config.command_map[:letsencrypt] = "/opt/letsencrypt/letsencrypt-auto"
18
17
 
19
18
  desc "Setup rails application for the first time on a server"
20
19
  task :setup do
21
20
  on roles(:all) do
22
21
  with fetch(:environment) do
23
- execute :git, :clone, fetch(:repo_url), fetch(:deploy_to)
22
+ if test "[ -d #{fetch(:deploy_to)} ]"
23
+ within fetch(:deploy_to) do
24
+ execute :git, :fetch, 'origin'
25
+ execute :git, :reset, '--hard origin/master'
26
+ end
27
+ else
28
+ execute :git, :clone, fetch(:repo_url), fetch(:deploy_to)
29
+ end
30
+ server_conf_dir = "#{fetch(:deploy_to)}/config/server"
31
+ execute :ln, "-s -f #{server_conf_dir}/nginx.conf /etc/nginx/conf.d/#{fetch(:application)}.conf"
32
+ execute :ln, "-s -f #{server_conf_dir}/letsencrypt.conf /etc/nginx/letsencrypt/#{fetch(:application)}.conf"
33
+ execute :ln, "-s -f #{server_conf_dir}/logrotate.conf /etc/logrotate.d/#{fetch(:application)}"
24
34
  within fetch(:deploy_to) do
25
- execute :bundle, :install
26
- execute :rake, 'db:create'
27
- execute :psql, "-d #{fetch(:application)}_production", "-f db/#{fetch(:application)}.sql"
28
- execute :rake, 'db:migrate'
29
- execute :rake, 'assets:precompile'
35
+ execute :bundle, :install, "--without development test"
30
36
  execute :mkdir, "-p #{fetch(:deploy_to)}/tmp/pids"
37
+ if test "[ -f #{fetch(:deploy_to)}/.env ]"
38
+ execute :rake, 'db:create'
39
+ if test "[ -f #{fetch(:deploy_to)}/db/#{fetch(:application)}.sql ]"
40
+ execute :psql, "-d #{fetch(:application)}_production", "-f db/#{fetch(:application)}.sql"
41
+ end
42
+ execute :rake, 'db:migrate'
43
+ execute :rake, 'assets:precompile'
44
+ execute :eye, :load, 'Eyefile'
45
+ execute :eye, :start, fetch(:application)
46
+ execute :service, "nginx restart"
47
+ else
48
+ warn "TODO 1: Create .env on the server by copying from .env.example.production and modify your database and smtp settings."
49
+ warn "TODO 2: Create rails secret token with 'rake secret' and insert it into .env"
50
+ warn "TODO 3: Check if you have ssl certificates for #{fetch(:application)} in /etc/letsencrypt/live/<%= @domain %>"
51
+ warn "TODO 4: If not, create ssl certificates by running the following command as root: "
52
+ warn " /opt/letsencrypt/letsencrypt-auto --config /etc/nginx/letsencrypt/#{fetch(:application)}.conf --standalone certonly"
53
+ warn "TODO 5: Run 'cap ENV setup' again!"
54
+ end
31
55
  end
32
- server_conf_dir = "#{fetch(:deploy_to)}/config/server"
33
- execute :ln, "-s #{server_conf_dir}/nginx.conf /etc/nginx/conf.d/#{fetch(:application)}.conf"
34
- execute :ln, "-s #{server_conf_dir}/letsencrypt.conf /etc/nginx/letsencrypt/#{fetch(:application)}.conf"
35
- execute :ln, "-s #{server_conf_dir}/logrotate.conf /etc/logrotate.d/#{fetch(:application)}"
36
- execute :eye, :load, 'Eyefile'
37
- execute :eye, :start, fetch(:application)
38
- execute :service, "nginx stop"
39
- execute :letsencrypt, "--config /etc/nginx/letsencrypt/#{fetch(:application)}.conf --standalone certonly"
40
- execute :service, "nginx start"
41
56
  end
42
57
  end
43
58
  end
@@ -47,14 +62,13 @@ task :remove do
47
62
  on roles(:all) do
48
63
  with fetch(:environment) do
49
64
  within fetch(:deploy_to) do
65
+ execute :eye, :load, 'Eyefile'
66
+ execute :eye, :stop, fetch(:application)
50
67
  execute :rake, 'db:drop'
68
+ execute :su_rm, "-rf #{fetch(:deploy_to)}"
51
69
  end if test "[ -d #{fetch(:deploy_to)} ]"
52
- execute :eye, :load, 'Eyefile'
53
- execute :eye, :stop, fetch(:application)
54
- execute :su_rm, "-f /etc/init/#{fetch(:application)}*"
55
- execute :su_rm, "-rf #{fetch(:deploy_to)}"
56
70
  execute :su_rm, "-f /etc/nginx/conf.d/#{fetch(:application)}.conf"
57
- execute :su_rm, "-f /etc/nginx/conf.d/#{fetch(:application)}_ssl.conf"
71
+ execute :su_rm, "-f /etc/nginx/letsencrypt/#{fetch(:application)}.conf"
58
72
  execute :su_rm, "-f /etc/logrotate.d/#{fetch(:application)}"
59
73
  execute :service, "nginx restart"
60
74
  end
@@ -103,7 +117,9 @@ task :reset_server do
103
117
  execute :git, :reset, '--hard origin/master'
104
118
  execute :rake, 'db:drop'
105
119
  execute :rake, 'db:create'
106
- execute :psql, "-d #{fetch(:application)}_production", "-f db/#{fetch(:application)}.sql"
120
+ if test "[ -f #{fetch(:deploy_to)}/db/#{fetch(:application)}.sql ]"
121
+ execute :psql, "-d #{fetch(:application)}_production", "-f db/#{fetch(:application)}.sql"
122
+ end
107
123
  execute :rake, 'db:migrate'
108
124
  execute :eye, :start, fetch(:application)
109
125
  execute :service, "nginx restart"
@@ -59,6 +59,7 @@ server {
59
59
  return 301 https://<%= @domain %>$request_uri;
60
60
  }
61
61
 
62
+ <% if @www_domain %>
62
63
  server {
63
64
  listen 443 ssl;
64
65
  server_name <%= @www_domain %>;
@@ -68,3 +69,4 @@ server {
68
69
  ssl_certificate /etc/letsencrypt/live/<%= @domain %>/fullchain.pem;
69
70
  ssl_certificate_key /etc/letsencrypt/live/<%= @domain %>/privkey.pem;
70
71
  }
72
+ <% end %>
@@ -5,13 +5,13 @@ APP_ROOT = File.expand_path('../..', __FILE__)
5
5
  require 'dotenv'
6
6
  Dotenv.load
7
7
 
8
- timeout Integer(ENV['UNICORN_TIMEOUT'] || 60)
9
8
  if ENV['UNICORN_BEHIND_NGINX']
10
9
  listen '/tmp/unicorn.<%= app_name %>.sock'
11
10
  else
12
11
  listen Integer(ENV['UNICORN_PORT'] || 3000)
13
12
  end
14
13
  worker_processes Integer(ENV['UNICORN_WORKERS'] || 1)
14
+ timeout Integer(ENV['UNICORN_TIMEOUT'] || 60)
15
15
  working_directory APP_ROOT
16
16
  pid "#{APP_ROOT}/tmp/pids/unicorn.pid"
17
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Jancev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -160,7 +160,8 @@ files:
160
160
  - lib/railman/secret.rb
161
161
  - lib/railman/version.rb
162
162
  - railman.gemspec
163
- - templates/rails_app/.env.example.tt
163
+ - templates/rails_app/.env.example.development.tt
164
+ - templates/rails_app/.env.example.production.tt
164
165
  - templates/rails_app/.envrc
165
166
  - templates/rails_app/.gitignore
166
167
  - templates/rails_app/.ruby-version
@@ -184,10 +185,14 @@ files:
184
185
  - templates/rails_app/app/views/layouts/_messages.html.erb
185
186
  - templates/rails_app/app/views/layouts/application.html.erb.tt
186
187
  - templates/rails_app/bin/bundle
188
+ - templates/rails_app/bin/cap
189
+ - templates/rails_app/bin/capify
187
190
  - templates/rails_app/bin/rails
188
191
  - templates/rails_app/bin/rake
189
192
  - templates/rails_app/bin/setup
190
193
  - templates/rails_app/bin/spring
194
+ - templates/rails_app/bin/unicorn
195
+ - templates/rails_app/bin/unicorn_rails
191
196
  - templates/rails_app/config.ru
192
197
  - templates/rails_app/config/application.rb.tt
193
198
  - templates/rails_app/config/boot.rb
@@ -213,7 +218,7 @@ files:
213
218
  - templates/rails_app/config/server/letsencrypt.conf.tt
214
219
  - templates/rails_app/config/server/logrotate.conf.tt
215
220
  - templates/rails_app/config/server/nginx.conf.tt
216
- - templates/rails_app/config/unicorn.rb
221
+ - templates/rails_app/config/unicorn.rb.tt
217
222
  - templates/rails_app/db/seeds.rb
218
223
  - templates/rails_app/lib/assets/.keep
219
224
  - templates/rails_app/lib/tasks/.keep