capistrano-s3 2.1.1 → 2.2.0

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: 8b0c3935d05258b33d19639d14d0fb32a37319db
4
- data.tar.gz: ab9319e9b78510f2e5aab8a265c24e877dc36b80
3
+ metadata.gz: f5218a88b280adaa259766a5e7a319e06c278956
4
+ data.tar.gz: 35bf3e49a5cab9ece24767916d0e97e33a146ff8
5
5
  SHA512:
6
- metadata.gz: 47e1998a7b7360a52d0bb34b2b20cbe16e35dc58a3a092b7b5215665cf1c2fdf9edb25db46b5caef55ce07489a243a7a9aa527dbd777e6d7228ab5dd91d97531
7
- data.tar.gz: abcb8607f6fe7724328d20c7adad16737cedd42c9a66f1cf6221fb1ac5a2c7d67cfb43ccec33932da64101b3e249750ad33ed796d9c9e3ecfbcfc94c0dd3fff6
6
+ metadata.gz: 73feab08d5b0c5c914a02b2c5db47403d44205b49c334a80639365c3a1eb1e6f363380a410ff1f94bf278459299684a7278e1b3b17f211465c680d6520cec4f0
7
+ data.tar.gz: 7b6c516974ed73332988faf8ecde09ee8aff8706d0bdabc2822bf506701cd5a62d5492262221c9b632545645907f3661af5339aacbf634fc4033eda44d28616a
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- ���Y=�&s���Zo���V2pvu]s��(`L���>���"EEkBV39��BA 9�"MEQCJ(����С����tmv_x2�������B�ݖI��O�V
2
- �T4��hE{�`�o �=�W�CM��_��P��q"EBob��L�T{���Sc
1
+ 1.�z5�F<�ݳ���p�����]�}#� �o"����]$�u��� �28z�͵�qg���|7 Y��hЕl�d4����9�o,�뇱ԕ��m9n 56 ����j�vMΩzT�_e�����|��:����ߛ����.��5��G �v�� O���_5"إ7IO{�a�Q��7���o����wYt!9��4c`z 5H�1�л��q�?a���(��C�0aF���tQ�׭���$��
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v2.2.0
4
+
5
+ Feature : Allow to deploy to multiple stages and buckets (#41)
6
+ Fix : issue with new target_path feature (#40)
7
+
3
8
  ## v2.1.1
4
9
 
5
10
  Update : removed locked & old net-ssh dependency for Ruby 1.9
@@ -11,7 +16,7 @@ Change : Relax mime-types version requirement (#36)
11
16
 
12
17
  ## v2.0.0
13
18
 
14
- Major change : AWS SDK dependency was upgragred to 2.6, see migration guide at bottom of README to upgrade from v1.
19
+ Major change : AWS SDK dependency was upgraded to 2.6, see migration guide at bottom of README to upgrade from v1.
15
20
  Feature : Add wait_for_invalidation task (#32) @exoszajzbuk
16
21
  Improvement : Simpler way to set deployment_path (#33) @j15e
17
22
 
@@ -8,14 +8,14 @@ module Capistrano
8
8
  LAST_PUBLISHED_FILE = '.last_published'
9
9
  LAST_INVALIDATION_FILE = '.last_invalidation'
10
10
 
11
- def self.publish!(region, key, secret, bucket, deployment_path, target_path, distribution_id, invalidations, exclusions, only_gzip, extra_options)
11
+ def self.publish!(region, key, secret, bucket, deployment_path, target_path, distribution_id, invalidations, exclusions, only_gzip, extra_options, stage = 'default')
12
12
  deployment_path_absolute = File.expand_path(deployment_path, Dir.pwd)
13
13
  s3 = self.establish_s3_client_connection!(region, key, secret)
14
14
  updated = false
15
15
 
16
16
  self.files(deployment_path_absolute, exclusions).each do |file|
17
17
  if !File.directory?(file)
18
- next if self.published?(file)
18
+ next if self.published?(file, bucket, stage)
19
19
  next if only_gzip && self.has_gzipped_version?(file)
20
20
 
21
21
  path = self.base_file_path(deployment_path_absolute, file)
@@ -34,7 +34,9 @@ module Capistrano
34
34
  :invalidation_batch => {
35
35
  :paths => {
36
36
  :quantity => invalidations.count,
37
- :items => invalidations.map { |path| File.join('/', target_path, path) }
37
+ :items => invalidations.map do |path|
38
+ File.join('/', self.add_prefix(path, prefix: target_path))
39
+ end
38
40
  },
39
41
  :caller_reference => SecureRandom.hex
40
42
  }
@@ -45,18 +47,18 @@ module Capistrano
45
47
  end
46
48
  end
47
49
 
48
- FileUtils.touch(LAST_PUBLISHED_FILE)
50
+ self.published_to!(bucket, stage)
49
51
  end
50
52
 
51
- def self.clear!(region, key, secret, bucket)
53
+ def self.clear!(region, key, secret, bucket, stage = 'default')
52
54
  s3 = self.establish_s3_connection!(region, key, secret)
53
55
  s3.buckets[bucket].clear!
54
56
 
55
- FileUtils.rm(LAST_PUBLISHED_FILE)
57
+ self.clear_published!(bucket, stage)
56
58
  FileUtils.rm(LAST_INVALIDATION_FILE)
57
59
  end
58
60
 
59
- def self.check_invalidation(region, key, secret, distribution_id)
61
+ def self.check_invalidation(region, key, secret, distribution_id, stage = 'default')
60
62
  last_invalidation_id = File.read(LAST_INVALIDATION_FILE).strip
61
63
 
62
64
  cf = self.establish_cf_client_connection!(region, key, secret)
@@ -100,9 +102,29 @@ module Capistrano
100
102
  Dir.glob("#{deployment_path}/**/*") - Dir.glob(exclusions.map { |e| "#{deployment_path}/#{e}" })
101
103
  end
102
104
 
103
- def self.published?(file)
104
- return false unless File.exists? LAST_PUBLISHED_FILE
105
- File.mtime(file) < File.mtime(LAST_PUBLISHED_FILE)
105
+ def self.last_published
106
+ if File.exists? LAST_PUBLISHED_FILE
107
+ YAML.load_file(LAST_PUBLISHED_FILE) || {}
108
+ else
109
+ {}
110
+ end
111
+ end
112
+
113
+ def self.published_to!(bucket, stage)
114
+ current_publish = self.last_published
115
+ current_publish["#{bucket}::#{stage}"] = Time.now.iso8601
116
+ File.write(LAST_PUBLISHED_FILE, current_publish.to_yaml)
117
+ end
118
+
119
+ def self.clear_published!(bucket, stage)
120
+ current_publish = self.last_published
121
+ current_publish["#{bucket}::#{stage}"] = nil
122
+ File.write(LAST_PUBLISHED_FILE, current_publish.to_yaml)
123
+ end
124
+
125
+ def self.published?(file, bucket, stage)
126
+ return false unless last_publish_time = self.last_published["#{bucket}::#{stage}"]
127
+ File.mtime(file) < Time.parse(last_publish_time)
106
128
  end
107
129
 
108
130
  def self.put_object(s3, bucket, target_path, path, file, only_gzip, extra_options)
@@ -110,7 +132,7 @@ module Capistrano
110
132
  mime_type = mime_type_for_file(base_name)
111
133
  options = {
112
134
  :bucket => bucket,
113
- :key => File.join(target_path, path),
135
+ :key => self.add_prefix(path, prefix: target_path),
114
136
  :body => open(file),
115
137
  :acl => 'public-read',
116
138
  }
@@ -126,7 +148,7 @@ module Capistrano
126
148
  options.merge!(build_gzip_content_type_hash(file, mime_type))
127
149
 
128
150
  # upload as original file name
129
- options.merge!(key: File.join(target_path, self.orig_name(path))) if only_gzip
151
+ options.merge!(key: self.add_prefix(self.orig_name(path), prefix: target_path)) if only_gzip
130
152
  end
131
153
  end
132
154
 
@@ -172,6 +194,14 @@ module Capistrano
172
194
  def self.orig_name(file)
173
195
  file.sub(/\.gz$/, "")
174
196
  end
197
+
198
+ def self.add_prefix(path, prefix:)
199
+ if prefix.empty?
200
+ path
201
+ else
202
+ File.join(prefix, path)
203
+ end
204
+ end
175
205
  end
176
206
  end
177
207
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module S3
3
- VERSION = "2.1.1"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
@@ -8,19 +8,19 @@ namespace :deploy do
8
8
  namespace :s3 do
9
9
  desc "Empties bucket of all files. Caution when using this command, as it cannot be undone!"
10
10
  task :empty do
11
- Capistrano::S3::Publisher.clear!(fetch(:region), fetch(:access_key_id), fetch(:secret_access_key), fetch(:bucket))
11
+ Capistrano::S3::Publisher.clear!(fetch(:region), fetch(:access_key_id), fetch(:secret_access_key), fetch(:bucket), fetch(:stage))
12
12
  end
13
13
 
14
14
  desc "Waits until the last CloudFront invalidation batch is completed"
15
15
  task :wait_for_invalidation do
16
- Capistrano::S3::Publisher.check_invalidation(fetch(:region), fetch(:access_key_id), fetch(:secret_access_key), fetch(:distribution_id))
16
+ Capistrano::S3::Publisher.check_invalidation(fetch(:region), fetch(:access_key_id), fetch(:secret_access_key), fetch(:distribution_id), fetch(:stage))
17
17
  end
18
18
 
19
19
  desc "Upload files to the bucket in the current state"
20
20
  task :upload_files do
21
21
  extra_options = { :write => fetch(:bucket_write_options), :redirect => fetch(:redirect_options) }
22
22
  Capistrano::S3::Publisher.publish!(fetch(:region), fetch(:access_key_id), fetch(:secret_access_key),
23
- fetch(:bucket), fetch(:deployment_path), fetch(:target_path), fetch(:distribution_id), fetch(:invalidations), fetch(:exclusions), fetch(:only_gzip), extra_options)
23
+ fetch(:bucket), fetch(:deployment_path), fetch(:target_path), fetch(:distribution_id), fetch(:invalidations), fetch(:exclusions), fetch(:only_gzip), extra_options, fetch(:stage))
24
24
  end
25
25
  end
26
26
 
@@ -10,12 +10,12 @@ describe Capistrano::S3::Publisher do
10
10
  context "on publish!" do
11
11
  it "publish all files" do
12
12
  Aws::S3::Client.any_instance.expects(:put_object).times(8)
13
- Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], [], false, {})
13
+ Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], [], false, {}, 'staging')
14
14
  end
15
15
 
16
16
  it "publish only gzip files when option is enabled" do
17
17
  Aws::S3::Client.any_instance.expects(:put_object).times(4)
18
- Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], [], true, {})
18
+ Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], [], true, {}, 'staging')
19
19
  end
20
20
 
21
21
  context "invalidations" do
@@ -23,14 +23,14 @@ describe Capistrano::S3::Publisher do
23
23
  Aws::S3::Client.any_instance.expects(:put_object).times(8)
24
24
  Aws::CloudFront::Client.any_instance.expects(:create_invalidation).once
25
25
 
26
- Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', ['*'], [], false, {})
26
+ Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', ['*'], [], false, {}, 'staging')
27
27
  end
28
28
 
29
29
  it "publish all files without invalidations" do
30
30
  Aws::S3::Client.any_instance.expects(:put_object).times(8)
31
31
  Aws::CloudFront::Client.any_instance.expects(:create_invalidation).never
32
32
 
33
- Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], [], false, {})
33
+ Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], [], false, {}, 'staging')
34
34
  end
35
35
  end
36
36
 
@@ -39,21 +39,21 @@ describe Capistrano::S3::Publisher do
39
39
  Aws::S3::Client.any_instance.expects(:put_object).times(7)
40
40
 
41
41
  exclude_paths = ['fonts/cantarell-regular-webfont.svg']
