unfold 1.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/uf +1 -1
- data/lib/unfold.rb +43 -39
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c128e5e9a0ffba8a2c01e9ee8485690584ddc87
|
4
|
+
data.tar.gz: d563032c64610b5348b09a11b37614b9cceb7ce3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e0a0c8534183bfa86f3d199fa115325fba6e27a89ae7dec1c41764c4f11108439a2eb4464c9d0c002e229dd13921a6021ca5e3edc620fa992c1d0e368ec93db
|
7
|
+
data.tar.gz: 1152007a66d85110722e763fed3015f158ab3614014bdf11965193db7b3fdea3c37385496ce286fcfb1678cf68b01954bdeb5d16bb86c02fda93d21732c2720f
|
data/bin/uf
CHANGED
data/lib/unfold.rb
CHANGED
@@ -3,10 +3,22 @@ require "net/ssh"
|
|
3
3
|
require "net/scp"
|
4
4
|
require "stringio"
|
5
5
|
|
6
|
+
CONFIG_RELATIVE = "/config/unfold.rb"
|
7
|
+
|
8
|
+
class File
|
9
|
+
def self.git_root
|
10
|
+
`git rev-parse --show-toplevel`.strip
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
module Unfold
|
15
|
+
class Config
|
16
|
+
attr_accessor :remote_host, :remote_user, :remote_destination, :appname, :env
|
17
|
+
end
|
18
|
+
|
7
19
|
# the method used in the config file
|
8
20
|
def self.config(env_arrays)
|
9
|
-
return
|
21
|
+
return [] if block_given? == false
|
10
22
|
configs = []
|
11
23
|
env_arrays.each do |env|
|
12
24
|
config = Config.new
|
@@ -17,56 +29,49 @@ module Unfold
|
|
17
29
|
return configs
|
18
30
|
end
|
19
31
|
|
20
|
-
class Config
|
21
|
-
attr_accessor :remote_host, :remote_user, :remote_destination, :appname, :env
|
22
|
-
end
|
23
|
-
|
24
32
|
# creates a post-receive hook script from an Unfold::Config object
|
25
33
|
def self.post_receive_script(c)
|
26
|
-
|
27
|
-
|
28
|
-
return %{
|
29
|
-
#!/bin/bash
|
30
|
-
read oldrev newrev refname
|
34
|
+
return %{#!/bin/bash
|
35
|
+
read oldrev newrev refname
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
45
|
-
deploy
|
46
|
-
}
|
37
|
+
deploy() {
|
38
|
+
if [ "$refname" = "refs/heads/master" ]; then
|
39
|
+
unset GIT_DIR
|
40
|
+
cd #{c.remote_destination}
|
41
|
+
git pull origin master > /dev/null 2> /dev/null
|
42
|
+
echo "\rUNFOLD: Deployed $newrev"
|
43
|
+
if [ -f config/unfold_postdeploy.rb ]; then
|
44
|
+
bash -lc "ruby config/unfold_postdeploy.rb"
|
45
|
+
fi
|
46
|
+
fi
|
47
|
+
}
|
48
|
+
deploy}
|
47
49
|
end
|
48
50
|
|
51
|
+
# loads config from config ruby script
|
49
52
|
def self.read_config
|
50
|
-
eval(File.read(
|
53
|
+
eval(File.read(File.git_root + CONFIG_RELATIVE))
|
51
54
|
end
|
52
55
|
|
56
|
+
# DRYs up the setup and teardown code
|
53
57
|
def self.ssh(c)
|
54
58
|
return nil if block_given? == false
|
55
59
|
Net::SSH.start(c.remote_host, c.remote_user) do |ssh|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# setup paths
|
60
|
-
repo_path = "#{path}/.unfold/repos/#{c.appname}-#{c.env}.git" # doesn't include ~/ so that it can be used in the remote url
|
61
|
-
logs_path = "#{path}/.unfold/logs/#{c.appname}-#{c.env}/"
|
62
|
-
yield(ssh,{ :repo => repo_path, :logs => logs_path })
|
60
|
+
home_path = ssh.exec!("cd; pwd").strip # home directory
|
61
|
+
repo_path = "#{home_path}/.unfold/repos/#{c.appname}-#{c.env}.git"
|
62
|
+
yield(ssh,{ :repo => repo_path })
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.teardown(local, remote)
|
67
67
|
Unfold.read_config.each do |c|
|
68
|
-
`git remote
|
69
|
-
|
68
|
+
`git remote remove #{c.env}` if local == true
|
69
|
+
|
70
|
+
if remote == true
|
71
|
+
Unfold.ssh c do |ssh, paths|
|
72
|
+
ssh.exec!("rm -rf #{paths[:repo]}")
|
73
|
+
end
|
74
|
+
end
|
70
75
|
end
|
71
76
|
end
|
72
77
|
|
@@ -74,7 +79,7 @@ module Unfold
|
|
74
79
|
Unfold.read_config.each do |c|
|
75
80
|
if c.env == envi
|
76
81
|
Unfold.ssh c do |ssh, paths|
|
77
|
-
print ssh.exec!("cd #{c.remote_destination};
|
82
|
+
print ssh.exec!("cd #{c.remote_destination}; git reset --hard #{revision}")
|
78
83
|
end
|
79
84
|
end
|
80
85
|
end
|
@@ -88,12 +93,11 @@ module Unfold
|
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
91
|
-
def self.setup_remote
|
96
|
+
def self.setup_remote
|
92
97
|
Unfold.read_config.each do |c|
|
93
98
|
Unfold.ssh c do |ssh, paths|
|
94
99
|
# create the remote repo
|
95
|
-
ssh.exec!("mkdir -p #{paths[:repo]};
|
96
|
-
ssh.exec!("cd #{paths[:repo]}; git --bare init")
|
100
|
+
ssh.exec!("mkdir -p #{c.remote_destination}; mkdir -p #{paths[:repo]}; cd #{paths[:repo]}; git --bare init")
|
97
101
|
|
98
102
|
# upload the post-receive hook
|
99
103
|
script = StringIO.new(Unfold.post_receive_script(c))
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unfold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathaniel Symer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: net-scp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Dead simple git deployment with minimal config.
|