heirloom 0.5.0rc1 → 0.5.0rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/lib/heirloom/archive/downloader.rb +21 -13
- data/lib/heirloom/archive/extracter.rb +38 -0
- data/lib/heirloom/archive.rb +1 -0
- data/lib/heirloom/cli/download.rb +5 -1
- data/lib/heirloom/cli/shared.rb +11 -0
- data/lib/heirloom/directory/directory.rb +3 -5
- data/lib/heirloom/misc/tmp.rb +12 -0
- data/lib/heirloom/misc.rb +1 -0
- data/lib/heirloom/version.rb +1 -1
- data/lib/heirloom.rb +2 -1
- data/spec/archive/downloader_spec.rb +32 -5
- data/spec/archive/extracter_spec.rb +21 -0
- data/spec/cli/download_spec.rb +7 -1
- data/spec/cli/shared_spec.rb +25 -0
- data/spec/directory/directory_spec.rb +5 -3
- data/spec/misc/tmp_spec.rb +19 -0
- metadata +19 -12
data/CHANGELOG
CHANGED
@@ -2,6 +2,8 @@ module Heirloom
|
|
2
2
|
|
3
3
|
class Downloader
|
4
4
|
|
5
|
+
include Heirloom::Misc::Tmp
|
6
|
+
|
5
7
|
def initialize(args)
|
6
8
|
@config = args[:config]
|
7
9
|
@name = args[:name]
|
@@ -12,6 +14,8 @@ module Heirloom
|
|
12
14
|
def download(args)
|
13
15
|
region = args[:region]
|
14
16
|
base_prefix = args[:base_prefix]
|
17
|
+
extract = args[:extract]
|
18
|
+
output = args[:output] ||= './'
|
15
19
|
|
16
20
|
s3_downloader = Downloader::S3.new :config => @config,
|
17
21
|
:logger => @logger,
|
@@ -20,16 +24,16 @@ module Heirloom
|
|
20
24
|
bucket = get_bucket :region => region, :base_prefix => base_prefix
|
21
25
|
|
22
26
|
@logger.info "Downloading s3://#{bucket}/#{key} from #{region}."
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
local_file.write
|
27
|
+
archive = s3_downloader.download_file :bucket => bucket,
|
28
|
+
:key => key
|
29
|
+
|
30
|
+
if extract
|
31
|
+
extracter = Extracter.new :config => @config
|
32
|
+
extracter.extract :archive => archive, :output => output
|
33
|
+
else
|
34
|
+
output_file = File.join output, file
|
35
|
+
@logger.info "Writing archive to '#{output_file}'."
|
36
|
+
File.open(output_file, 'w') { |local_file| local_file.write archive }
|
33
37
|
end
|
34
38
|
|
35
39
|
@logger.info "Download complete."
|
@@ -37,12 +41,16 @@ module Heirloom
|
|
37
41
|
|
38
42
|
private
|
39
43
|
|
40
|
-
def
|
41
|
-
"#{
|
44
|
+
def file
|
45
|
+
"#{@id}.tar.gz"
|
42
46
|
end
|
43
47
|
|
44
48
|
def key
|
45
|
-
"#{@name}/#{
|
49
|
+
"#{@name}/#{file}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_bucket(args)
|
53
|
+
"#{args[:base_prefix]}-#{args[:region]}"
|
46
54
|
end
|
47
55
|
|
48
56
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Heirloom
|
2
|
+
class Extracter
|
3
|
+
|
4
|
+
include Heirloom::Misc::Tmp
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
@config = args[:config]
|
8
|
+
@logger = @config.logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def extract(args)
|
12
|
+
@tmp_archive = random_archive
|
13
|
+
|
14
|
+
create_tmp_archive args[:archive]
|
15
|
+
extract_tmp_archive args[:output]
|
16
|
+
delete_tmp_archive
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def create_tmp_archive(archive)
|
22
|
+
File.open(@tmp_archive, 'w') { |local_file| local_file.write archive }
|
23
|
+
end
|
24
|
+
|
25
|
+
def extract_tmp_archive(output)
|
26
|
+
@logger.info "Extracting archive to '#{output}'."
|
27
|
+
cmd = "tar xzf #{@tmp_archive} -C #{output}"
|
28
|
+
@logger.debug "Executing '#{cmd}'."
|
29
|
+
`#{cmd}`
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_tmp_archive
|
33
|
+
@logger.debug "Deleting '#{@tmp_archive}'."
|
34
|
+
File.delete @tmp_archive
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/heirloom/archive.rb
CHANGED
@@ -4,6 +4,7 @@ require 'heirloom/archive/builder.rb'
|
|
4
4
|
require 'heirloom/archive/updater.rb'
|
5
5
|
require 'heirloom/archive/uploader.rb'
|
6
6
|
require 'heirloom/archive/downloader.rb'
|
7
|
+
require 'heirloom/archive/extracter.rb'
|
7
8
|
require 'heirloom/archive/authorizer.rb'
|
8
9
|
require 'heirloom/archive/destroyer.rb'
|
9
10
|
require 'heirloom/archive/verifier.rb'
|
@@ -14,14 +14,17 @@ module Heirloom
|
|
14
14
|
:required => [:base_prefix, :name, :id, :output],
|
15
15
|
:config => @config
|
16
16
|
|
17
|
+
|
17
18
|
@archive = Archive.new :name => @opts[:name],
|
18
19
|
:id => @opts[:id],
|
19
20
|
:config => @config
|
20
21
|
end
|
21
22
|
|
22
23
|
def download
|
24
|
+
ensure_directory :path => @opts[:output], :config => @config
|
23
25
|
@archive.download :output => @opts[:output],
|
24
26
|
:region => @opts[:region],
|
27
|
+
:extract => @opts[:extract],
|
25
28
|
:base_prefix => @opts[:base_prefix]
|
26
29
|
end
|
27
30
|
|
@@ -46,7 +49,8 @@ EOS
|
|
46
49
|
opt :name, "Name of archive.", :type => :string
|
47
50
|
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
48
51
|
:default => 'info'
|
49
|
-
opt :output, "
|
52
|
+
opt :output, "Path to download archive.", :type => :string
|
53
|
+
opt :extract, "Extract the archive in the given output path.", :short => "-x"
|
50
54
|
opt :region, "Region to download archive.", :type => :string,
|
51
55
|
:default => 'us-west-1'
|
52
56
|
opt :secret, "AWS Secret Access Key", :type => :string
|
data/lib/heirloom/cli/shared.rb
CHANGED
@@ -36,6 +36,17 @@ module Heirloom
|
|
36
36
|
exit 1 unless missing_opts.empty?
|
37
37
|
end
|
38
38
|
|
39
|
+
def ensure_directory(args)
|
40
|
+
config = args[:config]
|
41
|
+
path = args[:path]
|
42
|
+
logger = config.logger
|
43
|
+
|
44
|
+
unless File.directory? path
|
45
|
+
logger.error "#{path} is not a directory."
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
39
50
|
def ensure_domain_exists(args)
|
40
51
|
config = args[:config]
|
41
52
|
name = args[:name]
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'tmpdir'
|
2
|
-
|
3
1
|
module Heirloom
|
4
2
|
|
5
3
|
class Directory
|
6
4
|
|
7
5
|
attr_reader :local_build
|
8
6
|
|
7
|
+
include Heirloom::Misc::Tmp
|
8
|
+
|
9
9
|
def initialize(args)
|
10
10
|
@config = args[:config]
|
11
11
|
@exclude = args[:exclude]
|
@@ -14,9 +14,7 @@ module Heirloom
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def build_artifact_from_directory
|
17
|
-
|
18
|
-
|
19
|
-
@local_build = File.join(Dir.tmpdir, random_text + ".tar.gz")
|
17
|
+
@local_build = random_archive
|
20
18
|
|
21
19
|
@logger.info "Building Heirloom '#{@local_build}' from '#{@path}'."
|
22
20
|
@logger.info "Excluding #{@exclude.to_s}."
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'heirloom/misc/tmp'
|
data/lib/heirloom/version.rb
CHANGED
data/lib/heirloom.rb
CHANGED
@@ -22,22 +22,49 @@ describe Heirloom do
|
|
22
22
|
@file_mock = mock 'file'
|
23
23
|
end
|
24
24
|
|
25
|
-
context "
|
25
|
+
context "extract set to false" do
|
26
26
|
it "should download to the current path if output is not specified" do
|
27
27
|
File.should_receive(:open).with('./123.tar.gz', 'w').
|
28
28
|
and_return @file_mock
|
29
29
|
|
30
30
|
@downloader.download :region => 'us-west-1',
|
31
|
-
:base_prefix => 'bucket'
|
31
|
+
:base_prefix => 'bucket',
|
32
|
+
:extract => false
|
32
33
|
end
|
33
34
|
|
34
35
|
it "should download arhcive to specified output" do
|
35
|
-
File.should_receive(:open).with('/tmp/
|
36
|
+
File.should_receive(:open).with('/tmp/dir/123.tar.gz', 'w').
|
36
37
|
and_return @file_mock
|
37
38
|
|
38
|
-
@downloader.download :output => '/tmp/
|
39
|
+
@downloader.download :output => '/tmp/dir',
|
39
40
|
:region => 'us-west-1',
|
40
|
-
:base_prefix => 'bucket'
|
41
|
+
:base_prefix => 'bucket',
|
42
|
+
:extract => false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "extract set to true" do
|
47
|
+
before do
|
48
|
+
@extracter_mock = mock 'extracter'
|
49
|
+
Heirloom::Extracter.should_receive(:new).with(:config => @config_mock).
|
50
|
+
and_return @extracter_mock
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should download and extract the to specified output" do
|
54
|
+
@extracter_mock.should_receive(:extract).with :archive => 'filename',
|
55
|
+
:output => '/tmp/dir'
|
56
|
+
@downloader.download :output => '/tmp/dir',
|
57
|
+
:region => 'us-west-1',
|
58
|
+
:base_prefix => 'bucket',
|
59
|
+
:extract => true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should download and extract the to the cwd" do
|
63
|
+
@extracter_mock.should_receive(:extract).with :archive => 'filename',
|
64
|
+
:output => './'
|
65
|
+
@downloader.download :region => 'us-west-1',
|
66
|
+
:base_prefix => 'bucket',
|
67
|
+
:extract => true
|
41
68
|
end
|
42
69
|
end
|
43
70
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Heirloom do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@logger_stub = stub 'logger', :info => true, :debug => true
|
7
|
+
@config_mock = mock 'config'
|
8
|
+
@config_mock.stub :logger => @logger_stub
|
9
|
+
@extracter = Heirloom::Extracter.new :config => @config_mock
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should extract the given archive object into the output directory" do
|
13
|
+
@extracter.should_receive(:random_archive).and_return '/tmp/file'
|
14
|
+
File.should_receive(:open).with('/tmp/file', 'w')
|
15
|
+
Heirloom::Extracter.any_instance.should_receive(:`).
|
16
|
+
with('tar xzf /tmp/file -C /output')
|
17
|
+
File.should_receive(:delete).with '/tmp/file'
|
18
|
+
@extracter.extract :archive => 'test', :output => '/output'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/cli/download_spec.rb
CHANGED
@@ -9,6 +9,7 @@ describe Heirloom do
|
|
9
9
|
:level => 'info',
|
10
10
|
:output => '/tmp/test123',
|
11
11
|
:region => 'us-east-1',
|
12
|
+
:extract => false,
|
12
13
|
:base_prefix => 'base' }
|
13
14
|
@logger_stub = stub 'logger'
|
14
15
|
@config_mock = mock 'config'
|
@@ -35,7 +36,12 @@ describe Heirloom do
|
|
35
36
|
it "should download an archive" do
|
36
37
|
@archive_mock.should_receive(:download).with :output => '/tmp/test123',
|
37
38
|
:region => 'us-east-1',
|
38
|
-
:base_prefix => 'base'
|
39
|
+
:base_prefix => 'base',
|
40
|
+
:extract => false
|
41
|
+
@cli_download.should_receive(:ensure_directory).
|
42
|
+
with(:config => @config_mock,
|
43
|
+
:path => '/tmp/test123').
|
44
|
+
and_return true
|
39
45
|
@cli_download.download
|
40
46
|
end
|
41
47
|
|
data/spec/cli/shared_spec.rb
CHANGED
@@ -90,6 +90,31 @@ describe Heirloom do
|
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
|
+
context "test ensure directory" do
|
94
|
+
before do
|
95
|
+
@logger_stub = mock 'logger', :error => true
|
96
|
+
@config_mock = mock 'config'
|
97
|
+
@config_mock.stub :logger => @logger_stub
|
98
|
+
@object = Object.new
|
99
|
+
@object.extend Heirloom::CLI::Shared
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should exit when path is not a directory" do
|
103
|
+
File.should_receive(:directory?).with('/tmp/test').
|
104
|
+
and_return false
|
105
|
+
lambda { @object.ensure_directory(:path => '/tmp/test',
|
106
|
+
:config => @config_mock) }.
|
107
|
+
should raise_error SystemExit
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should not exit when path is a directory" do
|
111
|
+
File.should_receive(:directory?).with('/tmp/test').
|
112
|
+
and_return true
|
113
|
+
@object.ensure_directory :path => '/tmp/test', :config => @config_mock
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
93
118
|
context "testing ensure domain" do
|
94
119
|
before do
|
95
120
|
@archive_mock = mock 'archive'
|
@@ -10,14 +10,14 @@ describe Heirloom::Directory do
|
|
10
10
|
@directory = Heirloom::Directory.new :config => @config_mock,
|
11
11
|
:exclude => ['.', '..', 'dont_pack_me'],
|
12
12
|
:path => '/target/dir'
|
13
|
+
@directory.stub :random_archive => '/tmp/dir/file.tar.gz'
|
13
14
|
output_mock = double 'output mock'
|
14
15
|
Dir.stub :tmpdir => '/tmp/dir'
|
15
|
-
Kernel.stub :rand => 0
|
16
16
|
Dir.should_receive(:entries).with('/target/dir').
|
17
17
|
exactly(2).times.
|
18
18
|
and_return(['pack_me', '.hidden', 'dont_pack_me'])
|
19
19
|
Heirloom::Directory.any_instance.should_receive(:`).
|
20
|
-
with("tar czf /tmp/dir/
|
20
|
+
with("tar czf /tmp/dir/file.tar.gz pack_me .hidden").
|
21
21
|
and_return output_mock
|
22
22
|
end
|
23
23
|
|
@@ -29,7 +29,9 @@ describe Heirloom::Directory do
|
|
29
29
|
context 'when unable to create the tar' do
|
30
30
|
before { $?.stub(:success?).and_return(false) }
|
31
31
|
|
32
|
-
it
|
32
|
+
it "should build return false" do
|
33
|
+
@directory.build_artifact_from_directory.should be_false
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Heirloom do
|
4
|
+
|
5
|
+
describe 'misc' do
|
6
|
+
before do
|
7
|
+
@object = Object.new
|
8
|
+
@object.extend Heirloom::Misc::Tmp
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return a temporary archive file" do
|
12
|
+
Kernel.stub :rand => 0
|
13
|
+
Dir.stub :tmpdir => '/tmp'
|
14
|
+
@object.random_archive.should == '/tmp/AAAAAAAA.tar.gz'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heirloom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.0rc2
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-08-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70122355909400 !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: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70122355909400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fog
|
27
|
-
requirement: &
|
27
|
+
requirement: &70122355908680 !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: *70122355908680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: grit
|
38
|
-
requirement: &
|
38
|
+
requirement: &70122355908000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70122355908000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: logger
|
49
|
-
requirement: &
|
49
|
+
requirement: &70122355907160 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70122355907160
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: trollop
|
60
|
-
requirement: &
|
60
|
+
requirement: &70122355906660 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70122355906660
|
69
69
|
description: I help build and manage building tar.gz files and deploying them into
|
70
70
|
the cloud
|
71
71
|
email:
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/heirloom/archive/builder.rb
|
93
93
|
- lib/heirloom/archive/destroyer.rb
|
94
94
|
- lib/heirloom/archive/downloader.rb
|
95
|
+
- lib/heirloom/archive/extracter.rb
|
95
96
|
- lib/heirloom/archive/lister.rb
|
96
97
|
- lib/heirloom/archive/reader.rb
|
97
98
|
- lib/heirloom/archive/updater.rb
|
@@ -118,6 +119,8 @@ files:
|
|
118
119
|
- lib/heirloom/downloader.rb
|
119
120
|
- lib/heirloom/downloader/s3.rb
|
120
121
|
- lib/heirloom/logger.rb
|
122
|
+
- lib/heirloom/misc.rb
|
123
|
+
- lib/heirloom/misc/tmp.rb
|
121
124
|
- lib/heirloom/uploader.rb
|
122
125
|
- lib/heirloom/uploader/s3.rb
|
123
126
|
- lib/heirloom/version.rb
|
@@ -127,6 +130,7 @@ files:
|
|
127
130
|
- spec/archive/builder_spec.rb
|
128
131
|
- spec/archive/destroyer_spec.rb
|
129
132
|
- spec/archive/downloader_spec.rb
|
133
|
+
- spec/archive/extracter_spec.rb
|
130
134
|
- spec/archive/lister_spec.rb
|
131
135
|
- spec/archive/reader_spec.rb
|
132
136
|
- spec/archive/updater_spec.rb
|
@@ -149,6 +153,7 @@ files:
|
|
149
153
|
- spec/directory/git_directory_spec.rb
|
150
154
|
- spec/downloader/s3_spec.rb
|
151
155
|
- spec/logger_spec.rb
|
156
|
+
- spec/misc/tmp_spec.rb
|
152
157
|
- spec/spec_helper.rb
|
153
158
|
homepage: ''
|
154
159
|
licenses: []
|
@@ -164,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
169
|
version: '0'
|
165
170
|
segments:
|
166
171
|
- 0
|
167
|
-
hash:
|
172
|
+
hash: -3832291684396607232
|
168
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
174
|
none: false
|
170
175
|
requirements:
|
@@ -183,6 +188,7 @@ test_files:
|
|
183
188
|
- spec/archive/builder_spec.rb
|
184
189
|
- spec/archive/destroyer_spec.rb
|
185
190
|
- spec/archive/downloader_spec.rb
|
191
|
+
- spec/archive/extracter_spec.rb
|
186
192
|
- spec/archive/lister_spec.rb
|
187
193
|
- spec/archive/reader_spec.rb
|
188
194
|
- spec/archive/updater_spec.rb
|
@@ -205,4 +211,5 @@ test_files:
|
|
205
211
|
- spec/directory/git_directory_spec.rb
|
206
212
|
- spec/downloader/s3_spec.rb
|
207
213
|
- spec/logger_spec.rb
|
214
|
+
- spec/misc/tmp_spec.rb
|
208
215
|
- spec/spec_helper.rb
|