heirloom 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGELOG +6 -0
  2. data/README.md +0 -1
  3. data/lib/heirloom/acl/s3.rb +10 -8
  4. data/lib/heirloom/artifact.rb +44 -43
  5. data/lib/heirloom/artifact/artifact_authorizer.rb +20 -22
  6. data/lib/heirloom/artifact/artifact_builder.rb +41 -37
  7. data/lib/heirloom/artifact/artifact_destroyer.rb +16 -14
  8. data/lib/heirloom/artifact/artifact_downloader.rb +22 -40
  9. data/lib/heirloom/artifact/artifact_lister.rb +10 -7
  10. data/lib/heirloom/artifact/artifact_reader.rb +17 -20
  11. data/lib/heirloom/artifact/artifact_updater.rb +6 -5
  12. data/lib/heirloom/artifact/artifact_uploader.rb +8 -8
  13. data/lib/heirloom/aws/s3.rb +1 -1
  14. data/lib/heirloom/cli.rb +37 -30
  15. data/lib/heirloom/cli/build.rb +40 -0
  16. data/lib/heirloom/cli/destroy.rb +20 -0
  17. data/lib/heirloom/cli/download.rb +23 -0
  18. data/lib/heirloom/cli/list.rb +17 -0
  19. data/lib/heirloom/cli/show.rb +27 -0
  20. data/lib/heirloom/cli/update.rb +23 -0
  21. data/lib/heirloom/config.rb +11 -6
  22. data/lib/heirloom/destroyer/s3.rb +6 -4
  23. data/lib/heirloom/directory/directory.rb +15 -11
  24. data/lib/heirloom/directory/git_directory.rb +4 -3
  25. data/lib/heirloom/downloader/s3.rb +1 -1
  26. data/lib/heirloom/logger.rb +6 -4
  27. data/lib/heirloom/version.rb +1 -1
  28. data/spec/acl/s3_spec.rb +51 -0
  29. data/spec/artifact/artifact_authorizer_spec.rb +34 -0
  30. data/spec/artifact/artifact_builder_spec.rb +41 -0
  31. data/spec/artifact/artifact_destroyer_spec.rb +45 -0
  32. data/spec/artifact/artifact_downloader_spec.rb +93 -0
  33. data/spec/artifact/artifact_lister_spec.rb +21 -0
  34. data/spec/artifact/artifact_reader_spec.rb +55 -0
  35. data/spec/artifact/artifact_updater_spec.rb +16 -0
  36. data/spec/artifact/artifact_uploader_spec.rb +16 -0
  37. data/spec/artifact_spec.rb +69 -19
  38. data/spec/aws/s3_spec.rb +55 -0
  39. data/spec/aws/simpledb_spec.rb +50 -0
  40. data/spec/config_spec.rb +32 -3
  41. data/spec/destroyer/s3_spec.rb +21 -0
  42. data/spec/directory/directory_spec.rb +26 -0
  43. data/spec/directory/git_directory_spec.rb +28 -0
  44. data/spec/downloader/s3_spec.rb +23 -0
  45. data/spec/logger_spec.rb +20 -0
  46. metadata +55 -16
@@ -0,0 +1,6 @@
1
+ ## v0.1.4:
2
+
3
+ * Limit list of artifact ids returned in list
4
+ * Sort ids by date added
5
+ * Show latest id as default
6
+ * Setting deafult download path to local dir
data/README.md CHANGED
@@ -3,7 +3,6 @@ Heirloom
3
3
 
4
4
  I help building and deploying artifcts to cloud based storage services and tracking meta data about those artifacts for easy deployments.
5
5
 
6
-
7
6
  How To Use Heirloom
8
7
  -------------------
9
8
 
@@ -2,14 +2,16 @@ module Heirloom
2
2
  module ACL
3
3
  class S3
4
4
 
5
+ attr_accessor :accounts, :config, :logger, :region
6
+
5
7
  def initialize(args)
