shards 0.1.0 → 1.0.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: ca225377c101802de92a670d8d81e2d5b6d0de4a
4
- data.tar.gz: 642c766b71407c5ba5e45d55dd0a7a0748340e00
3
+ metadata.gz: 523c7e9cab3fd380bcea554992a5c19251c84479
4
+ data.tar.gz: 9e928d55218cde3343ce950d6d6f2cc256cca8de
5
5
  SHA512:
6
- metadata.gz: 0faf4808695321e851bff64b5cc7ba6a0d1bec68efa9981bfec4d96f73ddcb457f8e2099ab140c95dfb0971f751f1b320c4fac433dda668cb1616f247df4df43
7
- data.tar.gz: 3c4fec087aeb2572ea5a70c265d711c34c5311682f091da4b9976ab18361ea32d064ee58170716fad4f451d8a35264e745703d2b9e15b82ff66ffedd3b5b3e01
6
+ metadata.gz: f38a73a336d92cd2a610a8a0f633cf06c03b95b5ad5484a37f86b89e0481ed3fb1ede5defda6db43d4cd80705506e3649c54b8f4a0a0b0e60073bdca2dbf6d76
7
+ data.tar.gz: afc4fb3664b00b44326f1eb64dde9a14579f57e815b2fff2633912c4153fd09bbc34b040b33d8f0758b5a7ec7c88f5705aa3ec2d4d7470170bdbce42a28598ff
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .rspec_status
12
12
  .byebug*
13
13
  *.swp
