railman 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/railman/cli.rb +47 -21
- data/lib/railman/config.rb +9 -0
- data/lib/railman/version.rb +1 -1
- data/templates/rails_app/.env.example.development.tt +4 -4
- data/templates/rails_app/.env.example.production.tt +8 -8
- data/templates/rails_app/Eyefile.tt +3 -3
- data/templates/rails_app/app/views/home/index.html.erb.tt +1 -1
- data/templates/rails_app/app/views/layouts/application.html.erb.tt +1 -1
- data/templates/rails_app/config/application.rb.tt +1 -1
- data/templates/rails_app/config/database.yml.tt +3 -3
- data/templates/rails_app/config/deploy.rb.tt +6 -2
- data/templates/rails_app/config/deploy/production.rb.tt +1 -1
- data/templates/rails_app/config/environments/{production.rb → production.rb.tt} +1 -1
- data/templates/rails_app/config/initializers/session_store.rb.tt +2 -2
- data/templates/rails_app/config/initializers/sidekiq.rb.tt +2 -2
- data/templates/rails_app/config/server/letsencrypt.conf.tt +3 -3
- data/templates/rails_app/config/server/logrotate.conf.tt +1 -1
- data/templates/rails_app/config/server/nginx.conf.tt +16 -16
- data/templates/rails_app/config/unicorn.rb.tt +1 -1
- data/templates/rails_app/test/integration/homepage_test.rb.tt +1 -1
- 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: e1ecb9d6bcb4c0a2dbd78093cd8892efe6b89884
|
4
|
+
data.tar.gz: 9a65f64857c7dd6e9dd27e451addebb774d4eb86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d436a33a67ad227d9975bb7059ae627aa9133c75af7cd6b3f4d3cea50b4547ffe81f3e716313af694cc3c3d9549b81364a496f4faea32612c4d0681994716f2
|
7
|
+
data.tar.gz: 8370baad6e71bf1d1436e25c299e188359496c1ca80739b25e5d3613272c4df32e4813be9dcdb1b35bf1c5ee02beac411e50eeac28f2e3bf474bba55ecc120c1
|
data/README.md
CHANGED
data/lib/railman/cli.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'yaml'
|
2
3
|
require 'creategem'
|
4
|
+
require 'railman/config'
|
3
5
|
require 'railman/secret'
|
4
6
|
|
5
7
|
module Railman
|
@@ -17,50 +19,74 @@ module Railman
|
|
17
19
|
desc "new APPNAME", "Create new rails application named APPNAME"
|
18
20
|
def new(app_name)
|
19
21
|
say "Create a new rails application named: #{app_name}", :green
|
20
|
-
|
22
|
+
config = create_config(app_name)
|
23
|
+
apply_rails_template(config)
|
21
24
|
say "The rails application '#{app_name}' was successfully created.", :green
|
22
25
|
say "Please check the settings in .env", :blue
|
23
26
|
end
|
24
27
|
|
25
28
|
desc "upgrade APPNAME", "Upgrade the rails upplication named APPNAME"
|
26
29
|
def upgrade(app_name)
|
27
|
-
puts "
|
28
|
-
|
30
|
+
puts "Upgrade the rails application: #{app_name}"
|
31
|
+
config = load_config(app_name)
|
32
|
+
apply_rails_template(config, false)
|
29
33
|
say "The rails application '#{app_name}' was successfully upgraded.", :green
|
30
34
|
say "Please check the settings in .env", :blue
|
31
35
|
end
|
32
36
|
|
33
37
|
private
|
34
38
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def create_config(app_name)
|
40
|
+
config = Railman::Config.new
|
41
|
+
config.app_name = app_name
|
42
|
+
config.class_name = Thor::Util.camel_case(app_name)
|
43
|
+
config.admin_email = ask("What is the adminitrator email address?")
|
44
|
+
config.domain = ask("What is the url of the application (without http and www)?")
|
45
|
+
if yes?("Do you want me to configure www.#{config.domain} domain to be redirected to #{config.domain}? (y/n)")
|
46
|
+
config.www_domain = "www.#{config.domain}"
|
47
|
+
config.domains = [config.domain, config.www_domain]
|
43
48
|
else
|
44
|
-
|
45
|
-
|
49
|
+
config.www_domain = nil
|
50
|
+
config.domains = [config.domain]
|
46
51
|
end
|
47
|
-
|
52
|
+
config
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_config(app_name)
|
56
|
+
if File.exists? File.join(app_name, ".railman")
|
57
|
+
YAML::load_file File.join(app_name, ".railman")
|
58
|
+
else
|
59
|
+
create_config(app_name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def save_config(config)
|
64
|
+
File.open File.join(config.app_name, ".railman"), "w" do |file|
|
65
|
+
file.write config.to_yaml
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def apply_rails_template(config, create = true)
|
70
|
+
@config = config
|
48
71
|
@repository = Creategem::Repository.new(vendor: :bitbucket,
|
49
72
|
user: git_repository_user_name(:bitbucket),
|
50
|
-
name: app_name,
|
73
|
+
name: @config.app_name,
|
51
74
|
gem_server_url: gem_server_url(:bitbucket))
|
52
75
|
@rake_secret = "TODO: generate with: rake secret"
|
53
76
|
@unicorn_behind_nginx = true
|
54
|
-
directory "rails_app", app_name
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
77
|
+
directory "rails_app", @config.app_name
|
78
|
+
if create
|
79
|
+
@rake_secret = Railman::Secret.generate_secret
|
80
|
+
@unicorn_behind_nginx = false
|
81
|
+
template "rails_app/.env.example.development.tt", "#{@config.app_name}/.env"
|
82
|
+
save_config(@config)
|
83
|
+
end
|
84
|
+
Dir.chdir @config.app_name do
|
59
85
|
run "bundle install"
|
60
86
|
run "chmod +x bin/*"
|
61
87
|
if create
|
62
88
|
create_local_git_repository
|
63
|
-
create_remote_git_repository(@repository) if yes?("Do you want me to create bitbucket repository named #{app_name}? (y/n)")
|
89
|
+
create_remote_git_repository(@repository) if yes?("Do you want me to create bitbucket repository named #{@config.app_name}? (y/n)")
|
64
90
|
end
|
65
91
|
end
|
66
92
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
# Railman::Config contains configuration parameters used to generate the rails application
|
4
|
+
# It is saved in .railman in the generated application, so that it can be used to upgrade the application later.
|
5
|
+
module Railman
|
6
|
+
class Config
|
7
|
+
attr_accessor :app_name, :class_name, :admin_email, :domain, :www_domain, :domains, :server
|
8
|
+
end
|
9
|
+
end
|
data/lib/railman/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Don't commit this file to Git !!! Copy from .env.example.development and modify for each machine
|
4
4
|
|
5
5
|
# Application settings
|
6
|
-
APP_NAME = '<%= app_name %>'
|
6
|
+
APP_NAME = '<%= @config.app_name %>'
|
7
7
|
|
8
8
|
|
9
9
|
# Database settings
|
@@ -16,12 +16,12 @@ SECRET_TOKEN = '<%= @rake_secret %>'
|
|
16
16
|
|
17
17
|
|
18
18
|
# Where to send exceptions and other admin emails
|
19
|
-
ADMIN_EMAIL = '<%= @admin_email %>'
|
19
|
+
ADMIN_EMAIL = '<%= @config.admin_email %>'
|
20
20
|
|
21
21
|
|
22
22
|
# Exception notification settings
|
23
|
-
EXCEPTION_NOTIFICATION_EMAIL_PREFIX = '[<%= @class_name %>] '
|
24
|
-
EXCEPTION_NOTIFICATION_SENDER = 'server@<%= @domain %>'
|
23
|
+
EXCEPTION_NOTIFICATION_EMAIL_PREFIX = '[<%= @config.class_name %>] '
|
24
|
+
EXCEPTION_NOTIFICATION_SENDER = 'server@<%= @config.domain %>'
|
25
25
|
|
26
26
|
|
27
27
|
# Unicorn settings
|
@@ -3,7 +3,7 @@
|
|
3
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
|
-
APP_NAME = '<%= app_name %>'
|
6
|
+
APP_NAME = '<%= @config.app_name %>'
|
7
7
|
|
8
8
|
|
9
9
|
# Database settings
|
@@ -16,20 +16,20 @@ SECRET_TOKEN = '<%= @rake_secret %>'
|
|
16
16
|
|
17
17
|
|
18
18
|
# SMTP server settings
|
19
|
-
SMTP_SERVER = 'mail.<%= @domain %>'
|
20
|
-
SMTP_USER = 'server@<%= @domain %>'
|
19
|
+
SMTP_SERVER = 'mail.<%= @config.domain %>'
|
20
|
+
SMTP_USER = 'server@<%= @config.domain %>'
|
21
21
|
SMTP_PASSWORD = '*****'
|
22
|
-
SMTP_DOMAIN = '<%= @domain %>'
|
23
|
-
SMTP_DEFAULT_URL = '<%= @domain %>'
|
22
|
+
SMTP_DOMAIN = '<%= @config.domain %>'
|
23
|
+
SMTP_DEFAULT_URL = '<%= @config.domain %>'
|
24
24
|
|
25
25
|
|
26
26
|
# Where to send exceptions and other admin emails
|
27
|
-
ADMIN_EMAIL = '<%= @admin_email %>'
|
27
|
+
ADMIN_EMAIL = '<%= @config.admin_email %>'
|
28
28
|
|
29
29
|
|
30
30
|
# Exception notification settings
|
31
|
-
EXCEPTION_NOTIFICATION_EMAIL_PREFIX = '[<%= @class_name %>] '
|
32
|
-
EXCEPTION_NOTIFICATION_SENDER = 'server@<%= @domain %>'
|
31
|
+
EXCEPTION_NOTIFICATION_EMAIL_PREFIX = '[<%= @config.class_name %>] '
|
32
|
+
EXCEPTION_NOTIFICATION_SENDER = 'server@<%= @config.domain %>'
|
33
33
|
|
34
34
|
|
35
35
|
# Unicorn settings
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Eye configuration file (https://github.com/kostya/eye)
|
2
2
|
# Load with: 'eye l Eyefile'
|
3
3
|
# Watch processes: 'eye w'
|
4
|
-
# Stop all processes: 'eye stop <%= app_name %>'
|
5
|
-
# Start all processes: 'eye start <%= app_name %>'
|
6
|
-
# Restart unicorn: 'eye restart <%= app_name %>:unicorn'
|
4
|
+
# Stop all processes: 'eye stop <%= @config.app_name %>'
|
5
|
+
# Start all processes: 'eye start <%= @config.app_name %>'
|
6
|
+
# Restart unicorn: 'eye restart <%= @config.app_name %>:unicorn'
|
7
7
|
|
8
8
|
APP_ROOT = File.expand_path('..', __FILE__)
|
9
9
|
|
@@ -1 +1 @@
|
|
1
|
-
<p>Welcome to: <%= @class_name %></p>
|
1
|
+
<p>Welcome to: <%= @config.class_name %></p>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
7
7
|
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
8
8
|
|
9
|
-
<title><%= @class_name %></title>
|
9
|
+
<title><%= @config.class_name %></title>
|
10
10
|
<%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
11
11
|
<%%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
12
12
|
|
@@ -6,7 +6,7 @@ require 'rails/all'
|
|
6
6
|
# you've limited to :test, :development, or :production.
|
7
7
|
Bundler.require(*Rails.groups)
|
8
8
|
|
9
|
-
module <%= @class_name %>
|
9
|
+
module <%= @config.class_name %>
|
10
10
|
class Application < Rails::Application
|
11
11
|
# Settings in config/environments/* take precedence over those specified here.
|
12
12
|
# Application configuration should go into files in config/initializers
|
@@ -3,7 +3,7 @@ development:
|
|
3
3
|
encoding: unicode
|
4
4
|
port: 5432
|
5
5
|
host: localhost
|
6
|
-
database: <%= app_name %>_development
|
6
|
+
database: <%= @config.app_name %>_development
|
7
7
|
username: <%%= ENV['DB_USER'] %>
|
8
8
|
password: <%%= ENV['DB_PASSWORD'] %>
|
9
9
|
pool: 5
|
@@ -14,7 +14,7 @@ test:
|
|
14
14
|
encoding: unicode
|
15
15
|
port: 5432
|
16
16
|
host: localhost
|
17
|
-
database: <%= app_name %>_test
|
17
|
+
database: <%= @config.app_name %>_test
|
18
18
|
username: <%%= ENV['DB_USER'] %>
|
19
19
|
password: <%%= ENV['DB_PASSWORD'] %>
|
20
20
|
pool: 5
|
@@ -25,7 +25,7 @@ production:
|
|
25
25
|
encoding: unicode
|
26
26
|
port: 5432
|
27
27
|
host: localhost
|
28
|
-
database: <%= app_name %>_production
|
28
|
+
database: <%= @config.app_name %>_production
|
29
29
|
username: <%%= ENV['DB_USER'] %>
|
30
30
|
password: <%%= ENV['DB_PASSWORD'] %>
|
31
31
|
pool: 15
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# Capistrano deployment tasks
|
2
2
|
lock '3.4.1'
|
3
3
|
|
4
|
-
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
set :application, '<%= @config.app_name %>'
|
5
7
|
set :repo_url, '<%= @repository.origin %>'
|
6
8
|
set :deploy_to, "/home/deploy/apps/#{fetch(:application)}"
|
7
9
|
set :rbenv_home, '/home/deploy/.rbenv'
|
@@ -45,7 +47,9 @@ task :setup do
|
|
45
47
|
execute :eye, :start, fetch(:application)
|
46
48
|
execute :service, "nginx restart"
|
47
49
|
else
|
48
|
-
|
50
|
+
execute :cp, '.env.example.production', '.env'
|
51
|
+
execute "sed -i -e 's/TODO: generate with: rake secret/#{SecureRandom.hex(64)}/g' .en"
|
52
|
+
warn "TODO: Edit .env and modify your database and smtp settings."
|
49
53
|
warn "TODO: Create rails secret token with 'rake secret' and insert it into .env"
|
50
54
|
warn "TODO: Create ssl certificates by running the following command as root: /etc/letsencrypt/generate_letsencrypt.sh"
|
51
55
|
warn "TODO: Run 'cap ENV setup' again!"
|
@@ -56,7 +56,7 @@ Rails.application.configure do
|
|
56
56
|
|
57
57
|
# Use a different cache store in production.
|
58
58
|
# config.cache_store = :mem_cache_store
|
59
|
-
config.cache_store = :dalli_store, { namespace:
|
59
|
+
config.cache_store = :dalli_store, { namespace: '<%= @config.app_name %>:' }
|
60
60
|
|
61
61
|
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
62
62
|
# config.action_controller.asset_host = 'http://assets.example.com'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
2
2
|
|
3
3
|
Rails.application.config.session_store :redis_session_store, {
|
4
|
-
key: "_<%= app_name %>_session",
|
5
|
-
redis: { key_prefix: "<%= app_name %>:", expire_after: 2.minutes }
|
4
|
+
key: "_<%= @config.app_name %>_session",
|
5
|
+
redis: { key_prefix: "<%= @config.app_name %>:", expire_after: 2.minutes }
|
6
6
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'sidekiq/scheduler'
|
2
2
|
|
3
|
-
# Configure Sidekiq Redis connection to use the '<%= app_name %>' namespace
|
4
|
-
redis_config = { url: 'redis://localhost:6379', namespace: '<%= app_name
|
3
|
+
# Configure Sidekiq Redis connection to use the '<%= @config.app_name %>' namespace
|
4
|
+
redis_config = { url: 'redis://localhost:6379', namespace: '<%= @config.app_name %>:' }
|
5
5
|
|
6
6
|
Sidekiq.configure_server do |config|
|
7
7
|
config.redis = redis_config
|
@@ -2,13 +2,13 @@
|
|
2
2
|
rsa-key-size = 4096
|
3
3
|
|
4
4
|
# this address will receive renewal reminders, IIRC
|
5
|
-
email = <%= @admin_email %>
|
5
|
+
email = <%= @config.admin_email %>
|
6
6
|
|
7
7
|
# Generate certificates for the specified domains
|
8
|
-
domains = <%= @domains.join(',') %>
|
8
|
+
domains = <%= @config.domains.join(',') %>
|
9
9
|
|
10
10
|
# turn off the ncurses UI, we want this to be run as a cronjob
|
11
11
|
text = True
|
12
12
|
|
13
13
|
# authenticate by placing a file in the webroot (under .well-known/acme-challenge/) and then letting LE fetch it
|
14
|
-
webroot-path = /home/deploy/apps/<%= app_name %>
|
14
|
+
webroot-path = /home/deploy/apps/<%= @config.app_name %>
|
@@ -1,13 +1,13 @@
|
|
1
|
-
upstream <%= app_name %> {
|
2
|
-
server unix:/tmp/unicorn.<%= app_name %>.sock fail_timeout=0;
|
1
|
+
upstream <%= @config.app_name %> {
|
2
|
+
server unix:/tmp/unicorn.<%= @config.app_name %>.sock fail_timeout=0;
|
3
3
|
}
|
4
4
|
|
5
5
|
server {
|
6
6
|
listen 443 ssl;
|
7
|
-
server_name <%= @domain %>;
|
7
|
+
server_name <%= @config.domain %>;
|
8
8
|
|
9
9
|
index index.html;
|
10
|
-
root /home/deploy/apps/<%= app_name %>/public;
|
10
|
+
root /home/deploy/apps/<%= @config.app_name %>/public;
|
11
11
|
try_files $uri/index.html $uri @app;
|
12
12
|
|
13
13
|
location @app {
|
@@ -18,7 +18,7 @@ server {
|
|
18
18
|
|
19
19
|
proxy_set_header Host $http_host;
|
20
20
|
proxy_redirect off;
|
21
|
-
proxy_pass http://<%= app_name %>;
|
21
|
+
proxy_pass http://<%= @config.app_name %>;
|
22
22
|
}
|
23
23
|
|
24
24
|
client_max_body_size 100m;
|
@@ -37,17 +37,17 @@ server {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
location ~ ^/(assets)/ {
|
40
|
-
root /home/deploy/apps/<%= app_name %>/public;
|
40
|
+
root /home/deploy/apps/<%= @config.app_name %>/public;
|
41
41
|
gzip_static on; # to serve pre-gzipped version
|
42
42
|
expires max;
|
43
43
|
add_header Cache-Control public;
|
44
44
|
}
|
45
45
|
|
46
46
|
# Let's Encrypt certificates
|
47
|
-
ssl_certificate /etc/letsencrypt/live/<%= @domain %>/fullchain.pem;
|
48
|
-
ssl_certificate_key /etc/letsencrypt/live/<%= @domain %>/privkey.pem;
|
47
|
+
ssl_certificate /etc/letsencrypt/live/<%= @config.domain %>/fullchain.pem;
|
48
|
+
ssl_certificate_key /etc/letsencrypt/live/<%= @config.domain %>/privkey.pem;
|
49
49
|
|
50
|
-
location /home/deploy/apps/<%= app_name %>/public/.well-known {
|
50
|
+
location /home/deploy/apps/<%= @config.app_name %>/public/.well-known {
|
51
51
|
allow all;
|
52
52
|
}
|
53
53
|
}
|
@@ -55,18 +55,18 @@ server {
|
|
55
55
|
|
56
56
|
server {
|
57
57
|
listen 80;
|
58
|
-
server_name <%= @domains.join(' ') %>;
|
59
|
-
return 301 https://<%= @domain %>$request_uri;
|
58
|
+
server_name <%= @config.domains.join(' ') %>;
|
59
|
+
return 301 https://<%= @config.domain %>$request_uri;
|
60
60
|
}
|
61
61
|
|
62
|
-
<% if @www_domain %>
|
62
|
+
<% if @config.www_domain %>
|
63
63
|
server {
|
64
64
|
listen 443 ssl;
|
65
|
-
server_name <%= @www_domain %>;
|
66
|
-
return 301 $scheme://<%= @domain %>$request_uri;
|
65
|
+
server_name <%= @config.www_domain %>;
|
66
|
+
return 301 $scheme://<%= @config.domain %>$request_uri;
|
67
67
|
|
68
68
|
# Let's Encrypt certificates
|
69
|
-
ssl_certificate /etc/letsencrypt/live/<%= @domain %>/fullchain.pem;
|
70
|
-
ssl_certificate_key /etc/letsencrypt/live/<%= @domain %>/privkey.pem;
|
69
|
+
ssl_certificate /etc/letsencrypt/live/<%= @config.domain %>/fullchain.pem;
|
70
|
+
ssl_certificate_key /etc/letsencrypt/live/<%= @config.domain %>/privkey.pem;
|
71
71
|
}
|
72
72
|
<% end %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Jancev
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- exe/railman
|
158
158
|
- lib/railman.rb
|
159
159
|
- lib/railman/cli.rb
|
160
|
+
- lib/railman/config.rb
|
160
161
|
- lib/railman/secret.rb
|
161
162
|
- lib/railman/version.rb
|
162
163
|
- railman.gemspec
|
@@ -205,7 +206,7 @@ files:
|
|
205
206
|
- templates/rails_app/config/deploy/production.rb.tt
|
206
207
|
- templates/rails_app/config/environment.rb
|
207
208
|
- templates/rails_app/config/environments/development.rb
|
208
|
-
- templates/rails_app/config/environments/production.rb
|
209
|
+
- templates/rails_app/config/environments/production.rb.tt
|
209
210
|
- templates/rails_app/config/environments/test.rb
|
210
211
|
- templates/rails_app/config/initializers/assets.rb
|
211
212
|
- templates/rails_app/config/initializers/backtrace_silencers.rb
|