underglow 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/lib/underglow/capistrano/helpers.rb +24 -21
- data/lib/underglow/capistrano/tasks/deploy.rake +11 -0
- data/lib/underglow/capistrano/tasks/rails.rake +73 -0
- data/lib/underglow/capistrano/tasks/unicorn.rake +18 -0
- data/lib/underglow/capistrano.rb +6 -5
- data/lib/underglow/version.rb +1 -1
- data/underglow.gemspec +11 -7
- metadata +33 -7
- data/lib/underglow/capistrano/deploy/db.rb +0 -8
- data/lib/underglow/capistrano/deploy/rails.rb +0 -20
- data/lib/underglow/capistrano/deploy/rake.rb +0 -33
- data/lib/underglow/capistrano/deploy/unicorn.rb +0 -16
- data/lib/underglow/capistrano/deploy.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9afa7d76bccc5002516cd987bdd8848e4ce28ea
|
4
|
+
data.tar.gz: 99e8c83643c201af223cc4c4fa51d3ceffa65b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cab59c67f916a5372c0e98189e1be02c673285ab9862dfe66b148c3118468337037335e0d06048275568f19bf3e3f0a8a9f92fa3d5f63dddb172c8b9df91908
|
7
|
+
data.tar.gz: f39009518c54ce2f8581b205731d290712cfc0f11d5ce99f6a173749a866dac90d6e2aa2f7fa3d00e7abba130629f478ccc526aacacb8a83399d32b387156ab1
|
data/Gemfile
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
gem 'activesupport'
|
4
|
+
gem 'capistrano-rails', '>= 1.0.0'
|
5
|
+
|
5
6
|
group :development do
|
6
7
|
gem "rspec", "~> 2.8.0"
|
7
8
|
gem "bundler"
|
@@ -1,26 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
after "multistage:ensure" do
|
4
|
-
set :rails_env, stage
|
5
|
-
end
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
6
3
|
|
7
|
-
|
8
|
-
def run_remote(command)
|
9
|
-
exec "ssh #{stage} -t 'source ~/.profile && #{command}'"
|
10
|
-
end
|
4
|
+
require 'pry'
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
6
|
+
def remote_file_exists?(path)
|
7
|
+
test("[ -e #{command.options[:in]}/#{path} ]")
|
8
|
+
end
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
10
|
+
def capture_remote_file(path)
|
11
|
+
return unless remote_file_exists?(path)
|
20
12
|
|
21
|
-
|
22
|
-
def kill(process, signal)
|
23
|
-
pidfile_path = "#{shared_path}/pids/#{process}.pid"
|
24
|
-
run "if [ -e #{pidfile_path} ]; then kill -#{signal} `cat #{pidfile_path}` > /dev/null 2>&1; fi"
|
25
|
-
end
|
13
|
+
capture(:cat, path).strip
|
26
14
|
end
|
15
|
+
|
16
|
+
# SSH with pseudo-tty
|
17
|
+
def execute_with_tty(*args)
|
18
|
+
exec "ssh #{host.user}@#{host.hostname} -t '#{command(*args).to_command}'"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Sends kill signal to process is running
|
22
|
+
def kill_process(process, signal)
|
23
|
+
within "#{shared_path}/pids" do
|
24
|
+
pid = capture_remote_file("#{process}.pid")
|
25
|
+
# binding.pry
|
26
|
+
|
27
|
+
execute :kill, "-#{signal}", pid unless pid.blank?
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
namespace :rails do
|
2
|
+
desc "Run rails console"
|
3
|
+
task console: :'deploy:set_rails_env' do
|
4
|
+
on roles(:app) do
|
5
|
+
within current_path do
|
6
|
+
with rails_env: fetch(:rails_env) do
|
7
|
+
execute_with_tty "bin/rails", "c"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
task c: :console
|
14
|
+
|
15
|
+
# Ex: cap production rake:invoke TASK=db:migrate TRACE=true ENV=FOO=bar,BAZ=boo"
|
16
|
+
desc "Run rails rake task"
|
17
|
+
task rake: :'deploy:set_rails_env' do
|
18
|
+
on roles(:app) do
|
19
|
+
within current_path do
|
20
|
+
with rails_env: fetch(:rails_env) do
|
21
|
+
# Build environment variables that we need
|
22
|
+
# to pass in
|
23
|
+
env = (ENV.delete('ENV') || "")
|
24
|
+
env_hash = env.split(',').each_with_object({}) do |pair, hash|
|
25
|
+
key, value = pair.split('=')
|
26
|
+
|
27
|
+
hash[key.downcase.to_sym] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
with env_hash do
|
31
|
+
args = ["bin/rake", ENV['TASK']]
|
32
|
+
args << "--trace" if ENV['TRACE']
|
33
|
+
|
34
|
+
execute(*args)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Run rails runner"
|
42
|
+
task runner: 'deploy:set_rails_env' do
|
43
|
+
on roles(:app) do
|
44
|
+
within current_path do
|
45
|
+
with rails_env: fetch(:rails_env) do
|
46
|
+
execute "bin/rails", "runner", ENV['FILE']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "View rails log"
|
53
|
+
task log: 'deploy:set_rails_env' do
|
54
|
+
on roles(:app) do
|
55
|
+
within current_path do
|
56
|
+
with rails_env: fetch(:rails_env) do
|
57
|
+
execute_with_tty "vi", "log/#{fetch(:stage)}.log"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "Tail rails log"
|
64
|
+
task tail: 'deploy:set_rails_env' do
|
65
|
+
on roles(:app) do
|
66
|
+
within current_path do
|
67
|
+
with rails_env: fetch(:rails_env) do
|
68
|
+
execute "tail", "-f", "log/#{fetch(:stage)}.log"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :unicorn do
|
2
|
+
# Sends a USR2 signal to master unicorn to spawn a new master (based on the updated codebase)
|
3
|
+
# When new master spawns new workers, the old master process is killed
|
4
|
+
# This allows for zero downtime
|
5
|
+
desc "Restarts Unicorn gracefully to serve updated code"
|
6
|
+
task :restart do
|
7
|
+
on roles(:web) do
|
8
|
+
kill_process "unicorn", "USR2"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Kill Unicorn"
|
13
|
+
task :reset do
|
14
|
+
on roles(:web) do
|
15
|
+
kill_process "unicorn", "SIGTERM"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/underglow/capistrano.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# First require capistrano helpers
|
1
2
|
require 'underglow/capistrano/helpers'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
|
4
|
+
# Load all capistrano tasks
|
5
|
+
Dir.glob(File.expand_path("../capistrano/tasks/*.rake", __FILE__)).each do |task|
|
6
|
+
load task
|
7
|
+
end
|
data/lib/underglow/version.rb
CHANGED
data/underglow.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "underglow"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Hu"]
|
12
|
-
s.date = "2014-
|
12
|
+
s.date = "2014-12-01"
|
13
13
|
s.description = "A library that makes life easier."
|
14
14
|
s.email = "axsuul@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,12 +25,10 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"lib/underglow.rb",
|
27
27
|
"lib/underglow/capistrano.rb",
|
28
|
-
"lib/underglow/capistrano/deploy.rb",
|
29
|
-
"lib/underglow/capistrano/deploy/db.rb",
|
30
|
-
"lib/underglow/capistrano/deploy/rails.rb",
|
31
|
-
"lib/underglow/capistrano/deploy/rake.rb",
|
32
|
-
"lib/underglow/capistrano/deploy/unicorn.rb",
|
33
28
|
"lib/underglow/capistrano/helpers.rb",
|
29
|
+
"lib/underglow/capistrano/tasks/deploy.rake",
|
30
|
+
"lib/underglow/capistrano/tasks/rails.rake",
|
31
|
+
"lib/underglow/capistrano/tasks/unicorn.rake",
|
34
32
|
"lib/underglow/extensions/array.rb",
|
35
33
|
"lib/underglow/extensions/string.rb",
|
36
34
|
"lib/underglow/extensions/symbol.rb",
|
@@ -56,17 +54,23 @@ Gem::Specification.new do |s|
|
|
56
54
|
s.specification_version = 4
|
57
55
|
|
58
56
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
58
|
+
s.add_runtime_dependency(%q<capistrano-rails>, [">= 1.0.0"])
|
59
59
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
60
60
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
61
61
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.8"])
|
62
62
|
s.add_development_dependency(%q<pry>, [">= 0"])
|
63
63
|
else
|
64
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
65
|
+
s.add_dependency(%q<capistrano-rails>, [">= 1.0.0"])
|
64
66
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
65
67
|
s.add_dependency(%q<bundler>, [">= 0"])
|
66
68
|
s.add_dependency(%q<jeweler>, ["~> 1.8.8"])
|
67
69
|
s.add_dependency(%q<pry>, [">= 0"])
|
68
70
|
end
|
69
71
|
else
|
72
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
73
|
+
s.add_dependency(%q<capistrano-rails>, [">= 1.0.0"])
|
70
74
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
71
75
|
s.add_dependency(%q<bundler>, [">= 0"])
|
72
76
|
s.add_dependency(%q<jeweler>, ["~> 1.8.8"])
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: underglow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Hu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capistrano-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rspec
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,12 +110,10 @@ files:
|
|
82
110
|
- Rakefile
|
83
111
|
- lib/underglow.rb
|
84
112
|
- lib/underglow/capistrano.rb
|
85
|
-
- lib/underglow/capistrano/deploy.rb
|
86
|
-
- lib/underglow/capistrano/deploy/db.rb
|
87
|
-
- lib/underglow/capistrano/deploy/rails.rb
|
88
|
-
- lib/underglow/capistrano/deploy/rake.rb
|
89
|
-
- lib/underglow/capistrano/deploy/unicorn.rb
|
90
113
|
- lib/underglow/capistrano/helpers.rb
|
114
|
+
- lib/underglow/capistrano/tasks/deploy.rake
|
115
|
+
- lib/underglow/capistrano/tasks/rails.rake
|
116
|
+
- lib/underglow/capistrano/tasks/unicorn.rake
|
91
117
|
- lib/underglow/extensions/array.rb
|
92
118
|
- lib/underglow/extensions/string.rb
|
93
119
|
- lib/underglow/extensions/symbol.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
Capistrano::Configuration.instance.load do
|
2
|
-
namespace :rails do
|
3
|
-
desc "Run rails console"
|
4
|
-
task :console, roles: :app do
|
5
|
-
run_remote "cd #{current_path} && #{deploy_to}/environment bin/rails c"
|
6
|
-
end
|
7
|
-
|
8
|
-
desc "View rails log"
|
9
|
-
task :log, roles: :app do
|
10
|
-
run_remote "cd #{current_path} && vi log/#{stage}.log"
|
11
|
-
end
|
12
|
-
|
13
|
-
desc "Tail rails log"
|
14
|
-
task :tail, roles: :app do
|
15
|
-
run_remote "cd #{current_path} && tail -f log/#{stage}.log"
|
16
|
-
end
|
17
|
-
|
18
|
-
alias_task :c, :console
|
19
|
-
end
|
20
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
Capistrano::Configuration.instance.load do
|
2
|
-
# So we can use rake within commands
|
3
|
-
after "multistage:ensure" do
|
4
|
-
set :rake_command, "RAILS_ENV=#{stage} #{current_path}/bin/rake -f #{current_path}/Rakefile"
|
5
|
-
end
|
6
|
-
|
7
|
-
before "deploy:update_code" do
|
8
|
-
# We are about to update code, so we need to use release path because the current path will be the old code
|
9
|
-
set :rake_command, "RAILS_ENV=#{stage} #{release_path}/bin/rake -f #{release_path}/Rakefile"
|
10
|
-
end
|
11
|
-
|
12
|
-
namespace :rake do
|
13
|
-
# Note: do not name this task to "run"
|
14
|
-
desc "Invoke a rake task, ex: cap production rake:invoke TASK=db:migrate TRACE=true ENV=FOO=BAR,BAZ=BOO"
|
15
|
-
task :invoke do
|
16
|
-
arguments = []
|
17
|
-
|
18
|
-
# Extract special environment variables
|
19
|
-
trace = ENV.delete('TRACE')
|
20
|
-
task = ENV.delete('TASK')
|
21
|
-
env = ENV.delete('ENV')
|
22
|
-
|
23
|
-
# Build arguments list
|
24
|
-
arguments << "--trace" if trace
|
25
|
-
arguments_command = arguments.join(' ')
|
26
|
-
|
27
|
-
# Build environment variables to pass in
|
28
|
-
env_command = env.split(',').join(' ') if env
|
29
|
-
|
30
|
-
run "#{env_command} #{rake_command} #{task} #{arguments_command}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
Capistrano::Configuration.instance.load do
|
2
|
-
namespace :unicorn do
|
3
|
-
# Sends a USR2 signal to master unicorn to spawn a new master (based on the updated codebase)
|
4
|
-
# When new master spawns new workers, the old master process is killed
|
5
|
-
# This allows for zero downtime
|
6
|
-
desc "Restarts Unicorn gracefully to serve updated code"
|
7
|
-
task :restart, roles: :web do
|
8
|
-
kill "unicorn", "USR2"
|
9
|
-
end
|
10
|
-
|
11
|
-
desc "Kill Unicorn"
|
12
|
-
task :reset, roles: :web do
|
13
|
-
kill "unicorn", "SIGTERM"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
Capistrano::Configuration.instance.load do
|
2
|
-
# this task gets called last by capistrano when required to restart stuff
|
3
|
-
namespace :deploy do
|
4
|
-
# Custom web enable/disable tasks by simply added active suffix to maintenance page
|
5
|
-
namespace :web do
|
6
|
-
desc "Present a maintenance page to visitors."
|
7
|
-
task :disable do
|
8
|
-
require 'haml'
|
9
|
-
on_rollback { run "rm #{shared_path}/system/maintenance.html" }
|
10
|
-
|
11
|
-
reason = ENV['REASON']
|
12
|
-
deadline = ENV['UNTIL']
|
13
|
-
template = File.read('app/views/layouts/maintenance.html.haml')
|
14
|
-
html = Haml::Engine.new(template).render(binding)
|
15
|
-
|
16
|
-
put html, "#{shared_path}/system/maintenance.html", mode: 0644
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
namespace :assets do
|
21
|
-
desc "Precompile assets only if they haven't changed"
|
22
|
-
task :precompile, roles: :web, except: { no_release: true } do
|
23
|
-
# if there's no current revision, then this is the first deploy, then we must precompile regardless
|
24
|
-
# otherwise, only precompile if assets have changed
|
25
|
-
if !remote_file_exists?("#{current_path}/REVISION") or capture("cd #{release_path} && #{source.local.log(source.next_revision(current_revision))} vendor/assets/ app/assets/ | wc -l").to_i > 0
|
26
|
-
run %Q{cd #{release_path} && #{rake_command} RAILS_ENV=#{stage} #{asset_env} assets:precompile}
|
27
|
-
else
|
28
|
-
logger.info "Skipping asset pre-compilation because there were no asset changes"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Give executable permissions to binstubs
|
35
|
-
after "bundle:install" do
|
36
|
-
run "chmod 775 -R #{release_path}/bin"
|
37
|
-
end
|
38
|
-
end
|