6
- @config = args[:config]
7
- @region = args[:region]
8
- @logger = args[:logger]
9
- @accounts = @config.authorized_aws_accounts
8
+ self.config = args[:config]
9
+ self.region = args[:region]
10
+ self.logger = config.logger
11
+ self.accounts = config.authorized_aws_accounts
10
12
  end
11
13
 
12
- def allow_read_acccess_from_accounts(args)
14
+ def allow_read_access_from_accounts(args)
13
15
  bucket = args[:bucket]
14
16
  key_name = args[:key_name]
15
17
  key_folder = args[:key_folder]
@@ -23,10 +25,10 @@ module Heirloom
23
25
 
24
26
  grants = build_bucket_grants :id => id,
25
27
  :name => name,
26
- :accounts => @accounts
28
+ :accounts => accounts
27
29
 
28
- @accounts.each do |a|
29
- @logger.info "Authorizing #{a} to s3://#{bucket}/#{key}"
30
+ accounts.each do |a|
31
+ logger.info "Authorizing #{a} to s3://#{bucket}/#{key}."
30
32
  end
31
33
  s3.put_object_acl bucket, key, grants
32
34
  end
@@ -12,98 +12,99 @@ module Heirloom
12
12
  class Artifact
13
13
 
14
14
  def initialize(args)
15
- @config = Config.new :config => args[:config]
16
- @logger = HeirloomLogger.new :logger => args[:logger]
15
+ @config = Config.new :config => args[:config],
16
+ :logger => args[:logger]
17
+ @name = args[:name]
18
+ @id = args[:id]
19
+ end
20
+
21
+ def authorize
22
+ artifact_authorizer.authorize
17
23
  end
18
24
 
19
25
  def build(args)
20
- if artifact_reader.exists? args
21
- @logger.info "Destroying existing artifact."
22
- destroy(args)
23
- end
24
-
25
- file = artifact_builder.build args
26
-
27
- artifact_uploader.upload :id => args[:id],
28
- :name => args[:name],
29
- :bucket_prefix => args[:bucket_prefix],
30
- :public_readable => args[:public],
31
- :file => file
32
-
33
- artifact_authorizer.authorize :id => args[:id],
34
- :name => args[:name],
35
- :public_readable => args[:public]
36
-
37
- artifact_builder.cleanup
26
+ artifact_builder.build args
27
+ end
38
28
 
39
- @logger.info "Artifact build completed."
29
+ def download(args)
30
+ artifact_downloader.download args
40
31
  end
41
32
 
42
33
  def update(args)
43
- artifact_updater.update(args)
44
- @logger.info "Artifact update completed."
34
+ artifact_updater.update args
45
35
  end
46
36
 
47
- def download(args)
48
- artifact_downloader.download(args)
49
- @logger.info "Artifact download completed."
37
+ def upload(args)
38
+ artifact_uploader.upload args
39
+ end
40
+
41
+ def exists?
42
+ artifact_reader.exists?
50
43
  end
51
44
 
52
- def destroy(args)
53
- artifact_destroyer.destroy(args)
54
- @logger.info "Artifact destroyed."
45
+ def destroy
46
+ artifact_destroyer.destroy
55
47
  end
56
48
 
57
- def show(args)
58
- artifact_reader.show(args)
49
+ def show
50
+ artifact_reader.show
59
51
  end
60
52
 
61
- def list(args)
62
- artifact_lister.list(args)
53
+ def list(limit=10)
54
+ artifact_lister.list(limit)
63
55
  end
64
56
 
65
- def names
66
- artifact_lister.names
57
+ def cleanup
58
+ artifact_builder.cleanup
67
59
  end
68
60
 
69
61
  private
70
62
 
71
63
  def artifact_lister
72
- @artifact_lister ||= ArtifactLister.new :config => @config
64
+ @artifact_lister ||= ArtifactLister.new :config => @config,
65
+ :name => @name
73
66
  end
74
67
 
75
68
  def artifact_reader
