docker_rails_proxy 0.0.2 → 0.0.3

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: 78dfed44ff1431c3e5216b9d354a1dd208b5f479
4
- data.tar.gz: 8e5b2f9ec42d2a826e3814cf6c122a33905b5273
3
+ metadata.gz: 46209c1765250f4682e94b8683c3d4d9a283cd81
4
+ data.tar.gz: 2a14b285c999e7ee40384db4dc79959f38dcce0d
5
5
  SHA512:
6
- metadata.gz: cc5c27596574efc2690de74f50d9c2a4bfe28f9c0badbc2f64bc112c4ffb1026d68ea625add78bf4109e30460cee2cfda3382e2d8ab5fd6878fd369b0f8acebe
7
- data.tar.gz: 8432d2afe6b3a3a91c0e1127963270617dde46b7a4983648ea9559567b4a129c0ddc5fc1ccfdcb857697fca25797c77516871461295bba13152acf2410ebd08e
6
+ metadata.gz: f6b857bbcf6c3af589c1bb654ca4dc491a27089cd7fd0c9012554cf91d8d63ca4812431ce1446fd5025ad5ab0e8fc55a282f3c35d51bc737130854bdf93cbac0
7
+ data.tar.gz: b87e1570ed1c61534c5d2303968e04294ed2aa5c0b9c6b35b66ecd53311208aed60e17e8081ee5a2e0182bce321497a8057022d6426c3a10288e39cb8033ab07
@@ -0,0 +1,18 @@
1
+ module DockerRailsProxy
2
+ class DataBags < AwsCli
3
+ class Pull < self
4
+ def process
5
+ if system <<-EOS.strip
6
+ aws s3 sync '#{options[:bucket_path]}' '#{options[:folder]}' \
7
+ --delete \
8
+ --exact-timestamps \
9
+ #{exclude_args} \
10
+ --profile '#{options[:profile]}'
11
+ EOS
12
+
13
+ puts "Data bags pulled from #{options[:bucket_path]} to #{options[:folder]}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ module DockerRailsProxy
2
+ class DataBags < AwsCli
3
+ class Push < self
4
+
5
+ after_initialize do
6
+ if File.exist?(options[:summary_path])
7
+ self.local_summary = File.read(options[:summary_path])
8
+ end
9
+ end
10
+
11
+ validates do
12
+ unless local_summary == bucket_summary
13
+ %{
14
+ It seems that someone else pushed something to #{options[:bucket_path]}.
15
+ Use `bin/#{APP_NAME} data-bags pull` to sync the data-bags.
16
+
17
+ P.S. Your changes will be discarded.
18
+ }
19
+ end
20
+ end
21
+
22
+ def process
23
+ if system <<-EOS
24
+ aws s3 sync '#{options[:folder]}' '#{options[:bucket_path]}' \
25
+ --delete \
26
+ --exact-timestamps \
27
+ #{exclude_args} \
28
+ --profile '#{options[:profile]}' \
29
+ --sse aws:kms
30
+ EOS
31
+
32
+ puts "Data bags pushed from #{options[:folder]} to #{options[:bucket_path]}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,65 +2,69 @@ require 'optparse'
2
2
 
3
3
  module DockerRailsProxy
4
4
  class DataBags < AwsCli
5
- attr_accessor :options
5
+ autoload :Pull, 'docker_rails_proxy/commands/data_bags/pull'
6
+ autoload :Push, 'docker_rails_proxy/commands/data_bags/push'
7
+
8
+ EXCLUDE = %w[.summary *.swp *.DS_Store].freeze
9
+
10
+ attr_accessor :options, :local_summary
6
11
 
7
12
  after_initialize { self.options = {} }
8
13
  after_initialize :parse_options!, :set_defaults
9
14
 
10
- before_process :set_folder_and_bucket
11
-
12
15
  validates { '--profile is required.' if options[:profile].nil? }
13
16
  validates { '--bucket is required.' if options[:bucket].nil? }
14
17
 
15
- def process
16
- case arguments.first
17
- when 'pull' then pull
18
- when 'push' then push
19
- else
20
- opt_parser.parse %w(-h)
18
+ validates do
19
+ unless system <<-EOS.strip
20
+ aws s3 ls --profile '#{options[:profile]}' | grep '#{options[:bucket]}'
21
+ EOS
22
+
23
+ "#{options[:bucket]} bucket does not exit."
21
24
  end
22
25
  end
23
26
 
24
- private
25
-
26
- def pull
27
- if system <<-EOS.strip
28
- aws s3 sync '#{options[:bucket]}' '#{options[:folder]}' \
29
- --delete \
30
- --exact-timestamps \
31
- --profile '#{options[:profile]}'
32
- EOS
27
+ after_process do
28
+ if File.directory?(options[:folder])
29
+ File.write(options[:summary_path], bucket_summary.strip)
30
+ end
31
+ end
33
32
 
34
- puts "Data bags pulled from #{options[:bucket]} to #{options[:folder]}"
33
+ builds -> (params:) do
34
+ case params[:arguments].shift
35
+ when 'pull' then Pull
36
+ when 'push' then Push
37
+ else
38
+ puts "Usage: bin/#{APP_NAME} #{command} <pull|push> [options]"
39
+ exit
35
40
  end
36
41
  end
37
42
 
38
- def push
39
- puts "#{options[:bucket]} will be synced with #{options[:folder]}, are you sure?: [yes]"
40
- confirm = $stdin.gets.chomp
43
+ private
41
44
 
42
- exit unless confirm == 'yes'
45
+ def bucket_summary
46
+ summary = %x(
47
+ aws s3 ls '#{options[:bucket]}' --summarize --recursive \
48
+ --profile '#{options[:profile]}' | grep -v '^$' | sort -n
49
+ ).strip.split("\n")
43
50
 
44
- if system <<-EOS
45
- aws s3 sync '#{options[:folder]}' '#{options[:bucket]}' \
46
- --delete \
47
- --exact-timestamps \
48
- --profile '#{options[:profile]}' \
49
- --sse aws:kms
50
- EOS
51
+ # 0 => Total Size
52
+ # 1 => Total Objects
53
+ # last => last updated file
54
+ (summary[ 0..1 ] << summary.last).map{|s| s.gsub(/\D/, ''.freeze) }.join('-')
55
+ end
51
56
 
52
- puts "Data bags pushed from #{options[:folder]} to #{options[:bucket]}"
53
- end
57
+ def exclude_args
58
+ EXCLUDE.map{|s| "--exclude '#{s}'" }.join(' ')
54
59
  end
55
60
 
56
61
  def set_defaults
57
62
  options[:profile] ||= APP_NAME
58
63
  options[:bucket] ||= "#{APP_NAME}-data-bags"
59
- end
60
64
 
61
- def set_folder_and_bucket
62
- options[:folder] = build_path('.data-bags')
63
- options[:bucket] = "s3://#{options[:bucket]}"
65
+ options[:bucket_path] = "s3://#{options[:bucket]}"
66
+ options[:folder] = build_path(".data-bags/#{options[:bucket]}")
67
+ options[:summary_path] = "#{options[:folder]}/.summary"
64
68
  end
65
69
 
66
70
  def parse_options!
@@ -37,7 +37,7 @@ module DockerRailsProxy
37
37
  exit 1
38
38
  end
39
39
  else
40
- puts "Usage: bin/#{APP_NAME} stack <create|destroy|deploy> [options]"
40
+ puts "Usage: bin/#{APP_NAME} #{command} <create|destroy|deploy> [options]"
41
41
  exit
42
42
  end
43
43
  end
@@ -21,7 +21,9 @@ class String
21
21
  end
22
22
 
23
23
  def parameterize(separator = '-'.freeze)
24
- downcase.gsub(/\W/, separator).gsub('_'.freeze, separator)
24
+ split(/(?=[A-Z])/).join(separator)
25
+ .downcase.gsub(/\W/, separator)
26
+ .gsub('_'.freeze, separator)
25
27
  end
26
28
 
27
29
  def present?
@@ -1,3 +1,3 @@
1
1
  module DockerRailsProxy
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_rails_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jairo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-04 00:00:00.000000000 Z
12
+ date: 2016-11-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Configures docker-compose and provides rails command helpers
15
15
  email:
@@ -31,6 +31,8 @@ files:
31
31
  - lib/docker_rails_proxy/commands/compose/proxy.rb
32
32
  - lib/docker_rails_proxy/commands/compose/up.rb
33
33
  - lib/docker_rails_proxy/commands/data_bags.rb
34
+ - lib/docker_rails_proxy/commands/data_bags/pull.rb
35
+ - lib/docker_rails_proxy/commands/data_bags/push.rb
34
36
  - lib/docker_rails_proxy/commands/rails.rb
35
37
  - lib/docker_rails_proxy/commands/rake.rb
36
38
  - lib/docker_rails_proxy/commands/rspec.rb