ruboty-capistrano 0.1.2 → 0.1.3
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 +4 -4
- data/Gemfile.lock +31 -2
- data/README.md +6 -4
- data/lib/ruboty/capistrano/actions/deployment.rb +51 -0
- data/lib/ruboty/capistrano/actions/rollback.rb +1 -1
- data/lib/ruboty/capistrano/config.rb +10 -4
- data/lib/ruboty/capistrano/github_repository_validators.rb +24 -0
- data/lib/ruboty/capistrano/version.rb +1 -1
- data/lib/ruboty/capistrano.rb +12 -0
- data/lib/ruboty/handlers/capistrano.rb +16 -5
- data/ruboty-capistrano.gemspec +3 -0
- metadata +46 -3
- data/lib/ruboty/capistrano/actions/deploy.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f1ecfbcec27de756e885dbcc48a1f6e1619d921
|
4
|
+
data.tar.gz: 4723bc8ba7bb77f3d04f418bc5368e2c036fa150
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e905af00a7eb9f90a4b8ecd6b59a4dbb61beb995f0787f3c4581ec9fb507969ec7d1299d84be44aca9b9cd1b71e57d14ab54ed9ac513d6e7869a63dd005ef65
|
7
|
+
data.tar.gz: 4230b3736a12505c88b0f53917f0da2f617eac21b2de5f0037b3d08f218ef712dc3529d14bbf53cec34c8293ec74023134912bd75b83dab902b9a1b1c3d5261c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruboty-capistrano (0.1.
|
4
|
+
ruboty-capistrano (0.1.3)
|
5
|
+
octokit
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -11,10 +12,26 @@ GEM
|
|
11
12
|
i18n (~> 0.7)
|
12
13
|
minitest (~> 5.1)
|
13
14
|
tzinfo (~> 1.1)
|
15
|
+
addressable (2.5.0)
|
16
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
17
|
+
coderay (1.1.1)
|
14
18
|
concurrent-ruby (1.0.2)
|
15
19
|
diff-lcs (1.2.5)
|
20
|
+
dotenv (2.1.1)
|
21
|
+
faraday (0.10.0)
|
22
|
+
multipart-post (>= 1.2, < 3)
|
16
23
|
i18n (0.7.0)
|
24
|
+
mem (0.1.5)
|
25
|
+
method_source (0.8.2)
|
17
26
|
minitest (5.9.0)
|
27
|
+
multipart-post (2.0.0)
|
28
|
+
octokit (4.6.2)
|
29
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
30
|
+
pry (0.10.4)
|
31
|
+
coderay (~> 1.1.0)
|
32
|
+
method_source (~> 0.8.1)
|
33
|
+
slop (~> 3.4)
|
34
|
+
public_suffix (2.0.4)
|
18
35
|
rake (10.5.0)
|
19
36
|
rspec (3.4.0)
|
20
37
|
rspec-core (~> 3.4.0)
|
@@ -29,6 +46,16 @@ GEM
|
|
29
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
47
|
rspec-support (~> 3.4.0)
|
31
48
|
rspec-support (3.4.1)
|
49
|
+
ruboty (1.2.4)
|
50
|
+
activesupport
|
51
|
+
bundler
|
52
|
+
dotenv
|
53
|
+
mem
|
54
|
+
slop
|
55
|
+
sawyer (0.8.1)
|
56
|
+
addressable (>= 2.3.5, < 2.6)
|
57
|
+
faraday (~> 0.8, < 1.0)
|
58
|
+
slop (3.6.0)
|
32
59
|
thread_safe (0.3.5)
|
33
60
|
tzinfo (1.2.2)
|
34
61
|
thread_safe (~> 0.1)
|
@@ -39,9 +66,11 @@ PLATFORMS
|
|
39
66
|
DEPENDENCIES
|
40
67
|
activesupport
|
41
68
|
bundler (~> 1.12)
|
69
|
+
pry
|
42
70
|
rake (~> 10.0)
|
43
71
|
rspec (~> 3.0)
|
72
|
+
ruboty
|
44
73
|
ruboty-capistrano!
|
45
74
|
|
46
75
|
BUNDLED WITH
|
47
|
-
1.
|
76
|
+
1.13.6
|
data/README.md
CHANGED
@@ -26,23 +26,25 @@ Or install it yourself as:
|
|
26
26
|
### Deploy
|
27
27
|
|
28
28
|
```
|
29
|
-
@bot_name deploy
|
29
|
+
@bot_name deploy role branch_name
|
30
30
|
```
|
31
31
|
|
32
32
|
### Rollback
|
33
33
|
|
34
34
|
```
|
35
|
-
@bot_name rollback
|
35
|
+
@bot_name rollback role
|
36
36
|
```
|
37
37
|
|
38
38
|
## Env
|
39
39
|
|
40
40
|
```
|
41
41
|
RUBOTY_ENV - deploy先の環境を指定する
|
42
|
-
|
43
|
-
DEPLOY_REPOSITORY_PATH - deploy対象のrepositoryのpath
|
42
|
+
LOCAL_REPOSITORY_PATH - deploy対象が存在しているディレクトリパス
|
44
43
|
(ex: "sample:/path/to/sample;admin:/path/to/admin")
|
45
44
|
DEPLOY_LOG_PATH - deploy時のログを残すpath
|
45
|
+
GITHUB_ACCESS_TOKEN - GitHubのアクセストークン(GitHubのAPIを用いるため)
|
46
|
+
REMOTE_REPOSITORY_PATH - deploy対象のGitHubのrepository
|
47
|
+
(ex: "sample:hoge/sample-repo;admin:hoge/admin-repo")
|
46
48
|
```
|
47
49
|
|
48
50
|
## License
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Capistrano
|
3
|
+
module Actions
|
4
|
+
class Deployment < Ruboty::Actions::Base
|
5
|
+
include Ruboty::Capistrano::GitHubRepositoryValidator
|
6
|
+
|
7
|
+
attr_reader :role, :branch, :errors
|
8
|
+
|
9
|
+
def initialize(role: , branch:)
|
10
|
+
@role = role
|
11
|
+
@branch = branch
|
12
|
+
@errors = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
return unless validates
|
17
|
+
|
18
|
+
deploy
|
19
|
+
errors.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
def message_before_deploy
|
23
|
+
"#{env}環境の#{role}にBRANCH:#{branch}をdeployします"
|
24
|
+
end
|
25
|
+
|
26
|
+
def message_after_deploy
|
27
|
+
"#{env}環境の#{role}にBRANCH:#{branch}をdeployしました"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def env
|
33
|
+
Ruboty::Capistrano.config.env
|
34
|
+
end
|
35
|
+
|
36
|
+
def repo_path
|
37
|
+
Ruboty::Capistrano.config.local_repo_path[role]
|
38
|
+
end
|
39
|
+
|
40
|
+
def deploy
|
41
|
+
cmd = "cd #{repo_path} && bundle && bundle exec cap #{env} deploy BRANCH=#{branch}"
|
42
|
+
out, err, status = Bundler.with_clean_env { Open3.capture3(cmd) }
|
43
|
+
return if err.empty?
|
44
|
+
|
45
|
+
Ruboty::Capistrano.logger err
|
46
|
+
errors << 'deploy中にエラーが発生しました'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -3,15 +3,21 @@ module Ruboty
|
|
3
3
|
class Config
|
4
4
|
include ActiveSupport::Configurable
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
config.log_path = ENV['DEPLOY_LOG_PATH']
|
9
|
-
config.repository_path = ENV['DEPLOY_REPOSITORY_PATH'].split(';').inject({}) do |hash, s|
|
6
|
+
extract = lambda do |env_str|
|
7
|
+
env_str.split(';').inject({}) do |hash, s|
|
10
8
|
key, value = s.split(":").first, s.split(":").last
|
11
9
|
hash[key] = value
|
12
10
|
hash
|
13
11
|
end
|
14
12
|
end
|
13
|
+
|
14
|
+
configure do |config|
|
15
|
+
config.env = ENV['RUBOTY_ENV']
|
16
|
+
config.github_access_token = ENV['GITHUB_ACCESS_TOKEN']
|
17
|
+
config.log_path = ENV['DEPLOY_LOG_PATH']
|
18
|
+
config.remote_repo_path = extract.call(ENV['REMOTE_REPOSITORY_PATH'])
|
19
|
+
config.local_repo_path = extract.call(ENV['LOCAL_REPOSITORY_PATH'])
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Ruboty::Capistrano
|
2
|
+
module GitHubRepositoryValidator
|
3
|
+
def self.included(klass)
|
4
|
+
raise 'wrong include error' unless klass.ancestors.include?(Ruboty::Actions::Base)
|
5
|
+
end
|
6
|
+
|
7
|
+
def validates
|
8
|
+
!!github_client.branch(repo, branch)
|
9
|
+
rescue Octokit::NotFound => e
|
10
|
+
errors << e.message
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def github_client
|
17
|
+
Octokit::Client.new(access_token: Ruboty::Capistrano.config.github_access_token)
|
18
|
+
end
|
19
|
+
|
20
|
+
def repo
|
21
|
+
Ruboty::Capistrano.config.remote_repo_path[role]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ruboty/capistrano.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require 'active_support/all'
|
3
3
|
require 'date'
|
4
|
+
require 'octokit'
|
4
5
|
require 'ruboty/capistrano/version'
|
6
|
+
require 'ruboty/capistrano/github_repository_validators'
|
5
7
|
require 'ruboty/handlers/capistrano'
|
8
|
+
require 'ruboty/capistrano/actions/deployment'
|
9
|
+
require 'ruboty/capistrano/actions/rollback'
|
6
10
|
|
7
11
|
module Ruboty
|
8
12
|
module Capistrano
|
@@ -11,5 +15,13 @@ module Ruboty
|
|
11
15
|
def self.config
|
12
16
|
@config ||= Ruboty::Capistrano::Config.config
|
13
17
|
end
|
18
|
+
|
19
|
+
def self.loggers
|
20
|
+
return STDOUT if Ruboty::Capistrano.config.log_path.to_s.empty?
|
21
|
+
return @logger if @logger
|
22
|
+
|
23
|
+
log_path = File.join(Ruboty::Capistrano.config.log_path, "#{DateTime.now.strftime('%Y%m%d%H%M')}.log")
|
24
|
+
@logger = Logger.new(deploy_log_path)
|
25
|
+
end
|
14
26
|
end
|
15
27
|
end
|
@@ -1,21 +1,32 @@
|
|
1
|
-
require 'ruboty/capistrano/actions/deploy'
|
2
|
-
require 'ruboty/capistrano/actions/rollback'
|
3
|
-
|
4
1
|
module Ruboty
|
5
2
|
module Handlers
|
6
3
|
class Capistrano < Base
|
7
|
-
env :
|
4
|
+
env :LOCAL_REPOSITORY_PATH, 'Deploy用の Repository Path を設定する'
|
8
5
|
|
9
6
|
on(/deploy\s+(.*)\s+(.*)/m, name: 'deploy', description: 'deployする')
|
10
7
|
on(/rollback\s+(.*)/m, name: 'rollback', description: 'rollbackする')
|
11
8
|
|
12
9
|
def deploy(message)
|
13
|
-
Ruboty::Capistrano::Actions::
|
10
|
+
deployment = Ruboty::Capistrano::Actions::Deployment.new(deploy_params(message))
|
11
|
+
message.reply(deployment.message_before_deploy)
|
12
|
+
|
13
|
+
if deployment.run
|
14
|
+
message.reply(deployment.message_after_deploy)
|
15
|
+
else
|
16
|
+
message.reply(deployment.errors.join(','))
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
def rollback(message)
|
17
21
|
Ruboty::Capistrano::Actions::Rollback.new(message).call
|
18
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def deploy_params(message)
|
27
|
+
role, branch = message.match_data[1..2]
|
28
|
+
{ role: role, branch: branch }
|
29
|
+
end
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
data/ruboty-capistrano.gemspec
CHANGED
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
spec.add_development_dependency "activesupport"
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_dependency 'octokit'
|
24
|
+
spec.add_development_dependency "pry"
|
23
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "ruboty"
|
25
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-capistrano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morioka Shuhei
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: octokit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +94,20 @@ dependencies:
|
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ruboty
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
description: " Ruboty plugin for deploy application via capistrano."
|
70
112
|
email:
|
71
113
|
- selmertsx@gmail.com
|
@@ -83,9 +125,10 @@ files:
|
|
83
125
|
- bin/console
|
84
126
|
- bin/setup
|
85
127
|
- lib/ruboty/capistrano.rb
|
86
|
-
- lib/ruboty/capistrano/actions/
|
128
|
+
- lib/ruboty/capistrano/actions/deployment.rb
|
87
129
|
- lib/ruboty/capistrano/actions/rollback.rb
|
88
130
|
- lib/ruboty/capistrano/config.rb
|
131
|
+
- lib/ruboty/capistrano/github_repository_validators.rb
|
89
132
|
- lib/ruboty/capistrano/version.rb
|
90
133
|
- lib/ruboty/handlers/capistrano.rb
|
91
134
|
- ruboty-capistrano.gemspec
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Ruboty
|
2
|
-
module Capistrano
|
3
|
-
module Actions
|
4
|
-
class Deploy < Ruboty::Actions::Base
|
5
|
-
class DeployError < StandardError; end
|
6
|
-
|
7
|
-
attr_reader :message, :path, :env, :branch, :role
|
8
|
-
|
9
|
-
def initialize(message)
|
10
|
-
@message = message
|
11
|
-
@env = Ruboty::Capistrano.config.env
|
12
|
-
@role = message.match_data[1]
|
13
|
-
@path = Ruboty::Capistrano.config.repository_path[@role]
|
14
|
-
@branch = message.match_data[2] || ENV['DEFAULT_BRANCH']
|
15
|
-
@logger = Logger.new(deploy_log_path)
|
16
|
-
end
|
17
|
-
|
18
|
-
def call
|
19
|
-
message.reply("#{@env}環境の#{@role}にBRANCH:#{@branch}をdeployします")
|
20
|
-
deploy
|
21
|
-
message.reply("#{@env}環境の#{@role}にBRANCH:#{@branch}をdeploy完了しました")
|
22
|
-
rescue => e
|
23
|
-
err_message = <<~TEXT
|
24
|
-
:cop:問題が発生しました:cop:
|
25
|
-
TEXT
|
26
|
-
|
27
|
-
@logger.error e.message
|
28
|
-
message.reply(err_message)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def deploy
|
33
|
-
if @env == 'production' && @branch != 'master'
|
34
|
-
raise InvalidDeploySettingError.new('production環境はmaster以外でdeploy出来ません')
|
35
|
-
end
|
36
|
-
|
37
|
-
cmd = "cd #{path} && bundle && bundle exec cap #{@env} deploy BRANCH=#{@branch}"
|
38
|
-
out, err, status = Bundler.with_clean_env { Open3.capture3(cmd) }
|
39
|
-
@logger.info out
|
40
|
-
raise DeployError.new(err) unless err.empty?
|
41
|
-
end
|
42
|
-
|
43
|
-
def deploy_log_path
|
44
|
-
return STDOUT if Ruboty::Capistrano.config.log_path.to_s.empty?
|
45
|
-
|
46
|
-
File.join(Ruboty::Capistrano.config.log_path, "#{DateTime.now.strftime('%Y%m%d%H%M')}.log")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|