git-deploy 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/git_deploy.rb +7 -3
- data/lib/git_deploy/configuration.rb +19 -19
- data/lib/git_deploy/ssh_methods.rb +1 -1
- data/lib/hooks/post-receive.sh +8 -6
- data/spec/configuration_spec.rb +48 -0
- metadata +9 -8
data/lib/git_deploy.rb
CHANGED
@@ -28,6 +28,7 @@ class GitDeploy < Thor
|
|
28
28
|
unless run_test("test -x #{deploy_to}")
|
29
29
|
run ["#{sudo}mkdir -p #{deploy_to}"] do |cmd|
|
30
30
|
cmd << "#{sudo}chown $USER #{deploy_to}" if options.sudo?
|
31
|
+
cmd
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
@@ -63,9 +64,12 @@ class GitDeploy < Thor
|
|
63
64
|
invoke :restart
|
64
65
|
end
|
65
66
|
|
66
|
-
desc "log
|
67
|
-
|
68
|
-
|
67
|
+
desc "log", "Shows the last part of the deploy log on the server"
|
68
|
+
method_option :tail, :aliases => '-t', :type => :boolean, :default => false
|
69
|
+
method_option :lines, :aliases => '-l', :type => :numeric, :default => 20
|
70
|
+
def log(n = nil)
|
71
|
+
tail_args = options.tail? ? '-f' : "-n#{n || options.lines}"
|
72
|
+
run "tail #{tail_args} #{deploy_to}/log/deploy.log"
|
69
73
|
end
|
70
74
|
|
71
75
|
desc "upload <files>", "Copy local files to the remote app"
|
@@ -1,30 +1,23 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'cgi'
|
3
|
+
require 'forwardable'
|
4
|
+
|
1
5
|
class GitDeploy
|
2
6
|
module Configuration
|
3
7
|
private
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
extend Forwardable
|
10
|
+
def_delegator :remote_url, :host
|
11
|
+
def_delegator :remote_url, :port, :remote_port
|
12
|
+
def_delegator :remote_url, :path, :deploy_to
|
9
13
|
|
10
14
|
def remote_user
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def extract_host_and_user
|
16
|
-
info = remote_url.split(':').first.split('@')
|
17
|
-
if info.size < 2
|
18
|
-
@user, @host = `whoami`.chomp, info.first
|
19
|
-
else
|
20
|
-
@user, @host = *info
|
15
|
+
@user ||= begin
|
16
|
+
user = remote_url.user
|
17
|
+
user ? CGI.unescape(user) : `whoami`.chomp
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
24
|
-
def deploy_to
|
25
|
-
@deploy_to ||= remote_url.split(':').last
|
26
|
-
end
|
27
|
-
|
28
21
|
def branch
|
29
22
|
'master'
|
30
23
|
end
|
@@ -50,8 +43,15 @@ class GitDeploy
|
|
50
43
|
url = remote_urls(remote).first
|
51
44
|
if url.nil?
|
52
45
|
abort "Error: Remote url not found for remote #{remote.inspect}"
|
53
|
-
elsif url =~
|
46
|
+
elsif url =~ /(^|@)github\.com\b/
|
54
47
|
abort "Error: Remote url for #{remote.inspect} points to GitHub. Can't deploy there!"
|
48
|
+
else
|
49
|
+
url = 'ssh://' + url.sub(%r{:/?}, '/') unless url =~ %r{^[\w-]+://}
|
50
|
+
begin
|
51
|
+
url = URI.parse url
|
52
|
+
rescue
|
53
|
+
abort "Error parsing remote url #{url}"
|
54
|
+
end
|
55
55
|
end
|
56
56
|
url
|
57
57
|
end
|
data/lib/hooks/post-receive.sh
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
#!/
|
1
|
+
#!/bin/bash -i
|
2
|
+
set -e
|
3
|
+
|
2
4
|
if [ "$GIT_DIR" = "." ]; then
|
3
5
|
# The script has been called as a hook; chdir to the working copy
|
4
6
|
cd ..
|
5
|
-
GIT_DIR
|
6
|
-
export GIT_DIR
|
7
|
+
unset GIT_DIR
|
7
8
|
fi
|
8
9
|
|
9
10
|
# try to obtain the usual system PATH
|
@@ -14,16 +15,17 @@ fi
|
|
14
15
|
|
15
16
|
# get the current branch
|
16
17
|
head="$(git symbolic-ref HEAD)"
|
17
|
-
# abort if we're on a detached head
|
18
|
-
[ "$?" != "0" ] && exit 1
|
19
18
|
|
20
19
|
# read the STDIN to detect if this push changed the current branch
|
21
20
|
while read oldrev newrev refname
|
22
21
|
do
|
23
22
|
[ "$refname" = "$head" ] && break
|
24
23
|
done
|
24
|
+
|
25
25
|
# abort if there's no update, or in case the branch is deleted
|
26
|
-
[ -z "${newrev//0}" ]
|
26
|
+
if [ -z "${newrev//0}" ]; then
|
27
|
+
exit
|
28
|
+
fi
|
27
29
|
|
28
30
|
# check out the latest code into the working copy
|
29
31
|
umask 002
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'git_deploy/configuration'
|
3
|
+
|
4
|
+
describe GitDeploy::Configuration do
|
5
|
+
|
6
|
+
subject {
|
7
|
+
mod = described_class
|
8
|
+
obj = Object.new
|
9
|
+
opt = options
|
10
|
+
(class << obj; self; end).class_eval do
|
11
|
+
include mod
|
12
|
+
mod.private_instance_methods.each {|m| public m }
|
13
|
+
define_method(:options) { opt }
|
14
|
+
end
|
15
|
+
obj
|
16
|
+
}
|
17
|
+
|
18
|
+
let(:options) { {:remote => 'production'} }
|
19
|
+
|
20
|
+
def stub_git_config(cmd, value)
|
21
|
+
subject.git_config[cmd] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def stub_remote_url(url, remote = options[:remote])
|
25
|
+
stub_git_config("config --get-all remote.#{remote}.url", url)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "extracting user/host from remote url" do
|
29
|
+
context "ssh url" do
|
30
|
+
before { stub_remote_url 'ssh://jon%20doe@example.com:88/path/to/app' }
|
31
|
+
|
32
|
+
its(:host) { should eq('example.com') }
|
33
|
+
its(:remote_port) { should eq(88) }
|
34
|
+
its(:remote_user) { should eq('jon doe') }
|
35
|
+
its(:deploy_to) { should eq('/path/to/app') }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "scp-style" do
|
39
|
+
before { stub_remote_url 'git@example.com:/path/to/app' }
|
40
|
+
|
41
|
+
its(:host) { should eq('example.com') }
|
42
|
+
its(:remote_port) { should be_nil }
|
43
|
+
its(:remote_user) { should eq('git') }
|
44
|
+
its(:deploy_to) { should eq('/path/to/app') }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70278714313620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70278714313620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: net-ssh
|
27
|
-
requirement: &
|
27
|
+
requirement: &70278714313100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70278714313100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: net-scp
|
38
|
-
requirement: &
|
38
|
+
requirement: &70278714312360 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70278714312360
|
47
47
|
description: A tool to install useful git hooks on your remote repository to enable
|
48
48
|
push-based, Heroku-like deployment on your host.
|
49
49
|
email: mislav.marohnic@gmail.com
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/git_deploy/templates/restart.sh
|
62
62
|
- lib/git_deploy.rb
|
63
63
|
- lib/hooks/post-receive.sh
|
64
|
+
- spec/configuration_spec.rb
|
64
65
|
- README.markdown
|
65
66
|
- LICENSE
|
66
67
|
homepage: https://github.com/mislav/git-deploy
|