hillary 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/hillary/repo/version.rb +2 -2
- data/lib/hillary/shellable.rb +1 -1
- data/lib/hillary/slug/bucket.rb +4 -0
- data/lib/hillary/slug.rb +28 -4
- data/lib/hillary/version.rb +1 -1
- data/spec/hillary/slug/bucket_spec.rb +11 -0
- data/spec/hillary/slug_spec.rb +55 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2VjZmE1YTk5NDFjYWQ2MTlhOTlmMzMxZWVlNDcyMTM1OTU2MzkxZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjgxODllNzQ1MDA4NjAwNWQ5MDVjNWI0MjMxMjZkZmI3MmFhMGNmMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWNhOTUwMzU4YjZmNjg4NTRkOTU4N2QzMDgyNmQ2YzgzM2UwMWM0MDhmMWI3
|
10
|
+
MjMxM2M2OTQyMzYzYWRmNTkyMTI5MDEwNjAwMTA4NWM4ZTBiOTE0YmY0Nzhk
|
11
|
+
MmY1NzM4NDhjYzg4ODg5ZjUzMTQyMDc0MzI2N2YyNjk0MzM3NDY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGI2ZWI5NDcwYjcyOTZlOTUwM2NmNWU0ZjIwODhhY2I0MDAzMmZiMmNlNzY1
|
14
|
+
YmYzNjVjZjg4NmJhNjU2MTg0ZjRmNWNlNjU2NmMxNDk3NmI3NGYxOWNmZTUy
|
15
|
+
MWE0NTE4OWZlNTAwODZjM2UxNzYzZGIzNjEyZGEzZGIwOTE1YmQ=
|
data/lib/hillary/repo/version.rb
CHANGED
data/lib/hillary/shellable.rb
CHANGED
data/lib/hillary/slug/bucket.rb
CHANGED
data/lib/hillary/slug.rb
CHANGED
@@ -11,6 +11,7 @@ module Hillary
|
|
11
11
|
attr_reader :branch, :version
|
12
12
|
|
13
13
|
SlugArchiveError = Class.new(StandardError)
|
14
|
+
SlugNotFoundError = Class.new(StandardError)
|
14
15
|
|
15
16
|
class << self
|
16
17
|
def build(path = File.expand_path('.'), version = Repo::Version.create!, options = {})
|
@@ -23,16 +24,24 @@ module Hillary
|
|
23
24
|
def initialize(path, version, options = {})
|
24
25
|
@path = path
|
25
26
|
@version = version
|
26
|
-
@logger = options[:logger] || Logger.new($stdout)
|
27
27
|
@bucket = options[:bucket] || Bucket.new
|
28
28
|
|
29
|
-
logger
|
29
|
+
@logger = if options[:logger]
|
30
|
+
options[:logger]
|
31
|
+
else
|
32
|
+
Logger.new($stdout).tap do |logger|
|
33
|
+
logger.formatter = proc do |severity, time, _, msg|
|
34
|
+
"#{time.strftime('%Y-%m-%d %H:%M:%S')} #{severity} - #{msg}\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
def build
|
33
41
|
if version.master?
|
42
|
+
create_slug_if_missing
|
34
43
|
copy_slug
|
35
|
-
|
44
|
+
elsif version.dev?
|
36
45
|
create_slug
|
37
46
|
upload_slug
|
38
47
|
end
|
@@ -49,6 +58,18 @@ module Hillary
|
|
49
58
|
private
|
50
59
|
attr_reader :logger, :bucket, :path
|
51
60
|
|
61
|
+
def create_slug_if_missing
|
62
|
+
return if bucket.exists?(canonical_storage_slug_file)
|
63
|
+
|
64
|
+
if version.production?
|
65
|
+
raise SlugNotFoundError, "Attempted to create production slug from RC, but canonical slug (#{bucket.name}:/#{canonical_storage_slug_file}) couldn't be found"
|
66
|
+
else
|
67
|
+
logger.warn("Unable to find slug #{bucket.name}:/#{canonical_storage_slug_file}")
|
68
|
+
create_slug
|
69
|
+
upload_slug
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
52
73
|
def copy_slug
|
53
74
|
logger.info("Copying #{bucket.name}:/#{canonical_storage_slug_file} to #{bucket.name}:/#{storage_slug_file}")
|
54
75
|
bucket.copy(canonical_storage_slug_file, storage_slug_file)
|
@@ -57,7 +78,10 @@ module Hillary
|
|
57
78
|
def create_slug
|
58
79
|
Dir.chdir(project_parent_directory) do
|
59
80
|
logger.info("Creating slug #{canonical_slug_file}")
|
60
|
-
|
81
|
+
|
82
|
+
command = "tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf #{canonical_slug_file} #{project_name}"
|
83
|
+
|
84
|
+
shell(command, logger: logger)
|
61
85
|
end
|
62
86
|
end
|
63
87
|
|
data/lib/hillary/version.rb
CHANGED
@@ -25,6 +25,17 @@ describe Hillary::Slug::Bucket do
|
|
25
25
|
|
26
26
|
subject{Hillary::Slug::Bucket.new(bucket_name, access_key, secret_key)}
|
27
27
|
|
28
|
+
describe '#exists?' do
|
29
|
+
it 'returns false when the file does not exist' do
|
30
|
+
expect(subject.exists?(canonical_slug_path)).to be_falsy
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns true when the file does exist' do
|
34
|
+
bucket.files.create(key: canonical_slug_path, body: StringIO.new(''), public: false)
|
35
|
+
expect(subject.exists?(canonical_slug_path)).to be_truthy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
28
39
|
describe '#write' do
|
29
40
|
it 'writes the file to the bucket with the given name' do
|
30
41
|
subject.write(canonical_slug_path, slug_file_path)
|
data/spec/hillary/slug_spec.rb
CHANGED
@@ -17,9 +17,10 @@ describe Hillary::Slug do
|
|
17
17
|
let(:out){StringIO.new}
|
18
18
|
let(:logger) do
|
19
19
|
Logger.new(out).tap do |logger|
|
20
|
+
logger.formatter = proc{|_, _, _, msg| msg + "\n"}
|
20
21
|
end
|
21
22
|
end
|
22
|
-
let(:bucket){double(Hillary::Slug::Bucket, write: nil, copy: nil, name: 'gz-slugbucket')}
|
23
|
+
let(:bucket){double(Hillary::Slug::Bucket, write: nil, copy: nil, name: 'gz-slugbucket', exists?: true)}
|
23
24
|
let(:path){File.expand_path('../../tmp/g3', __FILE__)}
|
24
25
|
|
25
26
|
describe '.build' do
|
@@ -45,20 +46,22 @@ describe Hillary::Slug do
|
|
45
46
|
end
|
46
47
|
|
47
48
|
describe '#build' do
|
49
|
+
let(:slug_name){'g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz'}
|
50
|
+
let(:slug_path){Pathname.new(path).join('..', slug_name).expand_path}
|
51
|
+
|
52
|
+
before(:each){FileUtils.mkdir_p(path)}
|
53
|
+
after(:each){FileUtils.rm_rf(path)}
|
54
|
+
|
48
55
|
context 'when branch is dev' do
|
49
56
|
subject(:slug){described_class.new(path, version, logger: logger, bucket: bucket)}
|
50
|
-
let(:slug_name){'g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz'}
|
51
|
-
let(:slug_path){Pathname.new(path).join('..', slug_name).expand_path}
|
52
57
|
|
53
58
|
describe 'when everything is successful' do
|
54
59
|
before(:each) do
|
55
|
-
FileUtils.mkdir_p(path)
|
56
60
|
allow(bucket).to receive(:write)
|
57
61
|
end
|
58
62
|
|
59
63
|
after(:each) do
|
60
64
|
FileUtils.rm_rf(slug_path)
|
61
|
-
FileUtils.rm_rf(path)
|
62
65
|
end
|
63
66
|
|
64
67
|
it 'creates the slug' do
|
@@ -78,6 +81,7 @@ describe Hillary::Slug do
|
|
78
81
|
|
79
82
|
expect(out.string).to eq(
|
80
83
|
"Creating slug g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
|
84
|
+
"tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz g3\n"\
|
81
85
|
'Uploading g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz '\
|
82
86
|
"to gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"
|
83
87
|
)
|
@@ -86,6 +90,7 @@ describe Hillary::Slug do
|
|
86
90
|
|
87
91
|
describe 'when archiving fails' do
|
88
92
|
it 'raises an error' do
|
93
|
+
FileUtils.rm_rf(path)
|
89
94
|
expect{slug.build}.to raise_error(Hillary::Shellable::ExecutionError)
|
90
95
|
end
|
91
96
|
end
|
@@ -107,18 +112,55 @@ describe Hillary::Slug do
|
|
107
112
|
|
108
113
|
subject(:slug){described_class.new(path, version, logger: logger, bucket: bucket)}
|
109
114
|
|
110
|
-
|
111
|
-
|
115
|
+
context 'when the canonical slug exists' do
|
116
|
+
it 'copies the canonical slug to rc slug name' do
|
117
|
+
expect(bucket).to receive(:copy).with('dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz', 'rc/g3_slug_RC2014_01_01_01_01_01.tar.gz')
|
112
118
|
|
113
|
-
|
119
|
+
slug.build
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'logs information about what is happening' do
|
123
|
+
slug.build
|
124
|
+
|
125
|
+
expect(out.string).to eq(
|
126
|
+
'Copying gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz '\
|
127
|
+
"to gz-slugbucket:/rc/g3_slug_RC2014_01_01_01_01_01.tar.gz\n"
|
128
|
+
)
|
129
|
+
end
|
114
130
|
end
|
115
131
|
|
116
|
-
|
117
|
-
|
132
|
+
context 'when the canonical slug does not exist' do
|
133
|
+
before(:each){allow(bucket).to receive(:exists?).and_return(false)}
|
118
134
|
|
119
|
-
|
120
|
-
|
121
|
-
|
135
|
+
it 'creates the slug' do
|
136
|
+
slug.build
|
137
|
+
|
138
|
+
expect(File.exist?(slug_path)).to eq(true)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'writes the slug to the bucket' do
|
142
|
+
expect(bucket).to receive(:write).with('dev/' + slug_name, slug_path)
|
143
|
+
|
144
|
+
slug.build
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'copies the canonical slug to rc slug name' do
|
148
|
+
expect(bucket).to receive(:copy).with('dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz', 'rc/g3_slug_RC2014_01_01_01_01_01.tar.gz')
|
149
|
+
|
150
|
+
slug.build
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'logs information about what is happening' do
|
154
|
+
slug.build
|
155
|
+
|
156
|
+
expect(out.string).to eq(
|
157
|
+
"Unable to find slug gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
|
158
|
+
"Creating slug g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
|
159
|
+
"tar --exclude \".git\" --exclude \"vendor/bundle\" -zcvf g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz g3\n"\
|
160
|
+
"Uploading g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz to gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz\n"\
|
161
|
+
"Copying gz-slugbucket:/dev/g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz to gz-slugbucket:/rc/g3_slug_RC2014_01_01_01_01_01.tar.gz\n"
|
162
|
+
)
|
163
|
+
end
|
122
164
|
end
|
123
165
|
end
|
124
166
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hillary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allen Madsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grit
|