captain-rails 1.0.2
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 +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/captain-rails.gemspec +27 -0
- data/config/initializers/captain.rb +3 -0
- data/lib/captain/capistrano.rb +74 -0
- data/lib/captain/config.rb +5 -0
- data/lib/captain/rails.rb +8 -0
- data/lib/captain/railtie.rb +10 -0
- data/lib/captain/tasks.rb +93 -0
- data/lib/captain/version.rb +3 -0
- data/lib/captain-rails.rb +19 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c2dc272a48e6712f0d42e829b3b38740feb85bef
|
4
|
+
data.tar.gz: 831b8c1b5042f609aed4a17d5ded721b123f3543
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 196cba08e022946c952d6487095d7639ecd607c92c16f84de7d94d7d3d31ce9ffa29d32c118b479d1de76b40b6821cff90902980d1aca5377a34b5ae1603ba63
|
7
|
+
data.tar.gz: 8e9a1a3589599b591d9f2366137fba811491675d64db0dff90472bfb986beec2c2e4522896761662a4737f19a40fe921dcbe09ee3d688f2584361e1fc2aaa367
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
captain-rails (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
capistrano (2.14.2)
|
10
|
+
highline
|
11
|
+
net-scp (>= 1.0.0)
|
12
|
+
net-sftp (>= 2.0.0)
|
13
|
+
net-ssh (>= 2.0.14)
|
14
|
+
net-ssh-gateway (>= 1.1.0)
|
15
|
+
highline (1.6.21)
|
16
|
+
net-scp (1.2.0)
|
17
|
+
net-ssh (>= 2.6.5)
|
18
|
+
net-sftp (2.1.2)
|
19
|
+
net-ssh (>= 2.6.5)
|
20
|
+
net-ssh (2.8.0)
|
21
|
+
net-ssh-gateway (1.2.0)
|
22
|
+
net-ssh (>= 2.6.5)
|
23
|
+
rake (10.3.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.3)
|
30
|
+
capistrano (~> 2.0)
|
31
|
+
captain-rails!
|
32
|
+
rake
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pazienti.it
|
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
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'captain/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "captain-rails"
|
8
|
+
spec.version = Captain::VERSION
|
9
|
+
spec.authors = ["Alessio Santo", "Salvatore Piazzolla"]
|
10
|
+
spec.email = ["alessio.santo@pazienti.it"]
|
11
|
+
spec.description = %q{A deploy tracker}
|
12
|
+
spec.summary = %q{A deploy tracker}
|
13
|
+
spec.homepage = "https://github.com/Pazienti/captain-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency("capistrano", "~> 2.0")
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Defines deploy:notify_captain which will send information about the deploy to Captain.
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
module Captain
|
5
|
+
module Capistrano
|
6
|
+
# Returns an empty quoted String if +str+ has a length of zero.
|
7
|
+
def self.shellescape(str)
|
8
|
+
str = str.to_s
|
9
|
+
|
10
|
+
# An empty argument will be skipped, so return empty quotes.
|
11
|
+
return "''" if str.empty?
|
12
|
+
|
13
|
+
str = str.dup
|
14
|
+
|
15
|
+
# Treat multibyte characters as is. It is caller's responsibility
|
16
|
+
# to encode the string in the right encoding for the shell
|
17
|
+
# environment.
|
18
|
+
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")
|
19
|
+
|
20
|
+
# A LF cannot be escaped with a backslash because a backslash + LF
|
21
|
+
# combo is regarded as line continuation and simply ignored.
|
22
|
+
str.gsub!(/\n/, "'\n'")
|
23
|
+
|
24
|
+
return str
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.load_into(configuration)
|
28
|
+
configuration.load do
|
29
|
+
after "deploy", "captain:deploy"
|
30
|
+
after "deploy:migrations", "captain:deploy"
|
31
|
+
after "deploy:cold", "captain:deploy"
|
32
|
+
|
33
|
+
namespace :captain do
|
34
|
+
desc <<-DESC
|
35
|
+
Notify Captain of the deployment by running the notification on the REMOTE machine.
|
36
|
+
- Run remotely so we use remote API keys, environment, etc.
|
37
|
+
DESC
|
38
|
+
task :deploy, :except => { :no_release => true } do
|
39
|
+
# Get environment, branch, local user, executable
|
40
|
+
rails_env = fetch(:rails_env, "production")
|
41
|
+
captain_env = fetch(:captain_env, fetch(:rails_env, "production"))
|
42
|
+
branch = fetch(:branch, "master")
|
43
|
+
local_user = ENV['USER'] || ENV['USERNAME']
|
44
|
+
executable = RUBY_PLATFORM.downcase.include?('mswin') ? fetch(:rake, 'rake.bat') : fetch(:rake, 'bundle exec rake ')
|
45
|
+
directory = configuration.release_path
|
46
|
+
|
47
|
+
# Get the username and email from local git
|
48
|
+
local_author_name = `git config --get user.name`
|
49
|
+
local_author_email = `git config --get user.email`
|
50
|
+
|
51
|
+
# Create the basic command
|
52
|
+
notify_command = "cd #{directory}; #{executable} RAILS_ENV=#{rails_env} captain:start TO=#{captain_env} REVISION=#{current_revision} REPO=#{repository} BRANCH=#{branch} USER=#{Captain::Capistrano::shellescape(local_user)} COMMIT_AUTHOR_NAME=#{local_author_name} COMMIT_AUTHOR_EMAIL=#{local_author_email}"
|
53
|
+
notify_command << " DRY_RUN=true" if dry_run
|
54
|
+
notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']
|
55
|
+
|
56
|
+
logger.info "Notifying Captain of Deploy (#{notify_command})"
|
57
|
+
if configuration.dry_run
|
58
|
+
logger.info "DRY RUN: Notification not actually run."
|
59
|
+
else
|
60
|
+
result = ""
|
61
|
+
run(notify_command, :once => true) { |ch, stream, data| result << data }
|
62
|
+
# TODO: Check if SSL is active on account via result content.
|
63
|
+
end
|
64
|
+
puts "Captain Notification Complete. CALLING THE RAKE"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if Capistrano::Configuration.instance
|
73
|
+
Captain::Capistrano.load_into(Capistrano::Configuration.instance)
|
74
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
namespace :captain do
|
4
|
+
task :start => :environment do
|
5
|
+
|
6
|
+
# Deploying TO [app environment]
|
7
|
+
# BRANCH [the master branch] of the
|
8
|
+
# REPO [repo address]
|
9
|
+
# REVISION [latest commit hex]
|
10
|
+
release_env = ENV['TO']
|
11
|
+
repo = ENV['REPO']
|
12
|
+
rev = ENV['REVISION']
|
13
|
+
branch = ENV['BRANCH']
|
14
|
+
|
15
|
+
# Retrieve author email and name from env
|
16
|
+
commit_author_name = ENV['COMMIT_AUTHOR_NAME']
|
17
|
+
commit_author_email = ENV['COMMIT_AUTHOR_EMAIL']
|
18
|
+
|
19
|
+
# Get the app id from the gem config object
|
20
|
+
app_id = Captain.config.public_key
|
21
|
+
|
22
|
+
# Up to you to use ssl
|
23
|
+
use_ssl = false || ENV['USE_SSL']
|
24
|
+
|
25
|
+
puts "Deploying Repo(#{repo} at #{branch}) on #{release_env} server heading #{rev}"
|
26
|
+
|
27
|
+
uri = URI.parse('http://deploydapp.herokuapp.com/api/v1/deployments') # Insert the address of the application api
|
28
|
+
|
29
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
30
|
+
http.use_ssl = true if use_ssl
|
31
|
+
|
32
|
+
request = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
|
33
|
+
|
34
|
+
data = {
|
35
|
+
:deployment => {
|
36
|
+
:repo => repo,
|
37
|
+
:environment => release_env,
|
38
|
+
:branch => branch,
|
39
|
+
:revision => rev,
|
40
|
+
:deployable_application_id => app_id,
|
41
|
+
:author_name => commit_author_name,
|
42
|
+
:author_email => commit_author_email
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
request.body = data.to_json
|
47
|
+
|
48
|
+
response = http.request(request)
|
49
|
+
|
50
|
+
puts response.body
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Task to install the gem requirements"
|
54
|
+
task :install, [:public_token] do |t, args|
|
55
|
+
public_token = args[:public_token]
|
56
|
+
|
57
|
+
# call the API
|
58
|
+
uri = URI.parse("http://deploydapp.herokuapp.com/api/v1/deployable_applications/#{public_token}/activate") # Insert the address of the application api
|
59
|
+
|
60
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
61
|
+
# http.use_ssl = true if use_ssl
|
62
|
+
|
63
|
+
request = Net::HTTP::Put.new(uri.path, {'Content-Type' =>'application/json'})
|
64
|
+
|
65
|
+
response = http.request(request)
|
66
|
+
|
67
|
+
if response.kind_of?(Net::HTTPOK)
|
68
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'config', 'initializers', 'captain.rb')
|
69
|
+
destination = File.new(Rails.root.to_s + '/config/initializers/captain.rb', 'w')
|
70
|
+
|
71
|
+
# FileUtils.cp(source, destination)
|
72
|
+
|
73
|
+
IO.readlines(source.to_s).each do |line|
|
74
|
+
str = line
|
75
|
+
str = "\tconfig.public_key = '#{public_token}'" if str.index('config.public_key').present?
|
76
|
+
|
77
|
+
destination.write(str + "\n")
|
78
|
+
end
|
79
|
+
|
80
|
+
destination.close
|
81
|
+
end
|
82
|
+
|
83
|
+
if File.exist?(Rails.root.to_s + '/config/deploy.rb')
|
84
|
+
# install gem requirements on deploy config
|
85
|
+
deploy_file = File.new(Rails.root.to_s + '/config/deploy.rb', 'a')
|
86
|
+
|
87
|
+
deploy_file.write("require '../config/boot'")
|
88
|
+
deploy_file.write("require 'deployd/capistrano'")
|
89
|
+
|
90
|
+
deploy_file.close
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "json"
|
2
|
+
require "captain/version"
|
3
|
+
require "captain/config"
|
4
|
+
|
5
|
+
module Captain
|
6
|
+
require "captain/railtie.rb" if defined?(Rails)
|
7
|
+
|
8
|
+
@config = Captain::Config.new
|
9
|
+
|
10
|
+
def self.config
|
11
|
+
|
12
|
+
if block_given?
|
13
|
+
yield(@config)
|
14
|
+
else
|
15
|
+
@config
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: captain-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessio Santo
|
8
|
+
- Salvatore Piazzolla
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-09-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: capistrano
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.0'
|
56
|
+
description: A deploy tracker
|
57
|
+
email:
|
58
|
+
- alessio.santo@pazienti.it
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- captain-rails.gemspec
|
69
|
+
- config/initializers/captain.rb
|
70
|
+
- lib/captain-rails.rb
|
71
|
+
- lib/captain/capistrano.rb
|
72
|
+
- lib/captain/config.rb
|
73
|
+
- lib/captain/rails.rb
|
74
|
+
- lib/captain/railtie.rb
|
75
|
+
- lib/captain/tasks.rb
|
76
|
+
- lib/captain/version.rb
|
77
|
+
homepage: https://github.com/Pazienti/captain-rails
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.6
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A deploy tracker
|
101
|
+
test_files: []
|
102
|
+
has_rdoc:
|