aws_one_click_staging 0.0.7 → 0.1.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: a9e972947656fc8ccaf30c1cd6d5cf6355d8baca
4
- data.tar.gz: 5b29ee1a07385d35aa42a19d4374099cda86d857
3
+ metadata.gz: 3e3cdc6ae9700edde65741d6ff8e797d3b260e45
4
+ data.tar.gz: 21a64e404ca0f783c34d102b858cea2dcf8ec3b0
5
5
  SHA512:
6
- metadata.gz: 61032bae2a85ea76f27fa846135cff4e249f427a4a2afddcc25b0987f3e896a7ecd6bc60dac1bca4c087c40fb8ca69559b7d82a1a4c840101868e537a3e396e0
7
- data.tar.gz: f45ffeb216713fbc204471459e71125b0e3a9f2a4ba73b31cbc52d9f0f95b9959fca9df66822f131e8c0f60fc5da1b37c460fad8afd6b996e518389779b3c9bf
6
+ metadata.gz: 97712b3d3f4bccc0dc6c7a9e1813c43d6bcae612328091a07e7e5ea6cd9e71e11056fabfa4efa59518b098c9a53e0786b0af2d67ca2e98b342f6656d69378891
7
+ data.tar.gz: 6bb7d555055c86dff31d8c814f9b2570b4d3afc116fdfc5e2d52bc71edf1e579a3976b8bbd0166bbc0119ceda0d601bd19998c05aeec173309ed5c527bfe671f
data/README.md CHANGED
@@ -4,6 +4,7 @@ AwsOneClickStaging is a CLI app that will allow you to create a clone of amazon'
4
4
 
5
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.
6
6
 
7
+
7
8
  ## Installation
8
9
 
9
10
  Run this code (you need ruby) to install:
@@ -40,10 +41,11 @@ aws_one_click_staging stage
40
41
 
41
42
  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
43
 
44
+
43
45
  ## AWS Permissions
44
46
 
45
47
  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).
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
49
 
48
50
  (staging-bot-rds-can-do-anything-to-staging-db)