76
- @artifact_reader ||= ArtifactReader.new :config => @config
69
+ @artifact_reader ||= ArtifactReader.new :config => @config,
70
+ :name => @name,
71
+ :id => @id
77
72
  end
78
73
 
79
74
  def artifact_builder
80
75
  @artifact_builder ||= ArtifactBuilder.new :config => @config,
81
- :logger => @logger
76
+ :name => @name,
77
+ :id => @id
82
78
  end
83
79
 
84
80
  def artifact_updater
85
81
  @artifact_updater ||= ArtifactUpdater.new :config => @config,
86
- :logger => @logger
82
+ :name => @name,
83
+ :id => @id
87
84
  end
88
85
 
89
86
  def artifact_uploader
90
87
  @artifact_uploader ||= ArtifactUploader.new :config => @config,
91
- :logger => @logger
88
+ :name => @name,
89
+ :id => @id
92
90
  end
93
91
 
94
92
  def artifact_downloader
95
93
  @artifact_downloader ||= ArtifactDownloader.new :config => @config,
96
- :logger => @logger
94
+ :name => @name,
95
+ :id => @id
97
96
  end
98
97
 
99
98
  def artifact_authorizer
100
99
  @artifact_authorizer ||= ArtifactAuthorizer.new :config => @config,
101
- :logger => @logger
100
+ :name => @name,
101
+ :id => @id
102
102
  end
103
103
 
104
104
  def artifact_destroyer
105
105
  @artifact_destroyer ||= ArtifactDestroyer.new :config => @config,
106
- :logger => @logger
106
+ :name => @name,
107
+ :id => @id
107
108
  end
108
109
 
109
110
  end
@@ -4,36 +4,34 @@ module Heirloom
4
4
 
5
5
  def initialize(args)
6
6
  @config = args[:config]
7
- @logger = args[:logger]
7
+ @name = args[:name]
8
+ @id = args[:id]
9
+ @logger = @config.logger
8
10
  end
9
11
 
10
- def authorize(args)
11
- id = args[:id]
12
- name = args[:name]
13
- public_readable = args[:public_readable]
14
-
15
- unless public_readable
16
- @logger.info "Authorizing access to artifact."
17
-
18
- @config.regions.each do |region|
19
- bucket = artifact_reader.get_bucket :region => region,
20
- :name => name,
21
- :id => id
22
- s3_acl = ACL::S3.new :config => @config,
23
- :logger => @logger,
24
- :region => region
25
-
26
- s3_acl.allow_read_acccess_from_accounts :key_name => id,
27
- :key_folder => name,
28
- :bucket => bucket
29
- end
12
+ def authorize
13
+ @logger.info "Authorizing access to artifact."
14
+
15
+ @config.regions.each do |region|
16
+ bucket = artifact_reader.get_bucket :region => region
17
+
18
+ s3_acl = ACL::S3.new :config => @config,
19
+ :region => region
20
+
21
+ s3_acl.allow_read_access_from_accounts :key_name => @id,
22
+ :key_folder => @name,
23
+ :bucket => bucket
30
24
  end
25
+
26
+ @logger.info "Authorization complete."
31
27
  end
32
28
 
33
29
  private
34
30
 
35
31
  def artifact_reader
36
- @artifact_reader ||= ArtifactReader.new :config => @config
32
+ @artifact_reader ||= ArtifactReader.new :config => @config,
33
+ :name => @name,
34
+ :id => @id
37
35
  end
38
36
 
39
37
  end
@@ -5,73 +5,77 @@ module Heirloom
5
5
 
6
6
  class ArtifactBuilder
7
7
 
8
+ attr_accessor :config, :id, :local_build, :logger, :name, :source
9
+
8
10
  def initialize(args)
9
- @config = args[:config]
10
- @logger = args[:logger]
11
+ self.config = args[:config]
12
+ self.name = args[:name]
13
+ self.id = args[:id]
14
+ self.logger = config.logger
15
+ sdb.create_domain name
11
16
  end
12
17
 
13
18
  def build(args)