42
- Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], exclude_paths, false, {})
42
+ Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], exclude_paths, false, {}, 'staging')
43
43
  end
44
44
 
45
45
  it "exclude multiple files" do
46
46
  Aws::S3::Client.any_instance.expects(:put_object).times(6)
47
47
 
48
48
  exclude_paths = ['fonts/cantarell-regular-webfont.svg', 'fonts/cantarell-regular-webfont.svg.gz']
49
- Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], exclude_paths, false, {})
49
+ Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], exclude_paths, false, {}, 'staging')
50
50
  end
51
51
 
52
52
  it "exclude directory" do
53
53
  Aws::S3::Client.any_instance.expects(:put_object).times(0)
54
54
 
55
55
  exclude_paths = ['fonts/**/*']
56
- Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], exclude_paths, false, {})
56
+ Capistrano::S3::Publisher.publish!('s3.amazonaws.com', 'abc', '123', 'mybucket.amazonaws.com', 'spec/sample', '', 'cf123', [], exclude_paths, false, {}, 'staging')
57
57
  end
58
58
  end
59
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Philippe Doyle
@@ -36,7 +36,7 @@ cert_chain:
36
36
  t/JsZnAlWYkJIees2SFV5X/t34oeMu04yY2u9y2YBqKovR97m5YF7zqgx0JODV0x
37
37
  ytwUJvEjznBnJV4OoDE=
38
38
  -----END CERTIFICATE-----
39
- date: 2017-05-05 00:00:00.000000000 Z
39
+ date: 2017-08-30 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: aws-sdk
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.6.10
209
+ rubygems_version: 2.6.12
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Build and deploy a static website to Amazon S3
metadata.gz.sig CHANGED
@@ -1,3 +1,3 @@
1
- �늌�/����l�N�z�Pw'-���i^E���0�����K���Nb��� J��YiR��3�<�E�5q��0
2
- D��<�՛���z�L��r�����!nh#l��a~ַ�e��c,%Tgn�kʇ6CCVY(*@s�*�l�p�<H�������d��e���1/Q�f
3
-
1
+ ���mW�%�Z�?E�v��l�ę_�@[G@���!,bS��I?7�p�|���+EQz�ҁ�RGaV�g��W��� �z���) ��P�ˣ�f 4��W4X��q�mXE%w�E�"*ș wg/�#
2
+ Yt����j��YyMFh�����1��1���'RqKg{0��}2���xa�9����?�f��1g��*���-Z~�e�}�Y
3
+ �g�8!�C��:�6�f����0}�Q '�v����D��M�ƒ_�5