capistrano-deploylock 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/capistrano-deploylock.gemspec +26 -0
- data/lib/capistrano/deploylock/version.rb +5 -0
- data/lib/capistrano/deploylock.rb +113 -0
- data/lib/capistrano/templates/deploy_lock.yml.erb +2 -0
- data/test/minitest_helper.rb +5 -0
- data/test/test_capistrano/deploylock.rb +12 -0
- data/test/test_capistrano.rb +6 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 474b17aedc4324ccbd1bed26e6ca008b1c4cba95
|
4
|
+
data.tar.gz: 34aafe9acf3e96b5e490846ee02ede7061df93b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9df8766664d48d0af8b24b397c4f98d4573cbf7ae070905a1daf249d87c655e5dccbaa69480cbca22cb01d8c765e0bbd1da05014ae9b26b6e917f7a0b3e90d26
|
7
|
+
data.tar.gz: ac65b3cfea63459f742b77b7bcd3c10ab84643b7bc2967f12db44e17633b6d01aa1967f145fa55bb729a7ec158f4dd45bdbaf43f835949f04ab120c5a7714ee8
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 tetuyoko
|
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,38 @@
|
|
1
|
+
# Capistrano::Deploylock
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'capistrano-deploylock'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install capistrano-deploylock
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
add config/deploy.rb
|
24
|
+
|
25
|
+
require 'capistrano/deploylock'
|
26
|
+
|
27
|
+
~~~
|
28
|
+
before "deploy:lock:start", "deploy:lock:check"
|
29
|
+
before "deploy", "deploy:lock:start"
|
30
|
+
~~~
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/[my-github-username]/capistrano-deploylock/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/deploylock/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano-deploylock"
|
8
|
+
spec.version = Capistrano::Deploylock::VERSION
|
9
|
+
spec.authors = ["tetuyoko"]
|
10
|
+
spec.email = ["tyokoyama53@gmail.com"]
|
11
|
+
spec.summary = %q{capistrano deploy lock}
|
12
|
+
spec.description = %q{capistrano deploy lock}
|
13
|
+
spec.homepage = "https://github.com/tetuyoko/developmentkit"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
|
25
|
+
spec.add_dependency "capistrano", '>= 2', '< 3'
|
26
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require "capistrano/deploylock/version"
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
module Capistrano::Deploylock
|
5
|
+
|
6
|
+
def self.load_into(configuration)
|
7
|
+
configuration.load do
|
8
|
+
_cset :deploy_lock_basename, "deploy_lock"
|
9
|
+
_cset(:deploy_lock_dirname) { "#{shared_path}/system" }
|
10
|
+
_cset(:deploy_lock_template_path) { File.join(File.dirname(__FILE__), "templates", "deploy_lock.yml") }
|
11
|
+
_cset(:deploy_lock_remote_path) { "#{deploy_lock_dirname}/#{deploy_lock_basename}.yml" }
|
12
|
+
_cset(:deploy_lock_remote_log_path) {"#{deploy_lock_dirname}/#{deploy_lock_basename}.log" }
|
13
|
+
_cset(:deploy_lock_file_local_path) {"./public/system/#{deploy_lock_basename}.yml" }
|
14
|
+
|
15
|
+
def remote_file_exists?(full_path)
|
16
|
+
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
17
|
+
end
|
18
|
+
|
19
|
+
def lock_force_end(with_log=false)
|
20
|
+
if remote_file_exists?(deploy_lock_remote_path)
|
21
|
+
puts '[SKIP] ロックファイルを削除します'
|
22
|
+
lock_end_log if with_log
|
23
|
+
run "rm -f #{deploy_lock_remote_path}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def lock_start_log
|
28
|
+
run "echo [started], #{Time.now}, #{git_config_user_name} >> #{deploy_lock_remote_log_path}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def lock_end_log
|
32
|
+
run "echo [ended], #{Time.now}, #{git_config_user_name} >> #{deploy_lock_remote_log_path}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def git_config_user_name
|
36
|
+
`git config --get user.name`
|
37
|
+
end
|
38
|
+
|
39
|
+
namespace :deploy do
|
40
|
+
namespace :lock do
|
41
|
+
desc 'デプロイロックを確認する'
|
42
|
+
task :start, roles: :web do
|
43
|
+
on_rollback { run "rm -f #{deploy_lock_remote_path}" }
|
44
|
+
require 'erb'
|
45
|
+
puts "\n**** [DEPLOY LOCK] ****"
|
46
|
+
puts "24時間後まであなたの名前を元に他人のデプロイをロックします。"
|
47
|
+
puts "この操作は下記のコマンドで取り消しできます。"
|
48
|
+
puts "bundle exedc cap $STAGENAME deploy:lock:end"
|
49
|
+
|
50
|
+
day = 1
|
51
|
+
expired_at = Time.now + (day * (60 * 60 * 24))
|
52
|
+
|
53
|
+
user = `users`.chomp
|
54
|
+
puts "\n**** [LOCKED] #{rails_env}はロックされ、有効期限内が設定されました. **** "
|
55
|
+
puts "\n locked_user : #{user}"
|
56
|
+
puts " expired_at : #{expired_at}\n\n"
|
57
|
+
|
58
|
+
erb = ERB.new(File.read("#{deploy_lock_template_path}.erb")).result(binding)
|
59
|
+
put erb, "#{deploy_lock_remote_path}", mode: 0644
|
60
|
+
lock_start_log
|
61
|
+
end
|
62
|
+
|
63
|
+
desc 'デプロイロックを確認する'
|
64
|
+
task :end, roles: :web do
|
65
|
+
lock_force_end(true)
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'デプロイロックを確認する'
|
69
|
+
task :check, roles: :web do
|
70
|
+
unless remote_file_exists?(deploy_lock_remote_path)
|
71
|
+
puts '[SKIP] ロックファイルがありません.'
|
72
|
+
next
|
73
|
+
end
|
74
|
+
|
75
|
+
FileUtils.rm deploy_lock_file_local_path, force: true
|
76
|
+
FileUtils.mkdir_p './public/system'
|
77
|
+
|
78
|
+
get deploy_lock_remote_path, deploy_lock_file_local_path
|
79
|
+
lock = YAML.load_file deploy_lock_file_local_path
|
80
|
+
|
81
|
+
if Time.now > lock["expired_at"]
|
82
|
+
puts '[SKIP] ロックファイルの設定期限が過ぎています.'
|
83
|
+
lock_force_end(false)
|
84
|
+
next
|
85
|
+
end
|
86
|
+
|
87
|
+
current_user = git_config_user_name.chomp
|
88
|
+
if lock["user"] == current_user
|
89
|
+
puts '[SKIP] あなたのロックファイルです.'
|
90
|
+
next
|
91
|
+
end
|
92
|
+
|
93
|
+
puts "\n**** [LOCKED] #{rails_env}はロックされ、有効期限内です. **** "
|
94
|
+
puts "\n locked_user : #{lock["user"]}"
|
95
|
+
puts " expired_at : #{lock["expired_at"]}\n\n"
|
96
|
+
|
97
|
+
puts "ロックは下記のコマンドで取り消しできます。"
|
98
|
+
puts "bundle exedc cap $STAGENAME deploy:lock:end"
|
99
|
+
|
100
|
+
FileUtils.rm './public/system/deploy_lock.yml', force: true
|
101
|
+
run "hostname; exit 1"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
if Capistrano::Configuration.instance
|
112
|
+
Capistrano::Deploylock.load_into(Capistrano::Configuration.instance)
|
113
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
class TestCapistrano::Deploylock < MiniTest::Unit::TestCase
|
4
|
+
def test_that_it_has_a_version_number
|
5
|
+
refute_nil ::Capistrano::Deploylock::VERSION
|
6
|
+
assert !defined?(Thin)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_it_does_something_useful
|
10
|
+
assert true
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-deploylock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tetuyoko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capistrano
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '2'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3'
|
75
|
+
description: capistrano deploy lock
|
76
|
+
email:
|
77
|
+
- tyokoyama53@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".travis.yml"
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- capistrano-deploylock.gemspec
|
89
|
+
- lib/capistrano/deploylock.rb
|
90
|
+
- lib/capistrano/deploylock/version.rb
|
91
|
+
- lib/capistrano/templates/deploy_lock.yml.erb
|
92
|
+
- test/minitest_helper.rb
|
93
|
+
- test/test_capistrano.rb
|
94
|
+
- test/test_capistrano/deploylock.rb
|
95
|
+
homepage: https://github.com/tetuyoko/developmentkit
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.4.4
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: capistrano deploy lock
|
119
|
+
test_files:
|
120
|
+
- test/minitest_helper.rb
|
121
|
+
- test/test_capistrano.rb
|
122
|
+
- test/test_capistrano/deploylock.rb
|
123
|
+
has_rdoc:
|