aws_one_click_staging 0.0.6 → 0.0.7

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: 9f71fa64a4b604a12dc314c4642ff3afb2d010fe
4
- data.tar.gz: bd848bdb29d799c1f1a2cb30d53b315115431789
3
+ metadata.gz: a9e972947656fc8ccaf30c1cd6d5cf6355d8baca
4
+ data.tar.gz: 5b29ee1a07385d35aa42a19d4374099cda86d857
5
5
  SHA512:
6
- metadata.gz: 10b293e91ca0ea581c680e246503cfbdeebdde0cb8e456255cced315f7142806123854867af5371a1643778ffd94b1e75caa6567d2fed6df124bdde2b0f31b04
7
- data.tar.gz: 9b7f6ff8f14df55133404d8ff9c9c61e3136f5f7f6034d25087067d197c8e799de3cd366206d2a418acb504d49e346b05d724a719d2c15325a9a8ada06a7e1db
6
+ metadata.gz: 61032bae2a85ea76f27fa846135cff4e249f427a4a2afddcc25b0987f3e896a7ecd6bc60dac1bca4c087c40fb8ca69559b7d82a1a4c840101868e537a3e396e0
7
+ data.tar.gz: f45ffeb216713fbc204471459e71125b0e3a9f2a4ba73b31cbc52d9f0f95b9959fca9df66822f131e8c0f60fc5da1b37c460fad8afd6b996e518389779b3c9bf
data/README.md CHANGED
@@ -40,11 +40,132 @@ aws_one_click_staging stage
40
40
 
41
41
  After a while, the operation will complete and it will say 'congrats' or something and output the RDS url and bucket name for the staging clone. Plug those values into your staging server and you should be good to go.
42
42
 
43
+ ## AWS Permissions
44
+
45
+ Because you're a professional, you want to grant only the permissions absolutely necessary to the 'staging-bot' user.
46
+ 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).
47
+
48
+ (staging-bot-rds-can-do-anything-to-staging-db)
49
+ ```
50
+ {
51
+ "Version": "2012-10-17",
52
+ "Statement": [
53
+ {
54
+ "Sid": "Stmt1448499769000",
55
+ "Effect": "Allow",
56
+ "Action": [
57
+ "rds:*"
58
+ ],
59
+ "Resource": [
60
+ "arn:aws:rds:*:*:db:PRODUCTIONDB-staging"
61
+ ]
62
+ }
63
+ ]
64
+ }
65
+ ```
66
+ (staging-bot-rds-can-do-anything-to-staging-snapshot)
67
+ ```
68
+ {
69
+ "Version": "2012-10-17",
70
+ "Statement": [
71
+ {
72
+ "Sid": "Stmt1448518052000",
73
+ "Effect": "Allow",
74
+ "Action": [
75
+ "rds:*"
76
+ ],
77
+ "Resource": [
78
+ "arn:aws:rds:*:*:snapshot:PRODUCTIONDB-snapshot-for-staging"
79
+ ]
80
+ }
81
+ ]
82
+ }
83
+ ```
84
+ (staging-bot-rds-can-snapshot-production-db)
85
+ ```
86
+ {
87
+ "Version": "2012-10-17",
88
+ "Statement": [
89
+ {
90
+ "Sid": "Stmt1448517746000",
91
+ "Effect": "Allow",
92
+ "Action": [
93
+ "rds:CreateDBSnapshot"
94
+ ],
95
+ "Resource": [
96
+ "arn:aws:rds:*:*:db:PRODUCTIONDB"
97
+ ]
98
+ }
99
+ ]
100
+ }
101
+ ```
102
+ (staging-bot-s3-can-do-anything-to-staging-bucket)
103
+ ```
104
+ {
105
+ "Version": "2012-10-17",
106
+ "Statement": [
107
+ {
108
+ "Sid": "Stmt1448518841000",
109
+ "Effect": "Allow",
110
+ "Action": [
111
+ "s3:*"
112
+ ],
113
+ "Resource": [
114
+ "arn:aws:s3:::PRODUCTIONDB-staging",
115
+ "arn:aws:s3:::PRODUCTIONDB-staging/*"
116
+ ]
117
+ }
118
+ ]
119
+ }
120
+ ```
121
+ (staging-bot-s3-can-read-from-production-bucket)
122
+ ```
123
+ {
124
+ "Version": "2012-10-17",
125
+ "Statement": [
126
+ {
127
+ "Sid": "Stmt1448523618000",
128
+ "Effect": "Allow",
129
+ "Action": [
130
+ "s3:GetBucketAcl",
131
+ "s3:GetBucketCORS",
132
+ "s3:GetBucketLocation",
133
+ "s3:GetBucketLogging",
134
+ "s3:GetBucketNotification",
135
+ "s3:GetBucketPolicy",
136
+ "s3:GetBucketRequestPayment",
137
+ "s3:GetBucketTagging",
138
+ "s3:GetBucketVersioning",
139
+ "s3:GetBucketWebsite",
140
+ "s3:GetLifecycleConfiguration",
141
+ "s3:GetObject",
142
+ "s3:GetObjectAcl",
143
+ "s3:GetObjectTorrent",
144
+ "s3:GetObjectVersion",
145
+ "s3:GetObjectVersionAcl",
146
+ "s3:GetObjectVersionTorrent",
147
+ "s3:ListAllMyBuckets",
148
+ "s3:ListBucket",
149
+ "s3:ListBucketMultipartUploads",
150
+ "s3:ListBucketVersions",
151
+ "s3:ListMultipartUploadParts"
152
+ ],
153
+ "Resource": [
154
+ "arn:aws:s3:::PRODUCTIONDB"
155
+ ]
156
+ }
157
+ ]
158
+ }
159
+ ```
160
+
43
161
 
44
162
  ## Development
45
163
 
46
164
  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).
47
165
 
166
+ 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.
167
+
168
+
48
169
  ## Contributing
49
170
 
50
171
  1. Fork it ( https://github.com/[my-github-username]/aws_one_click_staging/fork )
@@ -17,8 +17,6 @@ module AwsOneClickStaging
17
17
  def clone_rds
18
18
  setup_aws_credentials
19
19
 
20
-
21
-
22
20
  @c = Aws::RDS::Client.new
23
21
 
24
22
  delete_snapshot_for_staging!
@@ -26,6 +24,7 @@ module AwsOneClickStaging
26
24
 
27
25
  delete_staging_db_instance!
28
26
  spawn_new_staging_db_instance!
27
+ print_staging_db_uri
29
28
  end
30
29
 
31
30
  def clone_s3_bucket
@@ -39,7 +38,7 @@ module AwsOneClickStaging
39
38
  bucket: @aws_staging_bucket}
40
39
 
41
40
  bs = BucketSyncService.new(from_creds, to_creds)
42
-
41
+ #bs.debug = true
43
42
  bs.perform
44
43
  end
45
44
 
@@ -67,7 +66,7 @@ module AwsOneClickStaging
67
66
  puts "deleting old staging db snapshot"
68
67
  response = @c.delete_db_snapshot(db_snapshot_identifier: @db_snapshot_id)
69
68
 
70
- sleep 1 while response.percent_progress != 100
69
+ sleep 1 while response.db_snapshot.percent_progress != 100
71
70
  true
72
71
  rescue
73
72
  false
@@ -86,9 +85,10 @@ module AwsOneClickStaging
86
85
 
87
86
 
88
87
  def delete_staging_db_instance!
89
- response = @c.delete_db_instance(db_instance_identifier: @db_instance_id_staging)
88
+ response = @c.delete_db_instance(db_instance_identifier: @db_instance_id_staging,
89
+ skip_final_snapshot: true)
90
90
 
91
- sleep 2 while response.percent_progress != 100
91
+ sleep 10 until db_instance_is_deleted?(@db_instance_id_staging)
92
92
  rescue
93
93
  false
94
94
  end
@@ -101,7 +101,7 @@ module AwsOneClickStaging
101
101
  master_user_password: @master_user_password,
102
102
  allocated_storage: "10")
103
103
 
104
- sleep 10 while get_fresh_db_instance_state.db_instance_status != "available"
104
+ sleep 10 while get_fresh_db_instance_state(@db_instance_id_staging).db_instance_status != "available"
105
105
  end
106
106
 
107
107
 
@@ -110,8 +110,26 @@ module AwsOneClickStaging
110
110
  @c.describe_db_snapshots(db_snapshot_identifier: @db_snapshot_id).db_snapshots.first
111
111
  end
112
112
 
113
- def get_fresh_db_instance_state
114
- @c.describe_db_instances(db_instance_identifier: @db_instance_id_staging).db_instances.first
113
+ def get_fresh_db_instance_state(db_instance_id)
114
+ @c.describe_db_instances(db_instance_identifier: db_instance_id).db_instances.first
115
+ end
116
+
117
+ def db_instance_is_deleted?(db_instance_id)
118
+ @c.describe_db_instances(db_instance_identifier: db_instance_id).db_instances.first
119
+ false
120
+ rescue Aws::RDS::Errors::DBInstanceNotFound => e
121
+ true
122
+ end
123
+
124
+ def print_staging_db_uri
125
+ l = 65
126
+ msg = ""
127
+ msg += "*" * l + "\n"
128
+ msg += "* "
129
+ msg += get_fresh_db_instance_state(@db_instance_id_staging).endpoint.address
130
+ msg += " *\n"
131
+ msg += "*" * l
132
+ puts msg
115
133
  end
116
134
 
117
135
 
@@ -1,3 +1,3 @@
1
1
  module AwsOneClickStaging
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_one_click_staging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheNotary