capistrano-net_storage-s3 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14610afab4d9f5c54d0952bad4f26306ab1eabe4
4
- data.tar.gz: 09d631a5add4f5a5e79c1ed20713e35a2bb9c32f
3
+ metadata.gz: 2992a319fb7a4282147716b31fe7e8c379dd1d40
4
+ data.tar.gz: c840ea5a48f423ec0939509255e1000091d93306
5
5
  SHA512:
6
- metadata.gz: 8e38f578854a6fe47190e05298c6ee9f66a3184710e591d0ccbfdf80e3cf6fa5caa32fb751a7c7ad3bfc90c86f80d68f7c9976f20da1d8c014e08b3e348bd6e7
7
- data.tar.gz: a7bb8332a0322eb50e39717e49c94da05f4a892a2bc471f8311c7c041b567a4407ad06469c7cfbc2452588bbea9664918fb0d185ac4809d2f07c213ab6cac238
6
+ metadata.gz: 718985fd43ef6f9895f0da392b10282ae49d16874bb0c18e9dd481bd646a8c1d0677187690a87fb6b23610cf2691f978a0aacb6d581db13cd10c2bd5705e38ca
7
+ data.tar.gz: 91c06e3aa98b211d5d56b09b744bbd1f7fc017932dfbe11718b83d161435c26dbf0797b7e35b0945a0c96bcef04dbb2fc95b3b0e2bd12935547af08b35428e28
data/CHANGELOG.md CHANGED
@@ -1,8 +1,15 @@
1
+ ## 0.2.2 (2017/5/9)
2
+
3
+ Feature:
4
+
5
+ - Implement `Capistrano::NetStorage::S3::Broker::AwsCLI#cleanup` to purge old
6
+ archives on S3 (#3)
7
+
1
8
  ## 0.2.1 (2017/4/21)
2
9
 
3
10
  Internal Changes (#2):
4
11
 
5
- - `Capistrano::NetStorage::S3::Broker::AwsCli` :
12
+ - `Capistrano::NetStorage::S3::Broker::AwsCLI` :
6
13
  - Use `run_locally` instead of `on :local`
7
14
  - Trap `SSHKit::StandardError` when finding an archive fails
8
15
 
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+ require 'time'
1
3
  require 'retryable'
2
4
 
3
5
  require 'capistrano/net_storage/s3/base'
@@ -41,6 +43,27 @@ class Capistrano::NetStorage::S3::Broker::AwsCLI < Capistrano::NetStorage::S3::B
41
43
  end
42
44
  end
43
45
 
46
+ def cleanup
47
+ c = config
48
+ list_args = %W(--bucket #{c.bucket} --output json)
49
+ if c.archives_directory
50
+ list_args += %W(--prefix #{c.archives_directory})
51
+ end
52
+ output = capture_aws_s3api('list-objects', list_args)
53
+ return if output.empty?
54
+
55
+ objects = JSON.parse(output)['Contents']
56
+ sorted = objects.sort_by { |obj| Time.parse(obj['LastModified']) }
57
+ fetch(:keep_releases).times do
58
+ break if sorted.empty?
59
+ sorted.pop
60
+ end
61
+ sorted.each do |obj|
62
+ delete_args = %W(--bucket #{c.bucket} --key #{obj['Key']})
63
+ execute_aws_s3api('delete-object', *delete_args)
64
+ end
65
+ end
66
+
44
67
  private
45
68
 
46
69
  def execute_aws_s3(cmd, *args)
@@ -60,4 +83,22 @@ class Capistrano::NetStorage::S3::Broker::AwsCLI < Capistrano::NetStorage::S3::B
60
83
  end
61
84
  end
62
85
  end
86
+
87
+ def execute_aws_s3api(cmd, *args)
88
+ c = config
89
+ run_locally do
90
+ with(c.aws_environments) do
91
+ execute :aws, 's3api', cmd, *args
92
+ end
93
+ end
94
+ end
95
+
96
+ def capture_aws_s3api(cmd, *args)
97
+ c = config
98
+ run_locally do
99
+ with(c.aws_environments) do
100
+ capture :aws, 's3api', cmd, *args
101
+ end
102
+ end
103
+ end
63
104
  end
@@ -66,14 +66,30 @@ class Capistrano::NetStorage::S3
66
66
  end
67
67
  end
68
68
 
69
- # S3 bucket URL via which one transports application archives
70
- # @return [URI::Generic]
71
- def bucket_url
69
+ # S3 bucket name via which one transports application archives
70
+ # @return [String]
71
+ def bucket
72
72
  @bucket ||= begin
73
73
  unless bucket = fetch(:net_storage_s3_bucket)
74
74
  raise Capistrano::NetStorage::S3::Error, ':net_storage_s3_bucket is not configured!'
75
75
  end
76
- URI.parse("s3://#{bucket}")
76
+ bucket
77
+ end
78
+ end
79
+
80
+ # S3 bucket URL via which one transports application archives
81
+ # @return [URI::Generic]
82
+ def bucket_url
83
+ @bucket_url ||= URI.parse("s3://#{bucket}")
84
+ end
85
+
86
+ # Directory path on S3 bucket for application archives
87
+ # @return [String]
88
+ def archives_directory
89
+ # append '/' in case missing
90
+ @archives_directory ||= begin
91
+ dir = fetch(:net_storage_s3_archives_directory)
92
+ dir.sub(%r{[^/]\Z}, '\&/') if dir
77
93
  end
78
94
  end
79
95
 
@@ -106,16 +122,5 @@ class Capistrano::NetStorage::S3
106
122
  def max_retry
107
123
  @max_retry ||= fetch(:net_storage_s3_max_retry, 3)
108
124
  end
109
-
110
- private
111
-
112
- # @return [String]
113
- def archives_directory
114
- # append '/' in case missing
115
- @archives_directory ||= begin
116
- dir = fetch(:net_storage_s3_archives_directory)
117
- dir.sub(%r{[^/]\Z}, '\&/') if dir
118
- end
119
- end
120
125
  end
121
126
  end
@@ -7,7 +7,7 @@ require 'capistrano/net_storage/s3/config'
7
7
 
8
8
  class Capistrano::NetStorage::S3::Transport < Capistrano::NetStorage::Transport::Base
9
9
  extend Forwardable
10
- def_delegators :broker, :check, :find_uploaded, :upload, :download
10
+ def_delegators :broker, :check, :find_uploaded, :upload, :download, :cleanup
11
11
 
12
12
  private
13
13
 
@@ -1,5 +1,5 @@
1
1
  require 'capistrano/net_storage/s3/base'
2
2
 
3
3
  class Capistrano::NetStorage::S3
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-net_storage-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - progrhyme
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano-net_storage