49
51
  ```
@@ -151,7 +153,8 @@ That's commendable. Use the below scripts and replace `PRODUCTIONDB` with the n
151
153
  "s3:ListMultipartUploadParts"
152
154
  ],
153
155
  "Resource": [
154
- "arn:aws:s3:::PRODUCTIONDB"
156
+ "arn:aws:s3:::PRODUCTIONDB",
157
+ "arn:aws:s3:::PRODUCTIONDB/*"
155
158
  ]
156
159
  }
157
160
  ]
@@ -4,19 +4,33 @@ require 'thor'
4
4
  require "aws_one_click_staging"
5
5
 
6
6
  class AwsOneClickStagingRunner < Thor
7
+ default_task :help
7
8
 
8
- default_task :start
9
-
10
- desc "check", "Checks if your ~/.config/aws_one_click_staging.yml for validity"
9
+ desc "check", "Checks your ~/.config/aws_one_click_staging.yml for validity"
11
10
  def check
12
11
  AwsOneClickStaging.check
13
12
  end
14
13
 
15
- desc "stage", "Makes a copy of the RDS database and the staging server's S3 bucket. This takes a while."
14
+ desc "stage", "Makes a copy of the RDS database and the staging server's S3 bucket. This takes a while. Run on an Amazon shell!"
16
15
  def stage
17
16
  AwsOneClickStaging.stage
18
17
  end
19
18
 
19
+ desc "just_rds", "Just clones the RDS part of things."
20
+ def just_rds
21
+ AwsOneClickStaging.just_rds
22
+ end
23
+
24
+ desc "just_s3", "Just clones the s3 part of things."
25
+ def just_s3
26
+ AwsOneClickStaging.just_s3
27
+ end
28
+
29
+ desc "just_ec2", "Just clones the ec2 part of things."
30
+ def just_ec2
31
+ AwsOneClickStaging.just_ec2
32
+ end
33
+
20
34
  desc "version", "Prints gem's version"
21
35
  def version
22
36
  AwsOneClickStaging::VERSION
@@ -14,15 +14,43 @@ module AwsOneClickStaging
14
14
  puts "cloning s3 bucket from amazon... this takes forever..."
15
15
  warrior.clone_s3_bucket
16
16
 
17
- puts "operations completed successfully!"
17
+ puts warrior.get_fancy_string_of_staging_db_uri
18
+
19
+ puts "\nOperations completed successfully!"
18
20
  end
19
21
 
20
22
  def self.check
21
23
  warrior = AwsWarrior.new # this makes a config file if needed
22
- puts "This command *would* test that you have the needed "
23
- puts "permissions on the buckets and rds instances you named "
24
- puts "in your config file... but alas, you're reading the "
25
- puts "outputs of a stubbed method..."
24
+ puts "This command *would* test that you have the needed permissions on the "
25
+ puts "buckets and rds instances you named in your config file... "
26
+ puts "but alas, you're reading the outputs of a stubbed method..."
27
+ end
28
+
29
+ def self.just_s3
30
+ warrior = AwsWarrior.new
31
+ return if warrior.nil?
32
+
33
+ puts "cloning s3 bucket from amazon... this takes forever..."
34
+ warrior.clone_s3_bucket
35
+ puts "\nOperations completed successfully!"
36
+
37
+ end
38
+
39
+ def self.just_rds
40
+ warrior = AwsWarrior.new
41
+ return if warrior.nil?
42
+
43
+ puts "cloning database from amazon... this takes a while..."
44
+ warrior.clone_rds
45
+
46
+ puts warrior.get_fancy_string_of_staging_db_uri
47
+
48
+ puts "\nOperations completed successfully!"
49
+ end
50
+
51
+ def self.just_ec2
52
+ warrior = AwsWarrior.new
53
+ puts "this is a stub because we only did this one time and don't feel need to repeat."
26
54
  end
27
55
 
28
56
  end
@@ -12,23 +12,21 @@ module AwsOneClickStaging
12
12
  @config_file = File.expand_path("#{@config_dir}/aws_one_click_staging.yml")
13
13
  return nil if create_config_file_if_needed!
14
14
  @config = YAML.load(read_config_file)
15
+ setup_aws_credentials_and_configs
15
16
  end
16
17
 
17
18
  def clone_rds
18
- setup_aws_credentials
19
-
20
- @c = Aws::RDS::Client.new
19
+ setup_aws_credentials_and_configs
21
20
 
22
21
  delete_snapshot_for_staging!
23
22
  create_new_snapshot_for_staging!
24
23
 
25
24
  delete_staging_db_instance!
26
25
  spawn_new_staging_db_instance!
27
- print_staging_db_uri
28
26
  end
29
27
 
30
28
  def clone_s3_bucket
31
- setup_aws_credentials
29
+ setup_aws_credentials_and_configs
32
30
 
33
31
  from_creds = { aws_access_key_id: @access_key_id,
34
32
  aws_secret_access_key: @secret_access_key,
@@ -38,14 +36,28 @@ module AwsOneClickStaging
38
36
  bucket: @aws_staging_bucket}
39
37
 
40
38
  bs = BucketSyncService.new(from_creds, to_creds)
41
- #bs.debug = true
39
+ bs.debug = true
40
+
41
+ puts "beginning clone of S3 bucket, this can go on for tens of minutes..."
42
42
  bs.perform
43
43
  end
44
44
 
45
+ def get_fancy_string_of_staging_db_uri
46
+ setup_aws_credentials_and_configs
47
+
48
+ l = 66
49
+ msg = ""
50
+ msg += "*" * l + "\n"
51
+ msg += "* "
52
+ msg += get_fresh_db_instance_state(@db_instance_id_staging).endpoint.address
53
+ msg += " *\n"
54
+ msg += "*" * l
55
+ msg
56
+ end
45
57
 
46
58
  private
47
59
 
48
- def setup_aws_credentials
60
+ def setup_aws_credentials_and_configs
49
61
  aws_region = @config["aws_region"]
50
62
  @access_key_id = @config["aws_access_key_id"]
51
63
  @secret_access_key = @config["aws_secret_access_key"]
@@ -60,6 +72,8 @@ module AwsOneClickStaging
60
72
 
61
73
  Aws.config.update({ region: aws_region,
62
74
  credentials: Aws::Credentials.new(@access_key_id, @secret_access_key) })
75
+
76
+ @c = Aws::RDS::Client.new
63
77
  end
64
78
 
65
79
  def delete_snapshot_for_staging!
@@ -73,7 +87,7 @@ module AwsOneClickStaging
73
87
  end
74
88
 
75
89
  def create_new_snapshot_for_staging!
76
- puts "creating new snapshot... this takes like 70 seconds..."
90
+ puts "creating new snapshot... this takes like 170 seconds..."
77
91
  response = @c.create_db_snapshot({db_instance_identifier: @db_instance_id_production,
78
92
  db_snapshot_identifier: @db_snapshot_id })
79
93
 
@@ -85,6 +99,7 @@ module AwsOneClickStaging
85
99
 
86
100
 
87
101
  def delete_staging_db_instance!
102
+ puts "Deleting old staging instance... This one's a doozy =/"
88
103
  response = @c.delete_db_instance(db_instance_identifier: @db_instance_id_staging,
89
104
  skip_final_snapshot: true)
90
105
 
@@ -94,6 +109,7 @@ module AwsOneClickStaging
94
109
  end
95
110
 
96
111
  def spawn_new_staging_db_instance!
112
+ puts "Spawning a new fully clony RDS db instance for staging purposes"
97
113
  response = @c.create_db_instance(db_instance_identifier: @db_instance_id_staging,
98
114
  db_instance_class: "db.t1.micro",
99
115
  engine: "postgres",
@@ -121,16 +137,7 @@ module AwsOneClickStaging
121
137
  true
122
138
  end
123
139
 
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
133
- end
140
+
134
141
 
135
142
 
136
143
  def read_config_file
@@ -1,3 +1,3 @@
1
1
  module AwsOneClickStaging
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
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.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheNotary