aws_one_click_staging 0.1.1 → 0.1.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: d779231c0e0dc99fe5f3c7ed558c953517b52eb0
4
- data.tar.gz: 6bad4ad285f0cc504c48b32efcecb0ed00660692
3
+ metadata.gz: eed057b20d3a62ae312c0c390fb47ede95b1eb03
4
+ data.tar.gz: 36281e22f2ea58d70d5e7674dc6d502972103a21
5
5
  SHA512:
6
- metadata.gz: 20456486a2357d797831905748a5352a8ad32aed06e11682c2071c3957066ed1341b744f3b5831076f374b1cc3f15085dd5517e0d7f4f2e443573efb0e5c7a01
7
- data.tar.gz: 2c3e1a8eb4829d92be2edab97e39fff8edc018a6f51e3c5f6712ad7fe003e1db97f3e0ee4b487e2a36466c30d10041650337e07b68a18781a1a1f1726c01778b
6
+ metadata.gz: 20af3681b0de1ad656917b8b5f56da342dec76467e17c0fdd7d190134c21137ca793e439d2b14fe77785988daeec644d8c71fd25f2ad6eac3f556d440cee6436
7
+ data.tar.gz: 87ffdce901f9e9881be8b5df95ed27de21923f3c5b2ae7772d503a28475c193e23c7160a353f392fc8cd4d0f0abab7e46b9686de70e928633fecc4b2903a8691
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  AwsOneClickStaging is a CLI app that will allow you to create a clone of amazon's S3 bucket (named app_name-staging) and the RDS database (named app_name-staging) so your staging server will be 100% up to date with your production server and allow you to perform some serious testing without the fear of losing important files stored on your S3 bucket.
4
4
 
5
- If you didn't already know, S3 is a file storage solution offered by Amazon, and it's not user friendly so you pretty much need to write/ use a script like this in order to setup a staging server. RDS is Amazon's database storage. As with all amazon services, RDS databases are in the clown so you can rely on it working well with your app and working hard to provide your users with hillarious service.
5
+ If you didn't already know, S3 is a file storage solution offered by Amazon, and it's not user friendly so you pretty much need to write/ use a script like this in order to setup a staging server. RDS is Amazon's database storage. As with all amazon services, RDS databases are in the clown so you can rely on it working well with your app and working hard to provide your users with hilarious service.
6
6
 
7
7
 
8
8
  ## Installation
@@ -20,7 +20,6 @@ Next you'll need to setup the config file:
20
20
  aws_access_key_id: ""
21
21
  aws_secret_access_key: ""
22
22
  aws_region: 'us-west-1'
23
- aws_master_username: ""
24
23
  aws_master_user_password: ""
25
24
  aws_production_bucket: "" # this bucket is read from
26
25
  aws_staging_bucket: "" # this bucket is DELETED and written to!
@@ -45,7 +44,7 @@ After a while, the operation will complete and it will say 'congrats' or somethi
45
44
  ## AWS Permissions
46
45
 
47
46
  Because you're a professional, you want to grant only the permissions absolutely necessary to the 'staging-bot' user.
48
- That's commendable. Use the below scripts and replace `PRODUCTIONDB` with the name of your production database/ s3 bucket (hopefully you used the same name for both). These rules are set via the `Identity & Access Management` subconsole on amazon.
47
+ That's commendable. Use the below rules, replacing `PRODUCTIONDB` with the name of your production database/ s3 bucket (hopefully you used the same name for both). These rules are set via the `Identity & Access Management` subconsole on amazon.
49
48
 
50
49
  (staging-bot-rds-can-do-anything-to-staging-db)
51
50
  ```
@@ -166,7 +165,7 @@ That's commendable. Use the below scripts and replace `PRODUCTIONDB` with the n
166
165
 
167
166
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
168
167
 
169
- There's a couple unit tests with commented out method calls. This was how I tested against amazon, simply uncomment a line, drop in a `binding.pry;exit!` and test/ debug what ever methods you think are messing up.
168
+ There's a couple unit tests with commented out method calls. This was how I tested against amazon, simply uncomment a line, drop in a `binding.pry;exit!` and test/ debug what ever methods you think are messing up. Also, if you create the file config/aws_actual_fffing_secrets.yml, you can set the config variables that will be used throughout testing... naturally, ensure such credentials never see the light of github.
170
169
 
171
170
 
172
171
  ## Contributing
@@ -176,3 +175,8 @@ There's a couple unit tests with commented out method calls. This was how I tes
176
175
  3. Commit your changes (`git commit -am 'Add some feature'`)
177
176
  4. Push to the branch (`git push origin my-new-feature`)
178
177
  5. Create a new Pull Request
178
+
179
+
180
+ ## Credits
181
+ Cory Forsyth [Bantic](github.com/bantic) wrote the S3 synchronization code used by this gem.
182
+ rob@eff did the other stuff.
File without changes
@@ -0,0 +1,14 @@
1
+ ## Future
2
+
3
+ * Should have multi-app support for config file
4
+
5
+
6
+ ## 0.1.1
7
+
8
+ - Added multi-threaded support (up to 16 requests at a time!)
9
+
10
+ ## 0.1.0
11
+
12
+ - released the gem kinda
13
+
14
+
@@ -7,7 +7,6 @@ aws_access_key_id: ""
7
7
  aws_secret_access_key: ""
8
8
 
9
9
  aws_region: 'us-west-1'
10
- aws_master_username: ""
11
10
  aws_master_user_password: ""
12
11
  aws_production_bucket: "" # this bucket is read from
13
12
  aws_staging_bucket: "" # this bucket is DELETED and written to!
@@ -44,7 +44,7 @@ module AwsOneClickStaging
44
44
 
45
45
  def get_fancy_string_of_staging_db_uri
46
46
  setup_aws_credentials_and_configs
47
-
47
+
48
48
  l = 66
49
49
  msg = ""
50
50
  msg += "*" * l + "\n"
@@ -61,7 +61,6 @@ module AwsOneClickStaging
61
61
  aws_region = @config["aws_region"]
62
62
  @access_key_id = @config["aws_access_key_id"]
63
63
  @secret_access_key = @config["aws_secret_access_key"]
64
- @master_username = @config["aws_master_username"]
65
64
  @master_user_password = @config["aws_master_user_password"]
66
65
  @aws_production_bucket = @config["aws_production_bucket"]
67
66
  @aws_staging_bucket = @config["aws_staging_bucket"]
@@ -110,14 +109,25 @@ module AwsOneClickStaging
110
109
 
111
110
  def spawn_new_staging_db_instance!
112
111
  puts "Spawning a new fully clony RDS db instance for staging purposes"
113
- response = @c.create_db_instance(db_instance_identifier: @db_instance_id_staging,
114
- db_instance_class: "db.t1.micro",
115
- engine: "postgres",
116
- master_username: @master_username,
117
- master_user_password: @master_user_password,
118
- allocated_storage: "10")
112
+
113
+ @c.describe_db_snapshots(db_snapshot_identifier: @db_snapshot_id).db_snapshots.first
114
+
115
+ response = @c.restore_db_instance_from_db_snapshot(
116
+ db_instance_identifier: @db_instance_id_staging,
117
+ db_snapshot_identifier: @db_snapshot_id,
118
+ db_instance_class: "db.t1.micro"
119
+ )
120
+
119
121
 
120
122
  sleep 10 while get_fresh_db_instance_state(@db_instance_id_staging).db_instance_status != "available"
123
+
124
+ # sets password for staging db and disables automatic backups
125
+ response = @c.modify_db_instance(
126
+ db_instance_identifier: @db_instance_id_staging,
127
+ backup_retention_period: 0,
128
+ master_user_password: @master_user_password
129
+ )
130
+ sleep 2 while get_fresh_db_instance_state(@db_instance_id_staging).db_instance_status != "available"
121
131
  end
122
132
 
123
133
 
@@ -7,13 +7,18 @@ class BucketSyncService
7
7
  attr_reader :from_bucket, :to_bucket, :logger
8
8
  attr_accessor :debug
9
9
 
10
+ # DEFAULT_ACL = :public_read
11
+ # PRIVATE_ACL = :private
12
+
13
+
14
+
10
15
  # from_credentials and to_credentials are both hashes with these keys:
11
16
  # * :aws_access_key_id
12
17
  # * :aws_secret_access_key
13
18
  # * :bucket
14
19
  def initialize(from_credentials, to_credentials)
15
- @from_bucket = get_bucket_reference(from_credentials)
16
- @to_bucket = get_bucket_reference(to_credentials)
20
+ @from_bucket = bucket_from_credentials(from_credentials)
21
+ @to_bucket = bucket_from_credentials(to_credentials)
17
22
  end
18
23
 
19
24
  def perform(output=STDOUT)
@@ -35,7 +40,7 @@ class BucketSyncService
35
40
  object_counts[:skip] += 1
36
41
  end
37
42
  }
38
- sleep 0.01 while threads.select {|t| t.alive?}.count > 16
43
+ sleep 0.01 while threads.select {|t| t.alive?}.count > 16 # throttling
39
44
  end
40
45
 
41
46
 
@@ -55,7 +60,17 @@ class BucketSyncService
55
60
 
56
61
  def sync(object)
57
62
  logger.debug "Syncing #{pp object}"
58
- object.copy_to(to_bucket.objects[object.key])
63
+ acl_setting = file_is_public?(object) ? :public_read : :private
64
+ object.copy_to(to_bucket.objects[object.key], acl: acl_setting)
65
+ end
66
+
67
+ # Crude, but ala aws I think :)
68
+ def file_is_public?(object)
69
+ grants = object.acl.grants
70
+ grants.each do |g|
71
+ return true if g.permission.name == :read && g.grantee.uri == "http://acs.amazonaws.com/groups/global/AllUsers"
72
+ end
73
+ return false
59
74
  end
60
75
 
61
76
  def pp(object)
@@ -71,16 +86,15 @@ class BucketSyncService
71
86
  return to_object.etag != object.etag # does the etag on the dst object differ from src?
72
87
  end
73
88
 
74
- def get_bucket_reference(credentials)
89
+
90
+ def bucket_from_credentials(credentials)
75
91
  s3 = AWS::S3.new(access_key_id: credentials[:aws_access_key_id],
76
92
  secret_access_key: credentials[:aws_secret_access_key])
77
93
 
78
94
  bucket = s3.buckets[ credentials[:bucket] ]
79
- create_bucket_if_needed!(bucket)
80
- end
81
-
82
- def create_bucket_if_needed!(bucket)
83
- return s3.buckets.create( credentials[:bucket] ) if !bucket.exists?
95
+ if !bucket.exists?
96
+ bucket = s3.buckets.create( credentials[:bucket] )
97
+ end
84
98
  bucket
85
99
  end
86
100
  end
@@ -1,3 +1,3 @@
1
1
  module AwsOneClickStaging
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_one_click_staging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheNotary
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-27 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -126,6 +126,7 @@ files:
126
126
  - aws_one_click_staging.gemspec
127
127
  - bin/aws_one_click_staging
128
128
  - changelog
129
+ - changelog.md
129
130
  - config/aws_one_click_staging.yml
130
131
  - lib/aws_one_click_staging.rb
131
132
  - lib/aws_one_click_staging/aws_warrior.rb
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  requirements: []
153
154
  rubyforge_project:
154
- rubygems_version: 2.4.4
155
+ rubygems_version: 2.4.8
155
156
  signing_key:
156
157
  specification_version: 4
157
158
  summary: When setup with the proper credentials, this gem sets up a staging instance