14
+ settings.env
15
+ /spec/support/write_yaml/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.3
data/Gemfile.lock ADDED
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shards (1.0.2)
5
+ aws-sdk-route53 (~> 1.9)
6
+ dotenv (~> 2.4)
7
+ git (~> 1.4)
8
+ net-scp (~> 1.2)
9
+ net-ssh (~> 5.0)
10
+ terminal-table (~> 1.8)
11
+ thor (~> 0.20)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ aruba (0.14.6)
17
+ childprocess (>= 0.6.3, < 0.10.0)
18
+ contracts (~> 0.9)
19
+ cucumber (>= 1.3.19)
20
+ ffi (~> 1.9.10)
21
+ rspec-expectations (>= 2.99)
22
+ thor (~> 0.19)
23
+ aws-eventstream (1.0.1)
24
+ aws-partitions (1.96.0)
25
+ aws-sdk-core (3.22.1)
26
+ aws-eventstream (~> 1.0)
27
+ aws-partitions (~> 1.0)
28
+ aws-sigv4 (~> 1.0)
29
+ jmespath (~> 1.0)
30
+ aws-sdk-route53 (1.10.1)
31
+ aws-sdk-core (~> 3)
32
+ aws-sigv4 (~> 1.0)
33
+ aws-sigv4 (1.0.3)
34
+ backports (3.11.3)
35
+ builder (3.2.3)
36
+ byebug (10.0.2)
37
+ childprocess (0.9.0)
38
+ ffi (~> 1.0, >= 1.0.11)
39
+ contracts (0.16.0)
40
+ cucumber (3.1.2)
41
+ builder (>= 2.1.2)
42
+ cucumber-core (~> 3.2.0)
43
+ cucumber-expressions (~> 6.0.1)
44
+ cucumber-wire (~> 0.0.1)
45
+ diff-lcs (~> 1.3)
46
+ gherkin (~> 5.1.0)
47
+ multi_json (>= 1.7.5, < 2.0)
48
+ multi_test (>= 0.1.2)
49
+ cucumber-core (3.2.0)
50
+ backports (>= 3.8.0)
51
+ cucumber-tag_expressions (~> 1.1.0)
52
+ gherkin (>= 5.0.0)
53
+ cucumber-expressions (6.0.1)
54
+ cucumber-tag_expressions (1.1.1)
55
+ cucumber-wire (0.0.1)
56
+ diff-lcs (1.3)
57
+ dotenv (2.5.0)
58
+ ffi (1.9.25)
59
+ gherkin (5.1.0)
60
+ git (1.4.0)
61
+ jmespath (1.4.0)
62
+ multi_json (1.13.1)
63
+ multi_test (0.1.2)
64
+ net-scp (1.2.1)
65
+ net-ssh (>= 2.6.5)
66
+ net-ssh (5.0.2)
67
+ rake (10.4.2)
68
+ rspec (3.6.0)
69
+ rspec-core (~> 3.6.0)
70
+ rspec-expectations (~> 3.6.0)
71
+ rspec-mocks (~> 3.6.0)
72
+ rspec-core (3.6.0)
73
+ rspec-support (~> 3.6.0)
74
+ rspec-expectations (3.6.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.6.0)
77
+ rspec-mocks (3.6.0)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.6.0)
80
+ rspec-support (3.6.0)
81
+ terminal-table (1.8.0)
82
+ unicode-display_width (~> 1.1, >= 1.1.1)
83
+ thor (0.20.0)
84
+ unicode-display_width (1.4.0)
85
+
86
+ PLATFORMS
87
+ ruby
88
+
89
+ DEPENDENCIES
90
+ aruba (~> 0.14)
91
+ bundler (~> 1.16)
92
+ byebug (~> 10.0)
93
+ rake (~> 10.0)
94
+ rspec (~> 3.0)
95
+ shards!
96
+
97
+ BUNDLED WITH
98
+ 1.16.2
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shards`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This gem is to manage the shards and sites working with octopus in rails and sycronize between Puppet repository reading shards and sites. Then it has some AWS libraries to update route53 DNS system and create databases in RDS servers.
6
+
7
+ Basically the gem has mothods to format by default some fields to save code lines in settings, and automation. The target is have a library and a terminal client application to create and delete shards and sites, and create and delete all resources associated with them.
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,7 +24,36 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ Add a settings.env file in your root application directory with the variables:
28
+
29
+ ```bash
30
+
31
+ ENGINEERING_ROOT_PATH=/your/root/path/to/engineering/repo/project
32
+ CONFIG_FILE=relative/path/to/config.yml
33
+ PROXY_SUBDOMAIN=proxy.example.com
34
+ DOMAIN=example.com
35
+ CONFIG_FILES_ROOT_PATH=puppet/environments/common/bbug_config/files
36
+ SHARDS_FILE_NAME=shards.yml
37
+ SITES_FILE_NAME=sites.yml
38
+ SHARD_LIST_KEY_ROOT_PATH=octopus production migration_group_shards
39
+ CONFIG_DIR_SUFFIX=config_dir_suffix
40
+ DNS_ZONE_CODE=DNS Zone Code
41
+ DB_USER=db_user_name
42
+ DB_PASSWORD=HerePasswordDB
43
+ PROXY_USER=proxy_username
44
+
45
+ # optional:
46
+ TEST=true #only for test.env delete this var in settings.env
47
+ CONFIG_REPLACE={ 'prod' => 'web' }
48
+ LIVE_BRANCH=shards_test # set this var to use in test.env or to change the default value 'v5'
49
+ WORKFLOW_YAML_FILE=path/to/your/workflow.yaml # write the path to your workflow yaml. You have to implement the existing methods.
50
+ # You could overwrite methods using this metaprograming way ading your on your_file.yaml
51
+ # Then add this var:
52
+ # FORMAT_METHODS_FILE=your/path/to/your_file.yaml
53
+ # Finally to overwrite the default behavior write your code in your_file.yaml. The yaml will be merged so you need define just the methods thay you need overwrite.
54
+ # The default definitions are in spec/support/format_methods.yaml
55
+
56
+ ```
26
57
 
27
58
  ## Development
28
59
 
@@ -40,4 +71,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
71
 
41
72
  ## Code of Conduct
42
73
 
43
- Everyone interacting in the Shards project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/shards/blob/master/CODE_OF_CONDUCT.md).
74
+ Everyone interacting in the Shards project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/BookingBug/shards/blob/master/CODE_OF_CONDUCT.md).
data/exe/shards ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "shards"
4
+
5
+ Shards::Client.start ARGV
@@ -0,0 +1,151 @@
1
+ ---
2
+ Shards::Dns:
3
+ name: (domain + stage.get('domain_suffix')).gsub('_','-')
4
+ zone: ENV['DNS_ZONE_CODE']
5
+ target: stage.route53
6
+ r53upsert: >
7
+ {
8
+ change_batch: {
9
+ changes: [
10
+ {
11
+ action: "UPSERT",
12
+ resource_record_set: {
13
+ name: host,
14
+ resource_records: [
15
+ {
16
+ value: target
17
+ },
18
+ ],
19
+ ttl: 300,
20
+ type: "CNAME",
21
+ },
22
+ },
23
+ ],
24
+ comment: "Adding #{name} to #{ENV['DOMAIN']}"
25
+ },
26
+ hosted_zone_id: "#{zone}"
27
+ }
28
+
29
+ host: name + '.' + ENV['DOMAIN']
30
+ dryrun_message: |
31
+ add "##### DNS Dryrun #####"
32
+ add "CNAME: #{host}"
33
+ add "Target: #{target}"
34
+ add "ZoneID: #{zone}"
35
+ add " "
36
+ creating_route53_message: |
37
+ add "##### Setting Up DNS"
38
+ add "Creating Route53 entry for #{host} as a CNAME to #{target}"
39
+ add " "
40
+ aws_route53_record_message: |
41
+ add "Route53 Response"
42
+ add aws_route53_resp.to_h
43
+
44
+ Shards::Db:
45
+ name: |
46
+ [stage.downcase_location, dns.domain, stage.name ].join('_').gsub('-','_')
47
+ server: stage.get 'db_server'
48
+ net: stage.get 'blank_db'
49
+ net_server: stage.get 'blank_db_server'
50
+ user: ENV['DB_USER']
51
+ password: ENV['DB_PASSWORD']
52
+ proxy: stage.get 'proxy'
53
+ proxy_user: ENV['PROXY_USER']
54
+ file: |
55
+ '/tmp/createdb' + dns.name + '.sh'
56
+ init_script: add "#!/bin/bash"
57
+ creating_database: |
58
+ add "echo \"# Creating database #{name}\""
59
+ add "#{conn} -e \"CREATE DATABASE #{name}\""
60
+ dumping_database: |
61
+ add "echo \"# Dumping database #{net}\""
62
+ add "#{dump} #{net} > #{sql_dump_file}"
63
+ inserting_data: |
64
+ add "echo \"# Inserting data from #{net} into #{name}\""
65
+ add "#{conn} #{name} < #{sql_dump_file}"
66
+ conn: |
67
+ "mysql #{conn_usr_pass} -h#{server}"
68
+ dump: |
69
+ "mysqldump #{conn_usr_pass} -h#{net_server}"
70
+ conn_usr_pass: '"-u#{user} -p#{password}"'
71
+ setting_up_database_message: |
72
+ add ""
73
+ add "##### Setting Up Database"
74
+ add "Generating DB creation script"
75
+ dryrun_message: |
76
+ add ""
77
+ add "##### Database Dryrun #####"
78
+ add "Source: #{net}"
79
+ add "Target: #{name}"
80
+ sql_dump_file: |
81
+ "/tmp/#{net}.sql.dump"
82
+ chmod_file_command: |
83
+ "chmod +x #{file}"
84
+ chmod_file_message: |
85
+ "Modifying Permissions."
86
+ db_creation_command: file
87
+ db_creation_message: |
88
+ "Running the DB Creation Script"
89
+ adapter: |
90
+ "mysql2"
91
+ reconnect: |
92
+ "true"
93
+ connection: |
94
+ { 'host' => server , 'adapter' => adapter, 'reconnect' => reconnect , 'username' => user , 'password' => password , 'database' => name }
95
+ show_command: |
96
+ conn + ' -N -B -e "show databases"'
97
+
98
+
99
+ Shards::Site:
100
+ file: file_path ENV['SITES_FILE_NAME']
101
+ name: |
102
+ client + ' - ' + stage.name.capitalize
103
+ desc: name
104
+ data: |
105
+ {
106
+ 'name' => name,
107
+ 'description' => desc,
108
+ 'subdomain' => stage.shard.dns.name,
109
+ 'domain' => domain,
110
+ 'shard' => stage.shard.name
111
+ }
112
+ domain: |
113
+ stage.shard.dns.host
114
+ add_site_message: |
115
+ add ""
116
+ add "##### Sites Dryrun #####"
117
+ data.to_s.split(separator).each { |x| add x }
118
+ separator: "', '"
119
+ add_data: |
120
+ yaml << data
121
+ yaml.sort_by! { |x| x["name"] }
122
+
123
+
124
+ Shards::Shard:
125
+ file: file_path ENV['SHARDS_FILE_NAME']
126
+ list: eval "yaml#{shard_list_key.to_s}"
127
+ base: |
128
+ { basename => basedata }
129
+ basename: list.keys.first
130
+ basedata: list[basename]
131
+ name: |
132
+ [stage.downcase_location , domain , stage.name].join('_')
133
+
134
+ Shards::Stage:
135
+ route53: name + '01.' + downcase_location + '.' + ENV['DOMAIN']
136
+ config_dir: |
137
+ [downcase_location, downcase_location + '_' + config_name, ENV['CONFIG_DIR_SUFFIX'] ].join('/')
138
+ blank_db: |
139
+ [downcase_location, 'net', name].join('_')
140
+ blank_db_server: get 'db_server'
141
+ proxy: downcase_location + '.' + ENV['PROXY_SUBDOMAIN']
142
+ domain_suffix: |
143
+ '-' + name
144
+ downcase_location: location_name.downcase
145
+ add_domain_message: |
146
+ add " "
147
+ add "#### Shards DryRun ####"
148
+ add "Shard: #{shard.name}"
149
+ add "DB: #{shard.db.name}"
150
+
151
+
@@ -0,0 +1,171 @@
1
+ ---
2
+ terminal:
3
+
4
+ ask_client:
5
+ question: Type the client name, please.
6
+ wrong_message: The client name %s.
7
+ correct: ask_location
8
+ wrong: ask_for_repeat
9
+ min_size: 2
10
+
11
+ ask_location:
12
+ question: Type the location mumber, please.
13
+ wrong_message: The location %s is not in the list.
14
+ correct: ask_stage
15
+ wrong: ask_for_repeat
16
+
17
+ ask_stage:
18
+ question: Type stage number, please.
19
+ wrong_message: The stage %s is not in the list.
20
+ correct: ask_domain
21
+ wrong: ask_for_repeat
22
+
23
+ ask_domain:
24
+ question: Type the domain name, please.
25
+ wrong_message: The domain name %s.
26
+ correct: check_shard_presence_in_shards
27
+ wrong: ask_for_repeat
28
+ min_size: 3
29
+ regex: ^[a-zA-Z0-9_]*$
30
+
31
+ check_shard_presence_in_shards:
32
+ wrong_message: The shard %s exists in shards.
33
+ correct: check_database_presence_in_server
34
+ wrong: finish
35
+
36
+ check_database_presence_in_server:
37
+ wrong_message: The database %s exists in server %s.
38
+ correct: check_domain_dns_presence
39
+ wrong: finish
40
+
41
+ check_domain_dns_presence:
42
+ wrong_message: There is already a record for the host %s.
43
+ correct: check_domain_presence_in_sites
44
+ wrong: finish
45
+
46
+ check_domain_presence_in_sites:
47
+ wrong_message: The domain %s is already present in sites.
48
+ correct: write_yaml_files
49
+ wrong: finish
50
+
51
+ write_yaml_files:
52
+ question: Type Y to confirm the changes
53
+ wrong_message: Undo changes
54
+ correct: create_database
55
+ wrong: clean_repo_and_exit
56
+
57
+ create_database:
58
+ message: The database %s has been successfully created in %s.
59
+ wrong_message: Error. Couldn't create the database %s in %s.
60
+ correct: commit_changes
61
+ wrong: clean_repo_and_exit
62
+
63
+ commit_changes:
64
+ message: The changes has been committed and pushed to the remote repository.
65
+ wrong_message: We had an issue to commit and push the changes.
66
+ correct: dns_upsert
67
+ wrong: finish
68
+
69
+ dns_upsert:
70
+ message: The dns record with the host %s has been succesfully created.
71
+ wrong_message: Error. Could not register the host %s as a dns record.
72
+ correct: ask_for_exit_or_restart
73
+ wrong: finish
74
+
75
+ ask_for_exit_and_restart:
76
+ question: Type 'r' to restart the process, another key to finish.
77
+ wrong_message: Process Interrupted.
78
+ correct: ask_location
79
+ wrong: finish
80
+
81
+ ask_for_repeat:
82
+ question: Wrong answer, type 'r' to repeat the step, another key to finish.
83
+ correct: repeat_previous_method
84
+ wrong_message: Process Interrupted. Cleanning the repo and exit.
85
+ wrong: finish
86
+
87
+ clean_repo_and_exit:
88
+ correct: finish
89
+
90
+ finish:
91
+ correct: finish
92
+
93
+ repeat_previous_method:
94
+ correct: repeat_previous_method
95
+ wrong: finish
96
+
97
+
98
+ fastterminal:
99
+
100
+ create:
101
+ correct: check_shard_presence_in_shards
102
+ wrong: clean_repo_and_exit
103
+ client_min_size: 2
104
+ domain_min_size: 3
105
+ domain_regex: ^[a-zA-Z0-9_]*$
106
+
107
+ check_shard_presence_in_shards:
108
+ wrong_message: The shard %s exists in shards.
109
+ correct: check_database_presence_in_server
110
+ wrong: finish
111
+
112
+ check_database_presence_in_server:
113
+ wrong_message: The database %s exists in server %s.
114
+ correct: check_domain_dns_presence
115
+ wrong: finish
116
+
117
+ check_domain_dns_presence:
118
+ wrong_message: There is already a record for the host %s.
119
+ correct: check_domain_presence_in_sites
120
+ wrong: finish
121
+
122
+ check_domain_presence_in_sites:
123
+ wrong_message: The domain %s is already present in sites.
124
+ correct: write_yaml_files
125
+ wrong: finish
126
+
127
+ write_yaml_files:
128
+ question: Type Y to confirm the changes
129
+ wrong_message: Undo changes
130
+ correct: create_database
131
+ wrong: clean_repo_and_exit
132
+
133
+ create_database:
134
+ message: The database %s has been successfully created in %s.
135
+ wrong_message: Error. Couldn't create the database %s in %s.
136
+ correct: commit_changes
137
+ wrong: clean_repo_and_exit
138
+
139
+ commit_changes:
140
+ message: The changes has been committed and pushed to the remote repository.
141
+ wrong_message: We had an issue to commit and push the changes.
142
+ correct: dns_upsert
143
+ wrong: finish
144
+
145
+ dns_upsert:
146
+ message: The dns record with the host %s has been succesfully created.
147
+ wrong_message: Error. Could not register the host %s as a dns record.
148
+ correct: ask_for_exit_or_restart
149
+ wrong: finish
150
+
151
+ ask_for_exit_and_restart:
152
+ question: Type 'r' to restart the process, another key to finish.
153
+ wrong_message: Process Interrupted.
154
+ correct: ask_location
155
+ wrong: finish
156
+
157
+ ask_for_repeat:
158
+ question: Wrong answer, type 'r' to repeat the step, another key to finish.
159
+ correct: repeat_previous_method
160
+ wrong_message: Process Interrupted. Cleanning the repo and exit.
161
+ wrong: finish
162
+
163
+ clean_repo_and_exit:
164
+ correct: finish
165
+
166
+ finish:
167
+ correct: finish
168
+
169
+ repeat_previous_method:
170
+ correct: repeat_previous_method
171
+ wrong: finish