heirloom 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README.md +1 -1
- data/Rakefile +6 -0
- data/lib/heirloom/archive/builder.rb +29 -29
- data/lib/heirloom/archive/destroyer.rb +27 -18
- data/lib/heirloom/archive/downloader.rb +12 -14
- data/lib/heirloom/archive/lister.rb +2 -1
- data/lib/heirloom/archive/reader.rb +22 -15
- data/lib/heirloom/archive/updater.rb +2 -1
- data/lib/heirloom/archive.rb +5 -2
- data/lib/heirloom/aws/simpledb.rb +15 -2
- data/lib/heirloom/cli/authorize.rb +12 -7
- data/lib/heirloom/cli/build.rb +29 -20
- data/lib/heirloom/cli/destroy.rb +11 -4
- data/lib/heirloom/cli/download.rb +11 -4
- data/lib/heirloom/cli/list.rb +15 -6
- data/lib/heirloom/cli/shared.rb +10 -1
- data/lib/heirloom/cli/show.rb +14 -5
- data/lib/heirloom/cli/update.rb +14 -6
- data/lib/heirloom/cli.rb +1 -2
- data/lib/heirloom/directory/directory.rb +16 -18
- data/lib/heirloom/directory/git_directory.rb +1 -1
- data/lib/heirloom/uploader/s3.rb +4 -3
- data/lib/heirloom/version.rb +1 -1
- data/spec/archive/builder_spec.rb +60 -58
- data/spec/archive/destroyer_spec.rb +9 -10
- data/spec/archive/downloader_spec.rb +2 -2
- data/spec/archive/lister_spec.rb +1 -1
- data/spec/archive/reader_spec.rb +92 -81
- data/spec/archive/updater_spec.rb +1 -1
- data/spec/archive_spec.rb +15 -6
- data/spec/aws/simpledb_spec.rb +35 -0
- data/spec/cli/authorize_spec.rb +34 -0
- data/spec/cli/build_spec.rb +57 -0
- data/spec/cli/destroy_spec.rb +33 -0
- data/spec/cli/download_spec.rb +37 -0
- data/spec/cli/list_spec.rb +34 -0
- data/spec/cli/shared_spec.rb +68 -34
- data/spec/cli/show_spec.rb +34 -0
- data/spec/cli/update_spec.rb +37 -0
- data/spec/directory/directory_spec.rb +13 -20
- data/spec/directory/git_directory_spec.rb +23 -22
- metadata +28 -14
data/lib/heirloom/cli/list.rb
CHANGED
@@ -2,17 +2,24 @@ module Heirloom
|
|
2
2
|
module CLI
|
3
3
|
class List
|
4
4
|
|
5
|
+
include Heirloom::CLI::Shared
|
6
|
+
|
5
7
|
def initialize
|
6
8
|
@opts = read_options
|
7
9
|
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
@config = load_config :logger => @logger,
|
11
|
+
:opts => @opts
|
12
|
+
|
13
|
+
exit 1 unless valid_options? :provided => @opts,
|
14
|
+
:required => [:name],
|
15
|
+
:logger => @logger
|
16
|
+
|
11
17
|
@archive = Archive.new :name => @opts[:name],
|
12
|
-
:
|
18
|
+
:config => @config
|
13
19
|
end
|
14
20
|
|
15
21
|
def list(count = @opts[:count])
|
22
|
+
@logger.debug "#{@archive.count} archives found."
|
16
23
|
jj @archive.list(count)
|
17
24
|
end
|
18
25
|
|
@@ -30,12 +37,14 @@ Usage:
|
|
30
37
|
heirloom list -n NAME
|
31
38
|
|
32
39
|
EOS
|
40
|
+
opt :count, "Number of versions to return.", :type => :integer,
|
41
|
+
:default => 10
|
33
42
|
opt :help, "Display Help"
|
43
|
+
opt :key, "AWS Access Key ID", :type => :string
|
34
44
|
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
35
45
|
:default => 'info'
|
36
46
|
opt :name, "Name of archive.", :type => :string
|
37
|
-
opt :
|
38
|
-
:default => 10
|
47
|
+
opt :secret, "AWS Secret Access Key", :type => :string
|
39
48
|
end
|
40
49
|
end
|
41
50
|
|
data/lib/heirloom/cli/shared.rb
CHANGED
@@ -2,7 +2,7 @@ module Heirloom
|
|
2
2
|
module CLI
|
3
3
|
module Shared
|
4
4
|
|
5
|
-
def
|
5
|
+
def valid_options?(args)
|
6
6
|
provided = args[:provided]
|
7
7
|
required = args[:required]
|
8
8
|
logger = args[:logger]
|
@@ -23,6 +23,15 @@ module Heirloom
|
|
23
23
|
missing_opts.empty?
|
24
24
|
end
|
25
25
|
|
26
|
+
def load_config(args)
|
27
|
+
opts = args[:opts]
|
28
|
+
logger = args[:logger]
|
29
|
+
config = Config.new :logger => logger
|
30
|
+
config.access_key = opts[:key] if opts[:key_given]
|
31
|
+
config.secret_key = opts[:secret] if opts[:secret_given]
|
32
|
+
config
|
33
|
+
end
|
34
|
+
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
data/lib/heirloom/cli/show.rb
CHANGED
@@ -2,15 +2,21 @@ module Heirloom
|
|
2
2
|
module CLI
|
3
3
|
class Show
|
4
4
|
|
5
|
+
include Heirloom::CLI::Shared
|
6
|
+
|
5
7
|
def initialize
|
6
8
|
@opts = read_options
|
7
9
|
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
@config = load_config :logger => @logger,
|
11
|
+
:opts => @opts
|
12
|
+
|
13
|
+
exit 1 unless valid_options? :provided => @opts,
|
14
|
+
:required => [:name],
|
15
|
+
:logger => @logger
|
16
|
+
|
11
17
|
id = @opts[:id] ? @opts[:id] : latest_id
|
12
18
|
@archive = Archive.new :name => @opts[:name],
|
13
|
-
:
|
19
|
+
:config => @config,
|
14
20
|
:id => id
|
15
21
|
end
|
16
22
|
|
@@ -21,7 +27,8 @@ module Heirloom
|
|
21
27
|
private
|
22
28
|
|
23
29
|
def latest_id
|
24
|
-
@archive = Archive.new :name
|
30
|
+
@archive = Archive.new :name => @opts[:name],
|
31
|
+
:config => @config
|
25
32
|
@archive.list(1).first
|
26
33
|
end
|
27
34
|
|
@@ -40,10 +47,12 @@ If -i is ommited, latest version is displayed.
|
|
40
47
|
|
41
48
|
EOS
|
42
49
|
opt :help, "Display Help"
|
50
|
+
opt :key, "AWS Access Key ID", :type => :string
|
43
51
|
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
44
52
|
:default => 'info'
|
45
53
|
opt :name, "Name of archive.", :type => :string
|
46
54
|
opt :id, "id of the archive to display.", :type => :string
|
55
|
+
opt :secret, "AWS Secret Access Key", :type => :string
|
47
56
|
end
|
48
57
|
end
|
49
58
|
|
data/lib/heirloom/cli/update.rb
CHANGED
@@ -2,17 +2,23 @@ module Heirloom
|
|
2
2
|
module CLI
|
3
3
|
class Update
|
4
4
|
|
5
|
+
include Heirloom::CLI::Shared
|
6
|
+
|
5
7
|
def initialize
|
6
8
|
@opts = read_options
|
7
9
|
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
@config = load_config :logger => @logger,
|
11
|
+
:opts => @opts
|
12
|
+
|
13
|
+
exit 1 unless valid_options? :provided => @opts,
|
14
|
+
:required => [:name, :id,
|
15
|
+
:attribute,
|
16
|
+
:updated_value],
|
17
|
+
:logger => @logger
|
18
|
+
|
13
19
|
@archive = Archive.new :name => @opts[:name],
|
14
20
|
:id => @opts[:id],
|
15
|
-
:
|
21
|
+
:config => @config
|
16
22
|
end
|
17
23
|
|
18
24
|
def update
|
@@ -37,9 +43,11 @@ EOS
|
|
37
43
|
opt :attribute, "Attribute to update.", :type => :string
|
38
44
|
opt :help, "Display Help"
|
39
45
|
opt :id, "ID of the archive to display.", :type => :string
|
46
|
+
opt :key, "AWS Access Key ID", :type => :string
|
40
47
|
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
41
48
|
:default => 'info'
|
42
49
|
opt :name, "Name of archive.", :type => :string
|
50
|
+
opt :secret, "AWS Secret Access Key", :type => :string
|
43
51
|
opt :updated_value, "Updated value of attribute.", :type => :string
|
44
52
|
end
|
45
53
|
end
|
data/lib/heirloom/cli.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'trollop'
|
2
2
|
|
3
|
+
require 'heirloom/cli/shared'
|
3
4
|
require 'heirloom/cli/authorize'
|
4
5
|
require 'heirloom/cli/build'
|
5
6
|
require 'heirloom/cli/list'
|
@@ -8,8 +9,6 @@ require 'heirloom/cli/update'
|
|
8
9
|
require 'heirloom/cli/download'
|
9
10
|
require 'heirloom/cli/destroy'
|
10
11
|
|
11
|
-
require 'heirloom/cli/shared'
|
12
|
-
|
13
12
|
module Heirloom
|
14
13
|
module CLI
|
15
14
|
def self.start
|
@@ -4,41 +4,39 @@ module Heirloom
|
|
4
4
|
|
5
5
|
class Directory
|
6
6
|
|
7
|
-
|
7
|
+
attr_reader :local_build
|
8
8
|
|
9
9
|
def initialize(args)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
@config = args[:config]
|
11
|
+
@exclude = args[:exclude]
|
12
|
+
@path = args[:path]
|
13
|
+
@logger = @config.logger
|
14
14
|
end
|
15
15
|
|
16
16
|
def build_artifact_from_directory
|
17
17
|
random_text = (0...8).map{65.+(Kernel.rand(25)).chr}.join
|
18
18
|
|
19
|
-
|
20
|
-
self.local_build = File.join(Dir.tmpdir, random_text + ".tar.gz")
|
21
|
-
end
|
19
|
+
@local_build = File.join(Dir.tmpdir, random_text + ".tar.gz")
|
22
20
|
|
23
|
-
logger.info "Building Heirloom '#{local_build}' from '#{path}'."
|
24
|
-
logger.info "Excluding #{exclude.to_s}."
|
25
|
-
logger.info "Adding #{files_to_pack.to_s}."
|
21
|
+
@logger.info "Building Heirloom '#{@local_build}' from '#{@path}'."
|
22
|
+
@logger.info "Excluding #{@exclude.to_s}."
|
23
|
+
@logger.info "Adding #{files_to_pack.to_s}."
|
26
24
|
|
27
|
-
build_archive
|
25
|
+
build_archive
|
28
26
|
end
|
29
27
|
|
30
28
|
private
|
31
29
|
|
32
|
-
def build_archive
|
33
|
-
command = "tar czf #{local_build} #{files_to_pack.join(' ')}"
|
34
|
-
logger.info "Archiving with: `#{command}`"
|
30
|
+
def build_archive
|
31
|
+
command = "tar czf #{@local_build} #{files_to_pack.join(' ')}"
|
32
|
+
@logger.info "Archiving with: `#{command}`"
|
35
33
|
output = `#{command}`
|
36
|
-
logger.debug "Exited with status: '#{$?.exitstatus}' ouput: '#{output}'"
|
34
|
+
@logger.debug "Exited with status: '#{$?.exitstatus}' ouput: '#{output}'"
|
37
35
|
$?.success?
|
38
36
|
end
|
39
|
-
|
37
|
+
|
40
38
|
def files_to_pack
|
41
|
-
Dir.entries(path) - ['.', '..'] - exclude
|
39
|
+
Dir.entries(@path) - ['.', '..'] - @exclude
|
42
40
|
end
|
43
41
|
|
44
42
|
end
|
data/lib/heirloom/uploader/s3.rb
CHANGED
@@ -32,6 +32,7 @@ module Heirloom
|
|
32
32
|
bucket = args[:bucket]
|
33
33
|
id = args[:id]
|
34
34
|
name = args[:name]
|
35
|
+
domain = "heirloom_#{name}"
|
35
36
|
key_folder = name
|
36
37
|
key_name = "#{id}.tar.gz"
|
37
38
|
|
@@ -39,13 +40,13 @@ module Heirloom
|
|
39
40
|
http_endpoint = "http://#{endpoints[@region]}/#{bucket}/#{key_folder}/#{key_name}"
|
40
41
|
https_endpoint = "https://#{endpoints[@region]}/#{bucket}/#{key_folder}/#{key_name}"
|
41
42
|
|
42
|
-
sdb.put_attributes
|
43
|
+
sdb.put_attributes domain, id, { "#{@region}-s3-url" => s3_endpoint }
|
43
44
|
@logger.info "Adding attribute #{s3_endpoint}."
|
44
45
|
|
45
|
-
sdb.put_attributes
|
46
|
+
sdb.put_attributes domain, id, { "#{@region}-http-url" => http_endpoint }
|
46
47
|
@logger.info "Adding attribute #{http_endpoint}."
|
47
48
|
|
48
|
-
sdb.put_attributes
|
49
|
+
sdb.put_attributes domain, id, { "#{@region}-https-url" => https_endpoint }
|
49
50
|
@logger.info "Adding attribute #{https_endpoint}."
|
50
51
|
end
|
51
52
|
|
data/lib/heirloom/version.rb
CHANGED
@@ -1,70 +1,68 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Heirloom do
|
3
|
+
describe Heirloom::Builder do
|
4
|
+
before do
|
5
|
+
@config_mock = double 'config'
|
6
|
+
@logger_stub = stub :debug => 'true', :info => 'true', :warn => 'true'
|
7
|
+
@config_mock.stub(:logger).and_return(@logger_stub)
|
8
|
+
@simpledb_mock = double 'simple db'
|
9
|
+
Heirloom::AWS::SimpleDB.should_receive(:new).with(:config => @config_mock).
|
10
|
+
and_return(@simpledb_mock)
|
11
|
+
@simpledb_mock.should_receive(:create_domain).with 'heirloom_tim'
|
12
|
+
@builder = Heirloom::Builder.new :config => @config_mock,
|
13
|
+
:name => 'tim',
|
14
|
+
:id => '123'
|
15
|
+
end
|
4
16
|
|
17
|
+
describe 'build' do
|
5
18
|
before do
|
6
|
-
@
|
7
|
-
@
|
8
|
-
|
9
|
-
@
|
10
|
-
Heirloom::AWS::SimpleDB.should_receive(:new).with(:config => @config_mock).
|
11
|
-
and_return(@simpledb_mock)
|
12
|
-
@simpledb_mock.should_receive(:create_domain).with 'tim'
|
13
|
-
@builder = Heirloom::Builder.new :config => @config_mock,
|
14
|
-
:name => 'tim',
|
15
|
-
:id => '123'
|
19
|
+
@author_stub = stub :name => 'weaver'
|
20
|
+
@directory_stub = stub :build_artifact_from_directory => '/tmp/build_dir',
|
21
|
+
:local_build => '/var/tmp/file.tar.gz'
|
22
|
+
@git_dir_mock = double "git directory mock"
|
16
23
|
end
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@builder.should_receive(:create_artifact_record)
|
31
|
-
Heirloom::GitDirectory.should_receive(:new).
|
32
|
-
with(:path => 'path_to_build').
|
33
|
-
and_return git_dir_mock
|
34
|
-
git_dir_mock.should_receive(:commit).
|
35
|
-
with('123').and_return git_commit_stub
|
36
|
-
commit_attributes = { 'sha' => '123',
|
37
|
-
'abbreviated_sha' => 'abc123',
|
38
|
-
'message' => 'yoyo',
|
39
|
-
'author' => 'weaver' }
|
40
|
-
@simpledb_mock.should_receive(:put_attributes).
|
41
|
-
with('tim', '123', commit_attributes)
|
25
|
+
context 'when successful' do
|
26
|
+
before do
|
27
|
+
Heirloom::Directory.should_receive(:new).
|
28
|
+
with(:path => 'path_to_build',
|
29
|
+
:exclude => ['.dir_to_exclude'],
|
30
|
+
:config => @config_mock).
|
31
|
+
and_return @directory_stub
|
32
|
+
Heirloom::GitDirectory.should_receive(:new).
|
33
|
+
with(:path => 'path_to_build').
|
34
|
+
and_return @git_dir_mock
|
35
|
+
@builder.should_receive(:create_artifact_record)
|
36
|
+
end
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
it "should build an archive" do
|
39
|
+
git_commit_stub = stub :id_abbrev => 'abc123',
|
40
|
+
:message => 'yoyo',
|
41
|
+
:author => @author_stub
|
42
|
+
@git_dir_mock.should_receive(:commit).
|
43
|
+
with('123').and_return git_commit_stub
|
44
|
+
commit_attributes = { 'sha' => '123',
|
45
|
+
'abbreviated_sha' => 'abc123',
|
46
|
+
'message' => 'yoyo',
|
47
|
+
'author' => 'weaver' }
|
48
|
+
@simpledb_mock.should_receive(:put_attributes).
|
49
|
+
with('heirloom_tim', '123', commit_attributes)
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
git_dir_mock.should_receive(:commit).
|
62
|
-
with('123').and_return false
|
63
|
-
@builder.build(:exclude => ['.dir_to_exclude'],
|
64
|
-
:directory => 'path_to_build',
|
65
|
-
:git => 'true').should == '/var/tmp/file.tar.gz'
|
66
|
-
end
|
51
|
+
@builder.build(:exclude => ['.dir_to_exclude'],
|
52
|
+
:directory => 'path_to_build',
|
53
|
+
:git => 'true').should == '/var/tmp/file.tar.gz'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should build an archive and log a warning if the git sha is not found" do
|
57
|
+
@logger_stub.should_receive(:warn).with "Could not find Git sha: 123."
|
58
|
+
@git_dir_mock.should_receive(:commit).
|
59
|
+
with('123').and_return false
|
60
|
+
@builder.build(:exclude => ['.dir_to_exclude'],
|
61
|
+
:directory => 'path_to_build',
|
62
|
+
:git => 'true').should == '/var/tmp/file.tar.gz'
|
63
|
+
end
|
67
64
|
|
65
|
+
end
|
68
66
|
|
69
67
|
it "should return false if the build fails" do
|
70
68
|
directory_stub = stub :build_artifact_from_directory => false
|
@@ -77,10 +75,14 @@ describe Heirloom do
|
|
77
75
|
:git => 'true').should be_false
|
78
76
|
end
|
79
77
|
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'cleanup' do
|
80
81
|
it "should cleanup the local archive" do
|
81
82
|
@builder.local_build = '/tmp/file'
|
82
83
|
File.should_receive(:delete).with('/tmp/file')
|
83
84
|
@builder.cleanup
|
84
85
|
end
|
86
|
+
end
|
85
87
|
|
86
88
|
end
|
@@ -7,13 +7,12 @@ describe Heirloom do
|
|
7
7
|
@logger_mock = double 'logger'
|
8
8
|
@config_mock.should_receive(:logger).and_return(@logger_mock)
|
9
9
|
@destroyer = Heirloom::Destroyer.new :config => @config_mock,
|
10
|
-
|
11
|
-
|
10
|
+
:name => 'tim',
|
11
|
+
:id => '123'
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should destroy the given archive" do
|
15
|
-
@logger_mock.
|
16
|
-
with "Destroying tim - 123"
|
15
|
+
@logger_mock.stub :info => true
|
17
16
|
reader_mock = mock 'archive reader'
|
18
17
|
@destroyer.should_receive(:reader).and_return reader_mock
|
19
18
|
bucket_mock = mock 'bucket'
|
@@ -21,8 +20,6 @@ describe Heirloom do
|
|
21
20
|
with(:region => 'us-west-1').
|
22
21
|
and_return 'bucket-us-west-1'
|
23
22
|
|
24
|
-
@logger_mock.should_receive(:info).
|
25
|
-
with "Destroying 's3://bucket-us-west-1/tim/123.tar.gz'."
|
26
23
|
|
27
24
|
s3_destroyer_mock = mock 's3 destroyer'
|
28
25
|
Heirloom::Destroyer::S3.should_receive(:new).
|
@@ -34,10 +31,12 @@ describe Heirloom do
|
|
34
31
|
:key_folder => 'tim',
|
35
32
|
:bucket => 'bucket-us-west-1'
|
36
33
|
sdb_mock = mock 'sdb'
|
37
|
-
@destroyer.
|
38
|
-
sdb_mock.should_receive(:delete).with '
|
39
|
-
|
40
|
-
|
34
|
+
@destroyer.stub :sdb => sdb_mock
|
35
|
+
sdb_mock.should_receive(:delete).with 'heirloom_tim', '123'
|
36
|
+
Kernel.should_receive(:sleep).with 3
|
37
|
+
sdb_mock.should_receive(:domain_empty?).with('heirloom_tim').
|
38
|
+
and_return true
|
39
|
+
sdb_mock.should_receive(:delete_domain).with('heirloom_tim')
|
41
40
|
@destroyer.destroy :regions => ['us-west-1']
|
42
41
|
end
|
43
42
|
|
@@ -7,8 +7,8 @@ describe Heirloom do
|
|
7
7
|
@logger_mock = double 'logger'
|
8
8
|
@config_mock.should_receive(:logger).and_return(@logger_mock)
|
9
9
|
@downloader = Heirloom::Downloader.new :config => @config_mock,
|
10
|
-
|
11
|
-
|
10
|
+
:name => 'tim',
|
11
|
+
:id => '123'
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should download an archive" do
|
data/spec/archive/lister_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Heirloom do
|
|
12
12
|
sdb_mock = mock 'sdb'
|
13
13
|
@lister.should_receive(:sdb).and_return sdb_mock
|
14
14
|
sdb_mock.should_receive(:select).
|
15
|
-
with("select * from
|
15
|
+
with("select * from heirloom_test123 where built_at > '2000-01-01T00:00:00.000Z' \
|
16
16
|
order by built_at desc limit 10").
|
17
17
|
and_return( {'1' => 'one', '2' => 'two', '3' => 'three'} )
|
18
18
|
@lister.list.should == ['1', '2', '3']
|