heirloom 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/heirloom.rb +3 -1
- data/lib/heirloom/acl/s3.rb +2 -1
- data/lib/heirloom/artifact.rb +40 -20
- data/lib/heirloom/artifact/artifact_authorizer.rb +3 -1
- data/lib/heirloom/artifact/artifact_builder.rb +36 -7
- data/lib/heirloom/artifact/artifact_downloader.rb +59 -0
- data/lib/heirloom/artifact/artifact_lister.rb +2 -2
- data/lib/heirloom/artifact/artifact_reader.rb +3 -2
- data/lib/heirloom/artifact/artifact_updater.rb +27 -0
- data/lib/heirloom/artifact/artifact_uploader.rb +10 -32
- data/lib/heirloom/aws/s3.rb +4 -0
- data/lib/heirloom/aws/simpledb.rb +2 -2
- data/lib/heirloom/cli.rb +46 -16
- data/lib/heirloom/directory.rb +1 -0
- data/lib/heirloom/directory/directory.rb +39 -0
- data/lib/heirloom/directory/git_directory.rb +0 -15
- data/lib/heirloom/downloader.rb +1 -0
- data/lib/heirloom/downloader/s3.rb +21 -0
- data/lib/heirloom/logger.rb +19 -0
- data/lib/heirloom/uploader/s3.rb +46 -1
- data/lib/heirloom/version.rb +1 -1
- metadata +22 -16
data/lib/heirloom.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require "heirloom/acl"
|
2
2
|
require "heirloom/aws"
|
3
|
-
require "heirloom/artifact"
|
4
3
|
require "heirloom/config"
|
4
|
+
require "heirloom/logger"
|
5
|
+
require "heirloom/artifact"
|
5
6
|
require "heirloom/directory"
|
6
7
|
require "heirloom/uploader"
|
8
|
+
require "heirloom/downloader"
|
7
9
|
require "heirloom/destroyer"
|
8
10
|
require "heirloom/version"
|
data/lib/heirloom/acl/s3.rb
CHANGED
@@ -16,10 +16,11 @@ module Heirloom
|
|
16
16
|
|
17
17
|
key = "#{key_folder}/#{key_name}.tar.gz"
|
18
18
|
|
19
|
-
current_acls = s3.get_bucket_acl
|
19
|
+
current_acls = s3.get_bucket_acl bucket
|
20
20
|
|
21
21
|
name = current_acls['Owner']['Name']
|
22
22
|
id = current_acls['Owner']['ID']
|
23
|
+
|
23
24
|
grants = build_bucket_grants :id => id,
|
24
25
|
:name => name,
|
25
26
|
:accounts => @accounts
|
data/lib/heirloom/artifact.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'heirloom/artifact/artifact_lister.rb'
|
2
2
|
require 'heirloom/artifact/artifact_reader.rb'
|
3
3
|
require 'heirloom/artifact/artifact_builder.rb'
|
4
|
+
require 'heirloom/artifact/artifact_updater.rb'
|
4
5
|
require 'heirloom/artifact/artifact_uploader.rb'
|
6
|
+
require 'heirloom/artifact/artifact_downloader.rb'
|
5
7
|
require 'heirloom/artifact/artifact_authorizer.rb'
|
6
8
|
require 'heirloom/artifact/artifact_destroyer.rb'
|
7
9
|
|
@@ -11,48 +13,56 @@ module Heirloom
|
|
11
13
|
|
12
14
|
def initialize(args)
|
13
15
|
@config = Config.new :config => args[:config]
|
14
|
-
@logger = args[:logger]
|
15
|
-
|
16
|
-
@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
17
|
-
@logger.formatter = proc do |severity, datetime, progname, msg|
|
18
|
-
"#{datetime}: #{msg}\n"
|
19
|
-
end
|
16
|
+
@logger = HeirloomLogger.new :logger => args[:logger]
|
20
17
|
end
|
21
18
|
|
22
19
|
def build(args)
|
23
|
-
if artifact_reader.exists?
|
20
|
+
if artifact_reader.exists? args
|
24
21
|
@logger.info "Destroying existing artifact."
|
25
22
|
destroy(args)
|
26
23
|
end
|
27
24
|
|
28
|
-
file = artifact_builder.build
|
25
|
+
file = artifact_builder.build args
|
29
26
|
|
30
27
|
artifact_uploader.upload :id => args[:id],
|
31
28
|
:name => args[:name],
|
32
|
-
:
|
33
|
-
:
|
29
|
+
:public_readable => args[:public],
|
30
|
+
:file => file
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
artifact_authorizer.authorize :id => args[:id],
|
33
|
+
:name => args[:name],
|
34
|
+
:public_readable => args[:public]
|
35
|
+
|
36
|
+
artifact_builder.cleanup
|
37
|
+
|
38
|
+
@logger.info "Artifact build completed."
|
39
|
+
end
|
40
|
+
|
41
|
+
def update(args)
|
42
|
+
artifact_updater.update(args)
|
43
|
+
@logger.info "Artifact update completed."
|
44
|
+
end
|
45
|
+
|
46
|
+
def download(args)
|
47
|
+
artifact_downloader.download(args)
|
48
|
+
@logger.info "Artifact download completed."
|
40
49
|
end
|
41
50
|
|
42
51
|
def destroy(args)
|
43
52
|
artifact_destroyer.destroy(args)
|
53
|
+
@logger.info "Artifact destroyed."
|
44
54
|
end
|
45
55
|
|
46
56
|
def show(args)
|
47
|
-
artifact_reader.show(args)
|
57
|
+
artifact_reader.show(args)
|
48
58
|
end
|
49
59
|
|
50
|
-
def
|
51
|
-
artifact_lister.
|
60
|
+
def list(args)
|
61
|
+
artifact_lister.list(args)
|
52
62
|
end
|
53
63
|
|
54
|
-
def
|
55
|
-
artifact_lister.
|
64
|
+
def names
|
65
|
+
artifact_lister.names
|
56
66
|
end
|
57
67
|
|
58
68
|
private
|
@@ -70,11 +80,21 @@ module Heirloom
|
|
70
80
|
:logger => @logger
|
71
81
|
end
|
72
82
|
|
83
|
+
def artifact_updater
|
84
|
+
@artifact_updater ||= ArtifactUpdater.new :config => @config,
|
85
|
+
:logger => @logger
|
86
|
+
end
|
87
|
+
|
73
88
|
def artifact_uploader
|
74
89
|
@artifact_uploader ||= ArtifactUploader.new :config => @config,
|
75
90
|
:logger => @logger
|
76
91
|
end
|
77
92
|
|
93
|
+
def artifact_downloader
|
94
|
+
@artifact_downloader ||= ArtifactDownloader.new :config => @config,
|
95
|
+
:logger => @logger
|
96
|
+
end
|
97
|
+
|
78
98
|
def artifact_authorizer
|
79
99
|
@artifact_authorizer ||= ArtifactAuthorizer.new :config => @config,
|
80
100
|
:logger => @logger
|
@@ -12,7 +12,9 @@ module Heirloom
|
|
12
12
|
name = args[:name]
|
13
13
|
public_readable = args[:public_readable]
|
14
14
|
|
15
|
-
unless
|
15
|
+
unless public_readable
|
16
|
+
@logger.info "Authorizing access to artifact."
|
17
|
+
|
16
18
|
@config.regions.each do |region|
|
17
19
|
bucket = "#{@config.bucket_prefix}-#{region}"
|
18
20
|
|
@@ -13,14 +13,32 @@ module Heirloom
|
|
13
13
|
def build(args)
|
14
14
|
@name = args[:name]
|
15
15
|
@id = args[:id]
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@
|
16
|
+
@exclude = args[:exclude]
|
17
|
+
|
18
|
+
directory = args[:directory] ||= '.'
|
19
|
+
|
20
|
+
@directory = Directory.new :directory => directory,
|
21
|
+
:exclude => @exclude,
|
22
|
+
:logger => @logger
|
23
|
+
|
24
|
+
@local_build = @directory.build_artifact_from_directory
|
21
25
|
|
22
26
|
create_artifact_record
|
23
|
-
|
27
|
+
|
28
|
+
if args[:git]
|
29
|
+
git_directory = GitDirectory.new :directory => directory,
|
30
|
+
:logger => @logger
|
31
|
+
@logger.info "Adding git commit to attributes."
|
32
|
+
@commit = git_directory.commit @id
|
33
|
+
add_git_commit_to_artifact_record
|
34
|
+
end
|
35
|
+
|
36
|
+
@local_build
|
37
|
+
end
|
38
|
+
|
39
|
+
def cleanup
|
40
|
+
@logger.info "Cleaning up local build #{@local_build}."
|
41
|
+
File.delete @local_build
|
24
42
|
end
|
25
43
|
|
26
44
|
private
|
@@ -34,10 +52,21 @@ module Heirloom
|
|
34
52
|
create_artifact_domain
|
35
53
|
attributes = { 'built_by' => "#{user}@#{hostname}",
|
36
54
|
'built_at' => Time.now.utc.iso8601,
|
37
|
-
'
|
55
|
+
'id' => @id }
|
56
|
+
@logger.info "Create artifact record #{@id}"
|
57
|
+
sdb.put_attributes @name, @id, attributes
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_git_commit_to_artifact_record
|
61
|
+
attributes = { 'sha' => @id,
|
38
62
|
'abbreviated_sha' => @commit.id_abbrev,
|
39
63
|
'message' => @commit.message,
|
40
64
|
'author' => @commit.author.name }
|
65
|
+
@logger.info "Git sha: #{@id}"
|
66
|
+
@logger.info "Git abbreviated_sha: #{@commit.id_abbrev}"
|
67
|
+
@logger.info "Git message: #{@commit.message}"
|
68
|
+
@logger.info "Git author: #{@commit.author.name}"
|
69
|
+
|
41
70
|
sdb.put_attributes @name, @id, attributes
|
42
71
|
end
|
43
72
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Heirloom
|
2
|
+
|
3
|
+
class ArtifactDownloader
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@config = args[:config]
|
7
|
+
@logger = args[:logger]
|
8
|
+
end
|
9
|
+
|
10
|
+
def download(args)
|
11
|
+
@id = args[:id]
|
12
|
+
@name = args[:name]
|
13
|
+
@output = args[:output]
|
14
|
+
@region = args[:region]
|
15
|
+
|
16
|
+
s3_downloader = Downloader::S3.new :config => @config,
|
17
|
+
:logger => @logger,
|
18
|
+
:region => @region
|
19
|
+
|
20
|
+
@logger.info "Downloading s3://#{get_bucket}/#{get_key} from #{@region}."
|
21
|
+
|
22
|
+
file = s3_downloader.download_file :bucket => get_bucket,
|
23
|
+
:key => get_key
|
24
|
+
|
25
|
+
@logger.info "Writing file to #{@output}."
|
26
|
+
|
27
|
+
File.open(@output, 'w') do |local_file|
|
28
|
+
local_file.write file
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def get_bucket
|
35
|
+
artifact = artifact_reader.show :name => @name,
|
36
|
+
:id => @id
|
37
|
+
|
38
|
+
url = artifact["#{@region}-s3-url"].first
|
39
|
+
|
40
|
+
bucket = url.gsub('s3://', '').split('/').first
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_key
|
44
|
+
artifact = artifact_reader.show :name => @name,
|
45
|
+
:id => @id
|
46
|
+
|
47
|
+
url = artifact["#{@region}-s3-url"].first
|
48
|
+
|
49
|
+
bucket = url.gsub('s3://', '').gsub(get_bucket, '')
|
50
|
+
bucket.slice!(0)
|
51
|
+
bucket
|
52
|
+
end
|
53
|
+
|
54
|
+
def artifact_reader
|
55
|
+
@artifact_reader ||= ArtifactReader.new :config => @config
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -9,11 +9,12 @@ module Heirloom
|
|
9
9
|
def show(args)
|
10
10
|
domain = args[:name]
|
11
11
|
id = args[:id]
|
12
|
-
sdb.select "select * from #{domain} where itemName() = '#{id}'"
|
12
|
+
items = sdb.select "select * from #{domain} where itemName() = '#{id}'"
|
13
|
+
items[id]
|
13
14
|
end
|
14
15
|
|
15
16
|
def exists?(args)
|
16
|
-
show(args)
|
17
|
+
show(args) != nil
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Heirloom
|
2
|
+
|
3
|
+
class ArtifactUpdater
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@config = args[:config]
|
7
|
+
@logger = args[:logger]
|
8
|
+
end
|
9
|
+
|
10
|
+
def update(args)
|
11
|
+
attribute = args[:attribute]
|
12
|
+
id = args[:id]
|
13
|
+
name = args[:name]
|
14
|
+
update = args[:update]
|
15
|
+
|
16
|
+
sdb.put_attributes name, id, { attribute => update }, { :replace => attribute }
|
17
|
+
@logger.info "Updated #{name} (#{id}): #{attribute} = #{update}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def sdb
|
23
|
+
@sdb ||= AWS::SimpleDB.new :config => @config
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -9,50 +9,28 @@ module Heirloom
|
|
9
9
|
|
10
10
|
def upload(args)
|
11
11
|
id = args[:id]
|
12
|
-
name = args[:name]
|
13
12
|
file = args[:file]
|
14
|
-
|
13
|
+
key_folder = args[:name]
|
14
|
+
key_name = "#{id}.tar.gz"
|
15
|
+
name = args[:name]
|
15
16
|
public_readable = args[:public_readable]
|
16
17
|
|
17
18
|
@config.regions.each do |region|
|
18
19
|
bucket = "#{@config.bucket_prefix}-#{region}"
|
19
20
|
|
20
21
|
s3_uploader = Uploader::S3.new :config => @config,
|
22
|
+
:logger => @logger,
|
21
23
|
:region => region
|
22
24
|
|
23
|
-
s3_uploader.upload_file :
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:key_folder
|
25
|
+
s3_uploader.upload_file :bucket => bucket,
|
26
|
+
:file => file,
|
27
|
+
:id => id,
|
28
|
+
:key_folder => key_folder,
|
29
|
+
:key_name => key_name,
|
30
|
+
:name => name,
|
27
31
|
:public_readable => public_readable
|
28
|
-
sdb.put_attributes name, id, { "#{region}-s3-url" =>
|
29
|
-
"s3://#{bucket}/#{name}/#{key}" }
|
30
|
-
|
31
|
-
@logger.info "Uploading s3://#{bucket}/#{name}/#{key}"
|
32
|
-
|
33
|
-
sdb.put_attributes name, id, { "#{region}-http-url" =>
|
34
|
-
"http://#{s3_endpoints[region]}/#{bucket}/#{name}/#{key}" }
|
35
|
-
@logger.info "Uploading http://#{s3_endpoints[region]}/#{bucket}/#{name}/#{key}"
|
36
|
-
|
37
|
-
sdb.put_attributes name, id, { "#{region}-https-url" =>
|
38
|
-
"https://#{s3_endpoints[region]}/#{bucket}/#{name}/#{key}" }
|
39
|
-
@logger.info "Uploading https://#{s3_endpoints[region]}/#{bucket}/#{name}/#{key}"
|
40
32
|
end
|
41
33
|
end
|
42
34
|
|
43
|
-
private
|
44
|
-
|
45
|
-
def s3_endpoints
|
46
|
-
{
|
47
|
-
'us-east-1' => 's3.amazonaws.com',
|
48
|
-
'us-west-1' => 's3-us-west-1.amazonaws.com',
|
49
|
-
'us-west-2' => 's3-us-west-2.amazonaws.com'
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
def sdb
|
54
|
-
@sdb ||= AWS::SimpleDB.new :config => @config
|
55
|
-
end
|
56
|
-
|
57
35
|
end
|
58
36
|
end
|
data/lib/heirloom/aws/s3.rb
CHANGED
@@ -19,8 +19,8 @@ module Heirloom
|
|
19
19
|
@sdb.create_domain(domain) unless domains.include? domain
|
20
20
|
end
|
21
21
|
|
22
|
-
def put_attributes(domain, key,
|
23
|
-
@sdb.put_attributes domain, key,
|
22
|
+
def put_attributes(domain, key, attributes, options = {})
|
23
|
+
@sdb.put_attributes domain, key, attributes, options
|
24
24
|
end
|
25
25
|
|
26
26
|
def select(query)
|
data/lib/heirloom/cli.rb
CHANGED
@@ -5,43 +5,73 @@ module Heirloom
|
|
5
5
|
def self.start
|
6
6
|
@opts = Trollop::options do
|
7
7
|
banner <<-EOS
|
8
|
+
|
8
9
|
I build and manage artifacts
|
9
10
|
|
10
11
|
Usage:
|
11
12
|
|
12
|
-
heirloom
|
13
|
-
heirloom
|
14
|
-
heirloom show -n NAME -i
|
15
|
-
heirloom build -n NAME -i
|
16
|
-
heirloom
|
13
|
+
heirloom names
|
14
|
+
heirloom list -n NAME
|
15
|
+
heirloom show -n NAME -i ID
|
16
|
+
heirloom build -n NAME -i ID [-d DIRECTORY] [-p] [-g]
|
17
|
+
heirloom download -n NAME -i ID -r REGION -o OUTPUT_FILE
|
18
|
+
heirloom update -n NAME -i ID -a ATTRIBUTE -u UPDATE
|
19
|
+
heirloom destroy -n NAME -i ID
|
20
|
+
|
17
21
|
EOS
|
18
22
|
opt :help, "Display Help"
|
19
|
-
opt :
|
23
|
+
opt :attribute, "Attribute to update.", :type => :string
|
24
|
+
opt :directory, "Source directory of build.", :type => :string,
|
25
|
+
:default => '.'
|
26
|
+
opt :exclude, "Comma spereate list of files or directories to exclude.", :type => :string,
|
27
|
+
:default => '.git'
|
28
|
+
opt :git, "Read git commit information from directory."
|
20
29
|
opt :id, "Id of artifact.", :type => :string
|
21
30
|
opt :name, "Name of artifact.", :type => :string
|
22
|
-
opt :
|
31
|
+
opt :output, "Output download to file.", :type => :string
|
32
|
+
opt :public, "Set this artifact as public readable?"
|
33
|
+
opt :region, "Region to download artifact.", :type => :string,
|
34
|
+
:default => 'us-west-1'
|
35
|
+
opt :update, "Update value of attribute.", :type => :string
|
23
36
|
end
|
24
37
|
|
25
38
|
cmd = ARGV.shift
|
26
39
|
a = Artifact.new :config => nil
|
27
40
|
|
28
41
|
case cmd
|
42
|
+
when 'names'
|
43
|
+
puts a.names
|
29
44
|
when 'list'
|
30
|
-
|
31
|
-
|
32
|
-
|
45
|
+
unless @opts[:name]
|
46
|
+
puts "Please specify an artifact name."
|
47
|
+
puts a.names
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
puts a.list :name => @opts[:name]
|
33
51
|
when 'show'
|
34
52
|
puts a.show(:name => @opts[:name],
|
35
|
-
:id
|
53
|
+
:id => @opts[:id]).to_yaml
|
36
54
|
when 'build'
|
37
|
-
a.build :name
|
38
|
-
:id
|
39
|
-
:accounts
|
55
|
+
a.build :name => @opts[:name],
|
56
|
+
:id => @opts[:id],
|
57
|
+
:accounts => @opts[:accounts],
|
40
58
|
:directory => @opts[:directory],
|
41
|
-
:
|
59
|
+
:exclude => @opts[:exclude].split(','),
|
60
|
+
:public => @opts[:public],
|
61
|
+
:git => @opts[:git]
|
62
|
+
when 'update'
|
63
|
+
a.update :name => @opts[:name],
|
64
|
+
:id => @opts[:id],
|
65
|
+
:attribute => @opts[:attribute],
|
66
|
+
:update => @opts[:update]
|
67
|
+
when 'download'
|
68
|
+
a.download :name => @opts[:name],
|
69
|
+
:id => @opts[:id],
|
70
|
+
:output => @opts[:output],
|
71
|
+
:region => @opts[:region]
|
42
72
|
when 'destroy', 'delete'
|
43
73
|
a.destroy :name => @opts[:name],
|
44
|
-
:id
|
74
|
+
:id => @opts[:id]
|
45
75
|
else
|
46
76
|
puts "Unkown command: '#{cmd}'."
|
47
77
|
end
|
data/lib/heirloom/directory.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
require 'archive/tar/minitar'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
include Archive::Tar
|
6
|
+
|
7
|
+
module Heirloom
|
8
|
+
|
9
|
+
class Directory
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
@directory = args[:directory]
|
13
|
+
@exclude = args[:exclude]
|
14
|
+
@logger = args[:logger]
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_artifact_from_directory
|
18
|
+
random_text = (0...8).map{65.+(rand(25)).chr}.join
|
19
|
+
temp_file_name = File.join(Dir.tmpdir, random_text + ".tar.gz")
|
20
|
+
|
21
|
+
@logger.info "Building artifact '#{temp_file_name}' from '#{@directory}'."
|
22
|
+
@logger.info "Excluding #{@exclude.to_s}."
|
23
|
+
@logger.info "Adding #{files_to_pack.to_s}."
|
24
|
+
|
25
|
+
tgz = Zlib::GzipWriter.new File.open(temp_file_name, 'wb')
|
26
|
+
|
27
|
+
Minitar.pack(files_to_pack, tgz)
|
28
|
+
temp_file_name
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def files_to_pack
|
34
|
+
Dir.entries(@directory) - ['.', '..'] - @exclude
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -1,9 +1,5 @@
|
|
1
|
-
require 'zlib'
|
2
|
-
require 'archive/tar/minitar'
|
3
|
-
require 'tmpdir'
|
4
1
|
require 'grit'
|
5
2
|
|
6
|
-
include Archive::Tar
|
7
3
|
include Grit
|
8
4
|
|
9
5
|
module Heirloom
|
@@ -20,16 +16,5 @@ module Heirloom
|
|
20
16
|
sha ? r.commits(sha).first : r.commits.first
|
21
17
|
end
|
22
18
|
|
23
|
-
def build_artifact_from_directory
|
24
|
-
random_text = (0...8).map{65.+(rand(25)).chr}.join
|
25
|
-
temp_file_name = File.join(Dir.tmpdir, random_text + ".tar.gz")
|
26
|
-
|
27
|
-
@logger.info "Building artifact '#{temp_file_name}' from '#{@directory}'."
|
28
|
-
|
29
|
-
tgz = Zlib::GzipWriter.new File.open(temp_file_name, 'wb')
|
30
|
-
Minitar.pack(@directory, tgz)
|
31
|
-
temp_file_name
|
32
|
-
end
|
33
|
-
|
34
19
|
end
|
35
20
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'heirloom/downloader/s3'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Heirloom
|
2
|
+
module Downloader
|
3
|
+
class S3
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@config = args[:config]
|
7
|
+
@region = args[:region]
|
8
|
+
@logger = args[:logger]
|
9
|
+
end
|
10
|
+
|
11
|
+
def download_file(args)
|
12
|
+
s3.get_object args[:bucket], args[:key]
|
13
|
+
end
|
14
|
+
|
15
|
+
def s3
|
16
|
+
@s3 ||= AWS::S3.new :config => @config,
|
17
|
+
:region => @region
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Heirloom
|
2
|
+
class HeirloomLogger
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
@logger = args[:logger] ||= Logger.new(STDOUT)
|
6
|
+
|
7
|
+
@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
8
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
9
|
+
"#{datetime}: #{msg}\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
@logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def info(msg)
|
16
|
+
@logger.info msg
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/heirloom/uploader/s3.rb
CHANGED
@@ -5,29 +5,74 @@ module Heirloom
|
|
5
5
|
def initialize(args)
|
6
6
|
@config = args[:config]
|
7
7
|
@region = args[:region]
|
8
|
+
@logger = args[:logger]
|
8
9
|
end
|
9
10
|
|
10
11
|
def upload_file(args)
|
12
|
+
bucket = args[:bucket]
|
11
13
|
file = args[:file]
|
14
|
+
id = args[:id]
|
12
15
|
key_name = args[:key_name]
|
13
16
|
key_folder = args[:key_folder]
|
17
|
+
name = args[:name]
|
14
18
|
public_readable = args[:public_readable]
|
15
|
-
bucket = args[:bucket]
|
16
19
|
|
17
20
|
s3_bucket = s3.get_bucket bucket
|
18
21
|
|
22
|
+
@logger.info "Uploading s3://#{bucket}/#{key_folder}/#{key_name}"
|
23
|
+
|
19
24
|
s3_bucket.files.create :key => "#{key_folder}/#{key_name}",
|
20
25
|
:body => File.open(file),
|
21
26
|
:public => public_readable
|
27
|
+
|
28
|
+
@logger.info "File is readable by the public internet." if public_readable
|
29
|
+
|
30
|
+
add_endpoint_attributes :bucket => bucket,
|
31
|
+
:id => id,
|
32
|
+
:key_folder => key_folder,
|
33
|
+
:key_name => key_name,
|
34
|
+
:name => name
|
22
35
|
end
|
23
36
|
|
24
37
|
private
|
25
38
|
|
39
|
+
def add_endpoint_attributes(args)
|
40
|
+
bucket = args[:bucket]
|
41
|
+
id = args[:id]
|
42
|
+
key_name = args[:key_name]
|
43
|
+
key_folder = args[:key_folder]
|
44
|
+
name = args[:name]
|
45
|
+
|
46
|
+
s3_endpoint = "s3://#{bucket}/#{key_folder}/#{key_name}"
|
47
|
+
http_endpoint = "http://#{endpoints[@region]}/#{bucket}/#{key_folder}/#{key_name}"
|
48
|
+
https_endpoint = "https://#{endpoints[@region]}/#{bucket}/#{key_folder}/#{key_name}"
|
49
|
+
|
50
|
+
sdb.put_attributes name, id, { "#{@region}-s3-url" => s3_endpoint }
|
51
|
+
@logger.info "Adding attribute #{s3_endpoint}."
|
52
|
+
|
53
|
+
sdb.put_attributes name, id, { "#{@region}-http-url" => http_endpoint }
|
54
|
+
@logger.info "Adding attribute #{http_endpoint}."
|
55
|
+
|
56
|
+
sdb.put_attributes name, id, { "#{@region}-https-url" => https_endpoint }
|
57
|
+
@logger.info "Adding attribute #{https_endpoint}."
|
58
|
+
end
|
59
|
+
|
60
|
+
def endpoints
|
61
|
+
{
|
62
|
+
'us-east-1' => 's3.amazonaws.com',
|
63
|
+
'us-west-1' => 's3-us-west-1.amazonaws.com',
|
64
|
+
'us-west-2' => 's3-us-west-2.amazonaws.com'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
26
68
|
def s3
|
27
69
|
@s3 ||= AWS::S3.new :config => @config,
|
28
70
|
:region => @region
|
29
71
|
end
|
30
72
|
|
73
|
+
def sdb
|
74
|
+
@sdb ||= AWS::SimpleDB.new :config => @config
|
75
|
+
end
|
31
76
|
end
|
32
77
|
end
|
33
78
|
end
|
data/lib/heirloom/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70254605304040 !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: *70254605304040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fog
|
27
|
-
requirement: &
|
27
|
+
requirement: &70254605302600 !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: *70254605302600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: grit
|
38
|
-
requirement: &
|
38
|
+
requirement: &70254605300080 !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: *70254605300080
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: logger
|
49
|
-
requirement: &
|
49
|
+
requirement: &70254605298600 !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: *70254605298600
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: minitar
|
60
|
-
requirement: &
|
60
|
+
requirement: &70254605296660 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70254605296660
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: trollop
|
71
|
-
requirement: &
|
71
|
+
requirement: &70254605294980 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70254605294980
|
80
80
|
description: I help build and manage artifacts
|
81
81
|
email:
|
82
82
|
- brett@weav.net
|
@@ -98,8 +98,10 @@ files:
|
|
98
98
|
- lib/heirloom/artifact/artifact_authorizer.rb
|
99
99
|
- lib/heirloom/artifact/artifact_builder.rb
|
100
100
|
- lib/heirloom/artifact/artifact_destroyer.rb
|
101
|
+
- lib/heirloom/artifact/artifact_downloader.rb
|
101
102
|
- lib/heirloom/artifact/artifact_lister.rb
|
102
103
|
- lib/heirloom/artifact/artifact_reader.rb
|
104
|
+
- lib/heirloom/artifact/artifact_updater.rb
|
103
105
|
- lib/heirloom/artifact/artifact_uploader.rb
|
104
106
|
- lib/heirloom/aws.rb
|
105
107
|
- lib/heirloom/aws/s3.rb
|
@@ -109,7 +111,11 @@ files:
|
|
109
111
|
- lib/heirloom/destroyer.rb
|
110
112
|
- lib/heirloom/destroyer/s3.rb
|
111
113
|
- lib/heirloom/directory.rb
|
114
|
+
- lib/heirloom/directory/directory.rb
|
112
115
|
- lib/heirloom/directory/git_directory.rb
|
116
|
+
- lib/heirloom/downloader.rb
|
117
|
+
- lib/heirloom/downloader/s3.rb
|
118
|
+
- lib/heirloom/logger.rb
|
113
119
|
- lib/heirloom/uploader.rb
|
114
120
|
- lib/heirloom/uploader/s3.rb
|
115
121
|
- lib/heirloom/version.rb
|
@@ -130,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
136
|
version: '0'
|
131
137
|
segments:
|
132
138
|
- 0
|
133
|
-
hash:
|
139
|
+
hash: 4250445776269630544
|
134
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
141
|
none: false
|
136
142
|
requirements:
|
@@ -139,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
145
|
version: '0'
|
140
146
|
segments:
|
141
147
|
- 0
|
142
|
-
hash:
|
148
|
+
hash: 4250445776269630544
|
143
149
|
requirements: []
|
144
150
|
rubyforge_project: heirloom
|
145
151
|
rubygems_version: 1.8.16
|