masshtab_dev_tools 0.0.1
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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/lib/generators/masshtab/deploy/USAGE +2 -0
- data/lib/generators/masshtab/deploy/deploy_generator.rb +26 -0
- data/lib/generators/masshtab/deploy/templates/Capfile +4 -0
- data/lib/generators/masshtab/deploy/templates/deploy.rb +121 -0
- data/lib/generators/masshtab/deploy/templates/unicorn.rb +38 -0
- data/lib/masshtab_dev_tools/version.rb +3 -0
- data/lib/masshtab_dev_tools.rb +5 -0
- data/masshtab_dev_tools.gemspec +25 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTRkNDRiYmNhOWU5MjNmZDMwYmZiZTBjNzliMGM4ZWQ1MThmZjYzYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWRjMmU0ZTQwMzNhMDE0OGNhNjQxZmYwY2E4M2E3MWY1ODIzYzY3Mw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
M2IyZGI2NGQxNDdjMjUxNTRhMTg5MzYwOTdhNzQwNThjYjQxODk3MDY2Zjcx
|
10
|
+
MGQ0YTk1MGQxOTkzMmViZDJhODc3ZTViNmVmZWQ2M2NhZDI0MDg1ZTQ2NjAx
|
11
|
+
YmU1ZThkZGRhMDdhNDU2MWFmYjk0ZjYxZTk2NzRlYzVjZDIwYzU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjFiOTViOThkMmU2NjVmYmUwNTFjYTBiMGFlYWE5OTlmMzYyZmU2NDliZjk3
|
14
|
+
ZTE0MzhkOWRkOGNkMWE1ZjE0MGUxNWVjOWNiODUwY2RkYTlmMGNmYTZmNDdh
|
15
|
+
ZWQ0ZTcxMjFkMGQ4MjgyZTkzY2JmZmE1NTEyMmViMjYwNjU5OTE=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sergey Kucher
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# MasshtabDevTools
|
2
|
+
|
3
|
+
Tools for specific company tasks.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'masshtab_dev_tools', group: :development
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install masshtab_dev_tools
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Deployment tool
|
22
|
+
|
23
|
+
From project folder:
|
24
|
+
|
25
|
+
rails generate masshtab:deploy USER_NAME SERVER_NAME [options]
|
26
|
+
|
27
|
+
Options:
|
28
|
+
[--repository=REPOSITORY] # Full address of the git repository. If empty server name and application name will be used
|
29
|
+
[--branch=BRANCH] # Branch name to deploy from
|
30
|
+
# Default: master
|
31
|
+
[--application-name=APPLICATION_NAME] # Name of rails application
|
32
|
+
# Default: simple_site
|
33
|
+
|
34
|
+
Runtime options:
|
35
|
+
-f, [--force] # Overwrite files that already exist
|
36
|
+
-p, [--pretend] # Run but do not make any changes
|
37
|
+
-q, [--quiet] # Suppress status output
|
38
|
+
-s, [--skip] # Skip files that already exist
|
39
|
+
|
40
|
+
For example:
|
41
|
+
rails g masshtab:deploy alex example.com
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Masshtab
|
2
|
+
class DeployGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
argument :user_name, type: :string, desc: 'Name of an user who has access to the project'
|
6
|
+
argument :server_name, type: :string, desc: 'Name or IP-address of the server'
|
7
|
+
|
8
|
+
class_option :repository, type: :string, desc: 'Full address of the git repository. If empty server name and application name will be used'
|
9
|
+
class_option :branch, type: :string, default: 'master', desc: 'Branch name to deploy from'
|
10
|
+
|
11
|
+
application_name = Rails.application.class.parent_name.underscore
|
12
|
+
class_option :application_name, type: :string, default: application_name, desc: 'Name of rails application'
|
13
|
+
|
14
|
+
def add_gems
|
15
|
+
gem 'unicorn'
|
16
|
+
gem 'capistrano'
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_files
|
20
|
+
template 'Capfile', Rails.root.join('Capfile')
|
21
|
+
template 'unicorn.rb', Rails.root.join('config', 'unicorn.rb')
|
22
|
+
template 'deploy.rb', Rails.root.join('config', 'deploy.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# cap deploy:setup
|
2
|
+
# cap deploy
|
3
|
+
# cap db:seed (on first deploy)
|
4
|
+
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
|
5
|
+
|
6
|
+
require 'bundler/capistrano'
|
7
|
+
|
8
|
+
# Uncomment this if you are using Thinking Sphinx
|
9
|
+
#require 'thinking_sphinx/deploy/capistrano'
|
10
|
+
|
11
|
+
# Uncomment this if you are using Whenever
|
12
|
+
#set :whenever_command, "bundle exec whenever"
|
13
|
+
#require "whenever/capistrano"
|
14
|
+
|
15
|
+
<% application_name = options.application_name %>
|
16
|
+
set :application, '<%= application_name %>'
|
17
|
+
set :domain, '<%= application_name %>@<%= server_name %>'
|
18
|
+
set :repository, '<%= options.repository || "git@#{server_name}:#{application_name}.git" %>'
|
19
|
+
set :scm, :git
|
20
|
+
set :deploy_via, :remote_cache
|
21
|
+
set :branch, :<%= options.branch %>
|
22
|
+
set :scm_username, '<%= user_name %>'
|
23
|
+
set :scm_verbose, true
|
24
|
+
set :user, '<%= application_name %>'
|
25
|
+
set :use_sudo, false
|
26
|
+
|
27
|
+
ssh_options[:forward_agent] = true
|
28
|
+
default_run_options[:pty] = false
|
29
|
+
|
30
|
+
set :keep_releases, 3
|
31
|
+
set :deploy_to, "/home/#{user}/htdocs"
|
32
|
+
set :rails_env, "production"
|
33
|
+
|
34
|
+
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
|
35
|
+
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
|
36
|
+
|
37
|
+
role :web, domain
|
38
|
+
role :app, domain
|
39
|
+
role :db, domain, :primary => true
|
40
|
+
|
41
|
+
set(:database_username, "<%= application_name %>")
|
42
|
+
set(:development_database) { application + "_development" }
|
43
|
+
set(:test_database) { application + "_test" }
|
44
|
+
set(:production_database) { application }
|
45
|
+
|
46
|
+
namespace :deploy do
|
47
|
+
task :restart do
|
48
|
+
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn_rails -c #{unicorn_conf} -E #{rails_env} -D; fi"
|
49
|
+
end
|
50
|
+
|
51
|
+
task :start do
|
52
|
+
run "bundle exec unicorn_rails -c #{unicorn_conf} -E #{rails_env} -D"
|
53
|
+
end
|
54
|
+
|
55
|
+
task :stop do
|
56
|
+
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Precache assets'
|
60
|
+
task :precache_assets, :roles => :app do
|
61
|
+
run "cd #{current_release} && bundle exec rake assets:precompile RAILS_ENV=production"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
namespace :db do
|
66
|
+
desc "Populates the Production Database"
|
67
|
+
task :seed do
|
68
|
+
puts "\n\n=== Populating the Production Database! ===\n\n"
|
69
|
+
run "cd #{current_path} && bundle exec rake db:seed RAILS_ENV=production"
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "Create database yaml in shared path"
|
73
|
+
task :configure do
|
74
|
+
set :database_password do
|
75
|
+
Capistrano::CLI.password_prompt "Database Password: "
|
76
|
+
end
|
77
|
+
|
78
|
+
db_config = <<-EOF
|
79
|
+
base: &base
|
80
|
+
adapter: mysql2
|
81
|
+
encoding: utf8
|
82
|
+
username: #{database_username}
|
83
|
+
password: #{database_password}
|
84
|
+
|
85
|
+
development:
|
86
|
+
database: #{development_database}
|
87
|
+
<<: *base
|
88
|
+
|
89
|
+
test:
|
90
|
+
database: #{test_database}
|
91
|
+
<<: *base
|
92
|
+
|
93
|
+
production:
|
94
|
+
database: #{production_database}
|
95
|
+
<<: *base
|
96
|
+
EOF
|
97
|
+
|
98
|
+
run "mkdir -p #{shared_path}/config"
|
99
|
+
put db_config, "#{shared_path}/config/database.yml"
|
100
|
+
end
|
101
|
+
|
102
|
+
desc "Make symlink for database yaml"
|
103
|
+
task :symlink do
|
104
|
+
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Uncomment this if you are using Thinking Sphinx
|
109
|
+
#after 'deploy:migrate', :roles => [:app] do
|
110
|
+
# thinking_sphinx.stop
|
111
|
+
# run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx"
|
112
|
+
# thinking_sphinx.configure
|
113
|
+
# thinking_sphinx.start
|
114
|
+
#end
|
115
|
+
|
116
|
+
before "deploy:setup", "db:configure"
|
117
|
+
before "bundle:install", "db:symlink"
|
118
|
+
after "bundle:install", "deploy:migrate"
|
119
|
+
after "deploy:migrate", "deploy:precache_assets"
|
120
|
+
|
121
|
+
require './config/boot'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
deploy_to = "/home/<%= options.application_name %>/htdocs"
|
2
|
+
rails_root = "#{deploy_to}/current"
|
3
|
+
pid_file = "#{deploy_to}/shared/pids/unicorn.pid"
|
4
|
+
socket_file = "#{deploy_to}/shared/sockets/unicorn.sock"
|
5
|
+
log_file = "#{rails_root}/log/unicorn.log"
|
6
|
+
err_log = "#{rails_root}/log/unicorn_error.log"
|
7
|
+
old_pid = pid_file + '.oldbin'
|
8
|
+
|
9
|
+
timeout 30
|
10
|
+
worker_processes 2
|
11
|
+
listen socket_file, :backlog => 1024
|
12
|
+
pid pid_file
|
13
|
+
stderr_path err_log
|
14
|
+
stdout_path log_file
|
15
|
+
preload_app true
|
16
|
+
|
17
|
+
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
|
18
|
+
|
19
|
+
before_exec do |server|
|
20
|
+
ENV["BUNDLE_GEMFILE"] = "#{rails_root}/Gemfile"
|
21
|
+
end
|
22
|
+
|
23
|
+
before_fork do |server, worker|
|
24
|
+
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
|
25
|
+
|
26
|
+
if File.exists?(old_pid) && server.pid != old_pid
|
27
|
+
begin
|
28
|
+
Process.kill("QUIT", File.read(old_pid).to_i)
|
29
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
30
|
+
# someone else did our job for us
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
after_fork do |server, worker|
|
36
|
+
defined?(ActiveRecord::Base) and
|
37
|
+
ActiveRecord::Base.establish_connection
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'masshtab_dev_tools/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "masshtab_dev_tools"
|
8
|
+
spec.version = MasshtabDevTools::VERSION
|
9
|
+
spec.authors = ["Sergey Kucher"]
|
10
|
+
spec.email = ["s.e.kucher@gmail.com"]
|
11
|
+
spec.description = 'Some useful development tools to masshtab company'
|
12
|
+
spec.summary = "- rails deployment generator"
|
13
|
+
spec.homepage = "https://github.com/sergey-kucher/masshtab_dev_tools"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", "~> 3.2.13"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: masshtab_dev_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Kucher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.13
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.13
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Some useful development tools to masshtab company
|
56
|
+
email:
|
57
|
+
- s.e.kucher@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/generators/masshtab/deploy/USAGE
|
68
|
+
- lib/generators/masshtab/deploy/deploy_generator.rb
|
69
|
+
- lib/generators/masshtab/deploy/templates/Capfile
|
70
|
+
- lib/generators/masshtab/deploy/templates/deploy.rb
|
71
|
+
- lib/generators/masshtab/deploy/templates/unicorn.rb
|
72
|
+
- lib/masshtab_dev_tools.rb
|
73
|
+
- lib/masshtab_dev_tools/version.rb
|
74
|
+
- masshtab_dev_tools.gemspec
|
75
|
+
homepage: https://github.com/sergey-kucher/masshtab_dev_tools
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.3
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: ! '- rails deployment generator'
|
99
|
+
test_files: []
|
100
|
+
has_rdoc:
|