heirloom 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/README.md +0 -1
- data/lib/heirloom/acl/s3.rb +10 -8
- data/lib/heirloom/artifact.rb +44 -43
- data/lib/heirloom/artifact/artifact_authorizer.rb +20 -22
- data/lib/heirloom/artifact/artifact_builder.rb +41 -37
- data/lib/heirloom/artifact/artifact_destroyer.rb +16 -14
- data/lib/heirloom/artifact/artifact_downloader.rb +22 -40
- data/lib/heirloom/artifact/artifact_lister.rb +10 -7
- data/lib/heirloom/artifact/artifact_reader.rb +17 -20
- data/lib/heirloom/artifact/artifact_updater.rb +6 -5
- data/lib/heirloom/artifact/artifact_uploader.rb +8 -8
- data/lib/heirloom/aws/s3.rb +1 -1
- data/lib/heirloom/cli.rb +37 -30
- data/lib/heirloom/cli/build.rb +40 -0
- data/lib/heirloom/cli/destroy.rb +20 -0
- data/lib/heirloom/cli/download.rb +23 -0
- data/lib/heirloom/cli/list.rb +17 -0
- data/lib/heirloom/cli/show.rb +27 -0
- data/lib/heirloom/cli/update.rb +23 -0
- data/lib/heirloom/config.rb +11 -6
- data/lib/heirloom/destroyer/s3.rb +6 -4
- data/lib/heirloom/directory/directory.rb +15 -11
- data/lib/heirloom/directory/git_directory.rb +4 -3
- data/lib/heirloom/downloader/s3.rb +1 -1
- data/lib/heirloom/logger.rb +6 -4
- data/lib/heirloom/version.rb +1 -1
- data/spec/acl/s3_spec.rb +51 -0
- data/spec/artifact/artifact_authorizer_spec.rb +34 -0
- data/spec/artifact/artifact_builder_spec.rb +41 -0
- data/spec/artifact/artifact_destroyer_spec.rb +45 -0
- data/spec/artifact/artifact_downloader_spec.rb +93 -0
- data/spec/artifact/artifact_lister_spec.rb +21 -0
- data/spec/artifact/artifact_reader_spec.rb +55 -0
- data/spec/artifact/artifact_updater_spec.rb +16 -0
- data/spec/artifact/artifact_uploader_spec.rb +16 -0
- data/spec/artifact_spec.rb +69 -19
- data/spec/aws/s3_spec.rb +55 -0
- data/spec/aws/simpledb_spec.rb +50 -0
- data/spec/config_spec.rb +32 -3
- data/spec/destroyer/s3_spec.rb +21 -0
- data/spec/directory/directory_spec.rb +26 -0
- data/spec/directory/git_directory_spec.rb +28 -0
- data/spec/downloader/s3_spec.rb +23 -0
- data/spec/logger_spec.rb +20 -0
- metadata +55 -16
@@ -4,15 +4,12 @@ module Heirloom
|
|
4
4
|
|
5
5
|
def initialize(args)
|
6
6
|
@config = args[:config]
|
7
|
+
@name = args[:name]
|
7
8
|
end
|
8
9
|
|
9
|
-
def list(
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def names
|
15
|
-
sdb.domains
|
10
|
+
def list(limit=10)
|
11
|
+
sdb.select("select * from #{@name} where built_at > '2000-01-01T00:00:00.000Z'\
|
12
|
+
order by built_at desc limit #{limit}").keys
|
16
13
|
end
|
17
14
|
|
18
15
|
private
|
@@ -21,5 +18,11 @@ module Heirloom
|
|
21
18
|
@sdb ||= AWS::SimpleDB.new :config => @config
|
22
19
|
end
|
23
20
|
|
21
|
+
def artifact_reader(id)
|
22
|
+
@artifact_reader ||= ArtifactReader.new :config => @config,
|
23
|
+
:name => @name,
|
24
|
+
:id => id
|
25
|
+
end
|
26
|
+
|
24
27
|
end
|
25
28
|
end
|
@@ -2,41 +2,38 @@ module Heirloom
|
|
2
2
|
|
3
3
|
class ArtifactReader
|
4
4
|
|
5
|
+
attr_accessor :config, :id, :name
|
6
|
+
|
5
7
|
def initialize(args)
|
6
|
-
|
8
|
+
self.config = args[:config]
|
9
|
+
self.name = args[:name]
|
10
|
+
self.id = args[:id]
|
7
11
|
end
|
8
12
|
|
9
|
-
def show
|
10
|
-
|
11
|
-
|
12
|
-
items = sdb.select "select * from #{domain} where itemName() = '#{id}'"
|
13
|
-
items[id]
|
13
|
+
def show
|
14
|
+
items = sdb.select "select * from #{name} where itemName() = '#{id}'"
|
15
|
+
items[@id]
|
14
16
|
end
|
15
17
|
|
16
|
-
def exists?
|
17
|
-
show
|
18
|
+
def exists?
|
19
|
+
show != nil
|
18
20
|
end
|
19
21
|
|
20
22
|
def get_bucket(args)
|
21
|
-
|
22
|
-
:id => args[:id]
|
23
|
-
|
24
|
-
url = artifact["#{args[:region]}-s3-url"].first
|
25
|
-
|
26
|
-
bucket = url.gsub('s3://', '').split('/').first
|
23
|
+
get_url(args).gsub('s3://', '').split('/').first
|
27
24
|
end
|
28
25
|
|
29
26
|
def get_key(args)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
url = artifact["#{args[:region]}-s3-url"].first
|
34
|
-
|
35
|
-
bucket = url.gsub('s3://', '').gsub(get_bucket(args), '')
|
27
|
+
bucket_path = get_bucket :region => args[:region]
|
28
|
+
bucket = get_url(args).gsub('s3://', '').gsub(bucket_path, '')
|
36
29
|
bucket.slice!(0)
|
37
30
|
bucket
|
38
31
|
end
|
39
32
|
|
33
|
+
def get_url(args)
|
34
|
+
show["#{args[:region]}-s3-url"].first
|
35
|
+
end
|
36
|
+
|
40
37
|
private
|
41
38
|
|
42
39
|
def sdb
|
@@ -4,17 +4,18 @@ module Heirloom
|
|
4
4
|
|
5
5
|
def initialize(args)
|
6
6
|
@config = args[:config]
|
7
|
-
@
|
7
|
+
@name = args[:name]
|
8
|
+
@id = args[:id]
|
9
|
+
|
10
|
+
@logger = @config.logger
|
8
11
|
end
|
9
12
|
|
10
13
|
def update(args)
|
11
14
|
attribute = args[:attribute]
|
12
|
-
id = args[:id]
|
13
|
-
name = args[:name]
|
14
15
|
update = args[:update]
|
15
16
|
|
16
|
-
sdb.put_attributes name, id, { attribute => update }, { :replace => attribute }
|
17
|
-
@logger.info "Updated #{name} (#{id}): #{attribute} = #{update}"
|
17
|
+
sdb.put_attributes @name, @id, { attribute => update }, { :replace => attribute }
|
18
|
+
@logger.info "Updated #{@name} (#{@id}): #{attribute} = #{update}."
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
@@ -4,15 +4,14 @@ module Heirloom
|
|
4
4
|
|
5
5
|
def initialize(args)
|
6
6
|
@config = args[:config]
|
7
|
-
@
|
7
|
+
@name = args[:name]
|
8
|
+
@id = args[:id]
|
9
|
+
@logger = @config.logger
|
8
10
|
end
|
9
11
|
|
10
12
|
def upload(args)
|
11
|
-
id = args[:id]
|
12
13
|
file = args[:file]
|
13
|
-
|
14
|
-
key_name = "#{id}.tar.gz"
|
15
|
-
name = args[:name]
|
14
|
+
key_name = "#{@id}.tar.gz"
|
16
15
|
bucket_prefix = args[:bucket_prefix]
|
17
16
|
public_readable = args[:public_readable]
|
18
17
|
|
@@ -25,12 +24,13 @@ module Heirloom
|
|
25
24
|
|
26
25
|
s3_uploader.upload_file :bucket => bucket,
|
27
26
|
:file => file,
|
28
|
-
:id => id,
|
29
|
-
:key_folder =>
|
27
|
+
:id => @id,
|
28
|
+
:key_folder => @name,
|
30
29
|
:key_name => key_name,
|
31
|
-
:name => name,
|
30
|
+
:name => @name,
|
32
31
|
:public_readable => public_readable
|
33
32
|
end
|
33
|
+
@logger.info "Upload complete."
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
data/lib/heirloom/aws/s3.rb
CHANGED
data/lib/heirloom/cli.rb
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
require 'trollop'
|
2
2
|
|
3
|
+
require 'heirloom/cli/build'
|
4
|
+
require 'heirloom/cli/list'
|
5
|
+
require 'heirloom/cli/show'
|
6
|
+
require 'heirloom/cli/update'
|
7
|
+
require 'heirloom/cli/download'
|
8
|
+
require 'heirloom/cli/destroy'
|
9
|
+
|
3
10
|
module Heirloom
|
4
11
|
module CLI
|
5
12
|
def self.start
|
6
13
|
@opts = Trollop::options do
|
14
|
+
version Heirloom::VERSION
|
7
15
|
banner <<-EOS
|
8
16
|
|
9
17
|
I build and manage artifacts
|
10
18
|
|
11
19
|
Usage:
|
12
20
|
|
13
|
-
heirloom names
|
14
21
|
heirloom list -n NAME
|
15
22
|
heirloom show -n NAME -i ID
|
16
23
|
heirloom build -n NAME -i ID -b BUCKET_PREFIX [-d DIRECTORY] [-p] [-g]
|
@@ -28,6 +35,8 @@ EOS
|
|
28
35
|
:default => '.git'
|
29
36
|
opt :git, "Read git commit information from directory."
|
30
37
|
opt :id, "Id of artifact.", :type => :string
|
38
|
+
opt :limit, "Limit the results returned by list.", :type => :integer,
|
39
|
+
:default => 10
|
31
40
|
opt :name, "Name of artifact.", :type => :string
|
32
41
|
opt :output, "Output download to file.", :type => :string
|
33
42
|
opt :public, "Set this artifact as public readable?"
|
@@ -37,43 +46,41 @@ EOS
|
|
37
46
|
end
|
38
47
|
|
39
48
|
cmd = ARGV.shift
|
40
|
-
a = Artifact.new :config => nil
|
41
49
|
|
42
50
|
case cmd
|
43
|
-
when 'names'
|
44
|
-
puts a.names
|
45
51
|
when 'list'
|
46
|
-
|
47
|
-
|
48
|
-
puts a.names
|
49
|
-
exit 1
|
50
|
-
end
|
51
|
-
puts a.list :name => @opts[:name]
|
52
|
+
cli_list = CLI::List.new :name => @opts[:name]
|
53
|
+
cli_list.list @opts[:limit]
|
52
54
|
when 'show'
|
53
|
-
|
54
|
-
|
55
|
+
cli_show = CLI::Show.new :name => @opts[:name],
|
56
|
+
:id => @opts[:id]
|
57
|
+
cli_show.show
|
55
58
|
when 'build'
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
cli_build = CLI::Build.new :name => @opts[:name],
|
60
|
+
:id => @opts[:id],
|
61
|
+
:accounts => @opts[:accounts],
|
62
|
+
:bucket_prefix => @opts[:bucket_prefix],
|
63
|
+
:directory => @opts[:directory],
|
64
|
+
:exclude => @opts[:exclude],
|
65
|
+
:public => @opts[:public],
|
66
|
+
:git => @opts[:git]
|
67
|
+
cli_build.build
|
64
68
|
when 'update'
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
cli_update = CLI::Update.new :name => @opts[:name],
|
70
|
+
:id => @opts[:id],
|
71
|
+
:attribute => @opts[:attribute],
|
72
|
+
:update => @opts[:update]
|
73
|
+
cli_update.update
|
69
74
|
when 'download'
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
75
|
+
cli_download = CLI::Download.new :name => @opts[:name],
|
76
|
+
:id => @opts[:id],
|
77
|
+
:output => @opts[:output],
|
78
|
+
:region => @opts[:region]
|
79
|
+
cli_download.download
|
74
80
|
when 'destroy', 'delete'
|
75
|
-
|
76
|
-
|
81
|
+
cli_destroy = CLI::Destroy.new :name => @opts[:name],
|
82
|
+
:id => @opts[:id]
|
83
|
+
cli_destroy.destroy
|
77
84
|
else
|
78
85
|
puts "Unkown command: '#{cmd}'."
|
79
86
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Heirloom
|
2
|
+
module CLI
|
3
|
+
class Build
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@name = args[:name]
|
7
|
+
@id = args[:id]
|
8
|
+
@accounts = args[:accounts]
|
9
|
+
@bucket_prefix = args[:bucket_prefix]
|
10
|
+
@directory = args[:directory]
|
11
|
+
@exclude = args[:exclude].split(',')
|
12
|
+
@public = args[:public]
|
13
|
+
@git = args[:git]
|
14
|
+
@logger = args[:logger]
|
15
|
+
@artifact = Artifact.new :name => @name,
|
16
|
+
:id => @id,
|
17
|
+
:logger => @logger
|
18
|
+
end
|
19
|
+
|
20
|
+
def build
|
21
|
+
@artifact.destroy if @artifact.exists?
|
22
|
+
|
23
|
+
file = @artifact.build :accounts => @accounts,
|
24
|
+
:bucket_prefix => @bucket_prefix,
|
25
|
+
:directory => @directory,
|
26
|
+
:exclude => @exclude,
|
27
|
+
:public => @public,
|
28
|
+
:git => @git
|
29
|
+
|
30
|
+
@artifact.upload :bucket_prefix => @bucket_prefix,
|
31
|
+
:file => file
|
32
|
+
|
33
|
+
@artifact.authorize unless @public
|
34
|
+
|
35
|
+
@artifact.cleanup
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Heirloom
|
2
|
+
module CLI
|
3
|
+
class Destroy
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@name = args[:name]
|
7
|
+
@id = args[:id]
|
8
|
+
@logger = args[:logger]
|
9
|
+
@artifact = Artifact.new :name => @name,
|
10
|
+
:id => @id,
|
11
|
+
:logger => @logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def destroy
|
15
|
+
@artifact.destroy
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Heirloom
|
2
|
+
module CLI
|
3
|
+
class Download
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@name = args[:name]
|
7
|
+
@id = args[:id]
|
8
|
+
@output = args[:output]
|
9
|
+
@region = args[:region]
|
10
|
+
@logger = args[:logger]
|
11
|
+
@artifact = Artifact.new :name => @name,
|
12
|
+
:id => @id,
|
13
|
+
:logger => @logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def download
|
17
|
+
@artifact.download :output => @output,
|
18
|
+
:region => @region
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Heirloom
|
2
|
+
module CLI
|
3
|
+
class List
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@artifact = Artifact.new :name => args[:name],
|
7
|
+
:logger => args[:logger]
|
8
|
+
end
|
9
|
+
|
10
|
+
def list(limit)
|
11
|
+
@logger = Logger
|
12
|
+
puts @artifact.list(limit)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Heirloom
|
2
|
+
module CLI
|
3
|
+
class Show
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
id = args[:id] ? args[:id] : latest_id(args)
|
7
|
+
@artifact = Artifact.new :name => args[:name],
|
8
|
+
:id => id,
|
9
|
+
:logger => args[:logger]
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@logger = Logger
|
14
|
+
puts @artifact.show.to_yaml
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def latest_id(args)
|
20
|
+
@artifact = Artifact.new :name => args[:name],
|
21
|
+
:logger => args[:logger]
|
22
|
+
@artifact.list(1).first
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Heirloom
|
2
|
+
module CLI
|
3
|
+
class Update
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@name = args[:name]
|
7
|
+
@id = args[:id]
|
8
|
+
@logger = args[:logger]
|
9
|
+
@attribute = args[:attribute]
|
10
|
+
@update = args[:update]
|
11
|
+
@artifact = Artifact.new :name => @name,
|
12
|
+
:id => @id,
|
13
|
+
:logger => @logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
@artifact.update :attribute => @attribute,
|
18
|
+
:update => @update
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/heirloom/config.rb
CHANGED
@@ -2,7 +2,8 @@ module Heirloom
|
|
2
2
|
class Config
|
3
3
|
|
4
4
|
attr_accessor :access_key, :secret_key, :regions,
|
5
|
-
:primary_region, :bucket_prefix, :authorized_aws_accounts
|
5
|
+
:primary_region, :bucket_prefix, :authorized_aws_accounts,
|
6
|
+
:logger
|
6
7
|
|
7
8
|
def initialize(args = {})
|
8
9
|
@config = args[:config]
|
@@ -13,12 +14,16 @@ module Heirloom
|
|
13
14
|
config_file = "#{ENV['HOME']}/.heirloom.yml"
|
14
15
|
c = @config ? @config : YAML::load( File.open( config_file ) )
|
15
16
|
|
16
|
-
self.
|
17
|
-
|
18
|
-
|
17
|
+
self.logger = c['logger'] ||= HeirloomLogger.new
|
18
|
+
|
19
|
+
aws = c['aws']
|
20
|
+
|
21
|
+
self.access_key = aws['access_key']
|
22
|
+
self.secret_key = aws['secret_key']
|
23
|
+
self.regions = aws['regions']
|
24
|
+
self.bucket_prefix = aws['bucket_prefix']
|
25
|
+
self.authorized_aws_accounts = aws['authorized_aws_accounts']
|
19
26
|
self.primary_region = regions ? regions.first : 'us-west-1'
|
20
|
-
self.bucket_prefix = c['aws']['bucket_prefix']
|
21
|
-
self.authorized_aws_accounts = c['aws']['authorized_aws_accounts']
|
22
27
|
end
|
23
28
|
|
24
29
|
end
|