14
- @name = args[:name]
15
- @id = args[:id]
16
- @exclude = args[:exclude]
19
+ self.source = args[:directory] ||= '.'
17
20
 
18
- directory = args[:directory] ||= '.'
21
+ directory = Directory.new :path => source,
22
+ :exclude => args[:exclude],
23
+ :config => config
19
24
 
20
- @directory = Directory.new :directory => directory,
21
- :exclude => @exclude,
22
- :logger => @logger
25
+ directory.build_artifact_from_directory
23
26
 
24
- @local_build = @directory.build_artifact_from_directory
27
+ self.local_build = directory.local_build
25
28
 
26
29
  create_artifact_record
27
30
 
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
31
+ add_git_commit if args[:git]
32
+
33
+ logger.info "Build complete."
35
34
 
36
- @local_build
35
+ local_build
37
36
  end
38
37
 
39
38
  def cleanup
40
- @logger.info "Cleaning up local build #{@local_build}."
41
- File.delete @local_build
39
+ logger.info "Cleaning up local build #{local_build}."
40
+ File.delete local_build
42
41
  end
43
42
 
44
43
  private
45
44
 
45
+ def add_git_commit
46
+ git_commit = GitDirectory.new(:path => source).commit
47
+ add_git_commit_to_artifact_record git_commit
48
+ end
49
+
46
50
  def create_artifact_domain
47
- @logger.info "Verifying artifact domain #{@name} exists."
48
- sdb.create_domain @name
51
+ logger.info "Verifying artifact domain #{name} exists."
49
52
  end
50
53
 
51
54
  def create_artifact_record
52
55
  create_artifact_domain
53
56
  attributes = { 'built_by' => "#{user}@#{hostname}",
54
57
  'built_at' => Time.now.utc.iso8601,
55
- 'id' => @id }
56
- @logger.info "Create artifact record #{@id}"
57
- sdb.put_attributes @name, @id, attributes
58
+ 'id' => id }
59
+ logger.info "Create artifact record #{id}."
60
+ sdb.put_attributes name, id, attributes
58
61
  end
59
62
 
60
- def add_git_commit_to_artifact_record
61
- attributes = { 'sha' => @id,
62
- 'abbreviated_sha' => @commit.id_abbrev,
63
- 'message' => @commit.message,
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
-
70
- sdb.put_attributes @name, @id, attributes
63
+ def add_git_commit_to_artifact_record(commit)
64
+ attributes = { 'sha' => id,
65
+ 'abbreviated_sha' => commit.id_abbrev,
66
+ 'message' => commit.message,
67
+ 'author' => commit.author.name }
68
+
69
+ logger.info "Git sha: #{id}"
70
+ logger.info "Git abbreviated_sha: #{commit.id_abbrev}"
71
+ logger.info "Git message: #{commit.message}"
72
+ logger.info "Git author: #{commit.author.name}"
73
+
74
+ sdb.put_attributes name, id, attributes
71
75
  end
72
76
 
73
77
  def sdb
74
- @sdb ||= AWS::SimpleDB.new :config => @config
78
+ @sdb ||= AWS::SimpleDB.new :config => config
75
79
  end
76
80
 
77
81
  def user
@@ -2,27 +2,26 @@ module Heirloom
2
2
 
3
3
  class ArtifactDestroyer
4
4
 
5
+ attr_accessor :config, :id, :logger, :name
6
+
5
7
  def initialize(args)
6
- @config = args[:config]
7
- @logger = args[:logger]
8
+ self.config = args[:config]
9
+ self.name = args[:name]
10
+ self.id = args[:id]
11
+ self.logger = config.logger
8
12
  end
9
13
 
10
- def destroy(args)
11
- id = args[:id]
12
- name = args[:name]
14
+ def destroy
15
+ logger.info "Destroying #{@name} - #{@id}"
13
16
 
14
- @logger.info "Destroying #{args[:name]} - #{args[:id]}"
17
+ config.regions.each do |region|
18
+ bucket = artifact_reader.get_bucket :region => region
15
19
 
16
- @config.regions.each do |region|
17
- puts "#{region}, #{name}, #{id}"
18
- bucket = artifact_reader.get_bucket :region => region,
19
- :name => name,
20
- :id => id
21
20
  key = "#{id}.tar.gz"
22
21
 
23
- @logger.info "Deleting s3://#{bucket}/#{name}/#{key}"
22
+ logger.info "Destroying 's3://#{bucket}/#{name}/#{key}'."
24
23
 
25
- s3_destroyer = Destroyer::S3.new :config => @config,
24
+ s3_destroyer = Destroyer::S3.new :config => config,
26
25
  :region => region
27
26
 
28
27
  s3_destroyer.destroy_file :key_name => key,
@@ -31,6 +30,7 @@ module Heirloom
31
30
 
32
31
  end
33
32
  sdb.delete name, id
33
+ logger.info "Destroy complete."
34
34
  end
35
35
 
36
36
  private
@@ -40,7 +40,9 @@ module Heirloom
40
40
  end
41
41
 
42
42
  def artifact_reader
43
- @artifact_reader ||= ArtifactReader.new :config => @config
43
+ @artifact_reader ||= ArtifactReader.new :config => config,
44
+ :name => name,
45
+ :id => id
44
46
  end
45
47
 
46
48
  end
@@ -2,65 +2,47 @@ module Heirloom
2
2
 
3
3
  class ArtifactDownloader
4
4
 
5
+ attr_accessor :config, :id, :name, :logger
6
+
5
7
  def initialize(args)
6
- @config = args[:config]
7
- @logger = args[:logger]
8
+ self.config = args[:config]
9
+ self.name = args[:name]
10
+ self.id = args[:id]
11
+ self.logger = config.logger
8
12
  end
9
13
 
10
14
  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
15
+ region = args[:region]
19
16
 
20
- bucket = artifact_reader.get_bucket :region => @region,
21
- :name => @name,
22
- :id => @id
17
+ s3_downloader = Downloader::S3.new :config => config,
18
+ :logger => logger,
19
+ :region => region
23
20
 
24
- key = artifact_reader.get_key :region => @region,
25
- :name => @name,
26
- :id => @id
21
+ bucket = artifact_reader.get_bucket :region => region
22
+ key = artifact_reader.get_key :region => region
27
23
 
28
- @logger.info "Downloading s3://#{bucket}/#{key} from #{@region}."
24
+ logger.info "Downloading s3://#{bucket}/#{key} from #{region}."
29
25
 
30
26
  file = s3_downloader.download_file :bucket => bucket,
31
27
  :key => key
32
28
 
33
- @logger.info "Writing file to #{@output}."
29
+ output = args[:output] ||= "./#{key.split('/').last}"
30
+
31
+ logger.info "Writing file to #{output}."
34
32
 
35
- File.open(@output, 'w') do |local_file|
33
+ File.open(output, 'w') do |local_file|
36
34
  local_file.write file
37
35
  end
38
- end
39
-
40
- private
41
36
 
42
- def get_bucket
43
- artifact = artifact_reader.show :name => @name,
44
- :id => @id
45
-
46
- url = artifact["#{@region}-s3-url"].first
47
-
48
- bucket = url.gsub('s3://', '').split('/').first
37
+ logger.info "Download complete."
49
38
  end
50
39
 
51
- def get_key
52
- artifact = artifact_reader.show :name => @name,
53
- :id => @id
54
-
55
- url = artifact["#{@region}-s3-url"].first
56
-
57
- bucket = url.gsub('s3://', '').gsub(get_bucket, '')
58
- bucket.slice!(0)
59
- bucket
60
- end
40
+ private
61
41
 
62
42
  def artifact_reader
63
- @artifact_reader ||= ArtifactReader.new :config => @config
43
+ @artifact_reader ||= ArtifactReader.new :config => config,
44
+ :name => name,
45
+ :id => id
64
46
  end
65
47
 
66
48
  end