sct 1.1.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cluster/lib/cluster/runner.rb +1 -1
- data/henk/lib/henk/commands_generator.rb +40 -2
- data/henk/lib/henk/runner.rb +126 -4
- data/sct/lib/sct/commands/dev.rb +23 -13
- data/sct/lib/sct/commands/shell.rb +2 -4
- data/sct/lib/sct/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ca92e3c8b95fa282f479795b17cd3b0c349afee8f07c50ee53626396e1473fd
|
4
|
+
data.tar.gz: 61313bc641c95704bf4c4591914f3a9a8b33b29b4962ec5c22f4cfc6a84d990b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6453c0b80246ab00dbcb6ea69c36801259f3666867c0a78ec4bb56827647740a245d1df47d3e4e207a068c969689264cd0668373e036a3420e3c603b45ec3db
|
7
|
+
data.tar.gz: ce6bced4dce7f734ef8b724c1400974ee1a8a51136b0ca6d3e506108ee62ce571dd3375289caef18f8474ebd5b7ed974b4869d118b9f8e13778633ae0ca92ae6
|
@@ -40,7 +40,7 @@ module Henk
|
|
40
40
|
Henk::Runner.new.encrypt_config_data options.domain
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
command :copy do |c|
|
45
45
|
c.syntax = 'sct henk copy'
|
46
46
|
c.description = 'Copy a client from another environment to your local environment'
|
@@ -81,7 +81,7 @@ module Henk
|
|
81
81
|
Henk::Runner.new.synchronize_employees options.target_domain
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
command :remove do |c|
|
86
86
|
c.syntax = 'sct henk remove'
|
87
87
|
c.description = 'Remove a client from your local environment.'
|
@@ -105,6 +105,44 @@ module Henk
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
+
command :"list-dumps" do |c|
|
109
|
+
c.syntax = 'sct henk list-dumps'
|
110
|
+
c.description = 'List the customer dumps currently available for import.'
|
111
|
+
|
112
|
+
c.action do |args, options|
|
113
|
+
Henk::Runner.new.list_dumps args, options
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
command :"import" do |c|
|
118
|
+
c.syntax = 'sct henk import <URL>'
|
119
|
+
c.description = 'Import a customer dump from GCP.'
|
120
|
+
|
121
|
+
c.action do |args, options|
|
122
|
+
case args.length
|
123
|
+
when 0
|
124
|
+
puts "Loading available customer dumps...".blue
|
125
|
+
|
126
|
+
available_dumps = `sct henk list-dumps`.lines chomp: true
|
127
|
+
|
128
|
+
dump_url = choose do |menu|
|
129
|
+
menu.prompt = "Please choose a dump to import:"
|
130
|
+
|
131
|
+
for dump in available_dumps
|
132
|
+
menu.choice dump
|
133
|
+
end
|
134
|
+
end
|
135
|
+
when 1
|
136
|
+
dump_url = args.first
|
137
|
+
else
|
138
|
+
UI.error "Expected 0 or 1 arguments, received #{args.length}: #{args}"
|
139
|
+
exit 1
|
140
|
+
end
|
141
|
+
|
142
|
+
Henk::Runner.new.import args, options, dump_url
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
108
146
|
run!
|
109
147
|
end
|
110
148
|
|
data/henk/lib/henk/runner.rb
CHANGED
@@ -3,7 +3,7 @@ require 'pp'
|
|
3
3
|
module Henk
|
4
4
|
class Runner
|
5
5
|
attr_accessor :options_mapping
|
6
|
-
|
6
|
+
|
7
7
|
def initialize
|
8
8
|
@options_mapping = {
|
9
9
|
"organization_name" => {
|
@@ -56,8 +56,8 @@ module Henk
|
|
56
56
|
|
57
57
|
connected_to_network = `docker network inspect spend-cloud | jq '.[0] | .Containers | map(select((.Name | test("^#{required_containers.join('|^')}")))) | length'`
|
58
58
|
|
59
|
-
if connected_to_network.to_s.strip! != "
|
60
|
-
puts "Error: ".red + "Not all required services are running or connected to the cluster (#{connected_to_network}/
|
59
|
+
if connected_to_network.to_s.strip! != "5"
|
60
|
+
puts "Error: ".red + "Not all required services are running or connected to the cluster (#{connected_to_network}/5)"
|
61
61
|
exit(1)
|
62
62
|
end
|
63
63
|
|
@@ -88,7 +88,7 @@ module Henk
|
|
88
88
|
def encrypt_config_data domain
|
89
89
|
puts "Manually encrypting config data for #{domain}".green
|
90
90
|
php_command = "php /var/www/scripts/encryptConfigData.php -c='#{domain}' --execute"
|
91
|
-
command = 'docker exec -it proactive-config bash -c "#{php_command}"'
|
91
|
+
command = 'docker exec -it proactive-config-php bash -c "#{php_command}"'
|
92
92
|
self.run command
|
93
93
|
end
|
94
94
|
|
@@ -171,5 +171,127 @@ module Henk
|
|
171
171
|
options_str += parsed_options.join(' ')
|
172
172
|
return options_str
|
173
173
|
end
|
174
|
+
|
175
|
+
def list_dumps args, options
|
176
|
+
run "gsutil ls gs://henk-db-dumps/"
|
177
|
+
end
|
178
|
+
|
179
|
+
def import args, options, dump_url
|
180
|
+
puts "Going to import #{dump_url}".blue
|
181
|
+
|
182
|
+
dir = Dir.mktmpdir
|
183
|
+
|
184
|
+
begin
|
185
|
+
zip = download_and_unzip dump_url, dir
|
186
|
+
|
187
|
+
customer = zip.slice 0, zip.rindex("_")
|
188
|
+
|
189
|
+
customer_database = customer.gsub "-", "_"
|
190
|
+
|
191
|
+
remove_customer customer
|
192
|
+
|
193
|
+
copy_db_encryption_key customer, dir
|
194
|
+
|
195
|
+
run_sql_files dir
|
196
|
+
|
197
|
+
add_customer_account customer, customer_database
|
198
|
+
|
199
|
+
update_and_encrypt_customer_config customer, customer_database
|
200
|
+
|
201
|
+
puts "Finished importing #{customer}".green
|
202
|
+
ensure
|
203
|
+
run "rm -r #{dir}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def download_and_unzip dump_url, dir
|
208
|
+
run "gsutil cp #{dump_url} #{dir}"
|
209
|
+
|
210
|
+
zip_path = Dir["#{dir}/*.zip"].first
|
211
|
+
|
212
|
+
run "unzip #{zip_path} -d #{dir}"
|
213
|
+
|
214
|
+
zip = File.basename zip_path
|
215
|
+
end
|
216
|
+
|
217
|
+
def remove_customer customer
|
218
|
+
local_customers = `sct henk list-clients`.lines chomp: true
|
219
|
+
|
220
|
+
if local_customers.include? customer
|
221
|
+
puts "Customer already exists. Removing customer before importing...".yellow
|
222
|
+
|
223
|
+
run "sct henk remove --domain #{customer}"
|
224
|
+
|
225
|
+
puts "Removed existing customer".green
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def copy_db_encryption_key customer, dir
|
230
|
+
run "docker exec proactive-config-php mkdir /data/#{customer}"
|
231
|
+
run "docker cp #{dir}/db_encryption.key proactive-config-php:/data/#{customer}/"
|
232
|
+
|
233
|
+
puts "Copied db_encryption.key to proactive-config-php:/data/#{customer}/".green
|
234
|
+
end
|
235
|
+
|
236
|
+
def run_sql_files dir
|
237
|
+
sql_paths = Dir["#{dir}/*.sql"]
|
238
|
+
|
239
|
+
sql_paths.each_with_index do |path, index|
|
240
|
+
file = File.basename path
|
241
|
+
database = File.basename path, ".*"
|
242
|
+
|
243
|
+
puts "Running #{file} (#{index + 1}/#{sql_paths.length})".blue
|
244
|
+
|
245
|
+
run_query "CREATE DATABASE IF NOT EXISTS `#{database}`"
|
246
|
+
|
247
|
+
run_query "source /sql/#{file}", database: database, volume: "#{dir}:/sql"
|
248
|
+
end
|
249
|
+
|
250
|
+
puts "Finished running SQL files".green
|
251
|
+
end
|
252
|
+
|
253
|
+
def add_customer_account customer, customer_database
|
254
|
+
account_data = "\n[#{customer}]\ndatabase = #{customer_database}\ndomain = NULL\nrewrite = #{customer}\nimport_planning = 1\njobs = 1\nscan_upload = 0\nfiatteren_mailbox = 1\ncontracten_mailbox = 1"
|
255
|
+
|
256
|
+
run "docker exec proactive-config-php sh -c 'echo \"#{account_data}\" >> /data/proactive_accounts.ini'"
|
257
|
+
|
258
|
+
puts "Added account to proactive_accounts.ini".green
|
259
|
+
end
|
260
|
+
|
261
|
+
def update_and_encrypt_customer_config customer, customer_database
|
262
|
+
dsn = "mysql:host=mysql-service;user=root;dbname=#{customer_database};config=proactive-php;config-path=cfg/db;"
|
263
|
+
|
264
|
+
website_application = "https://#{customer}.dev.spend.cloud"
|
265
|
+
|
266
|
+
email_administrator = "noreply@dev.spend.cloud"
|
267
|
+
|
268
|
+
debug_email_address = "noreply@dev.spend.cloud"
|
269
|
+
|
270
|
+
query = "UPDATE `00_settings` SET `045` = \"#{dsn}\", `029` = \"#{website_application}\", `002` = \"#{email_administrator}\", `031` = \"#{debug_email_address}\" WHERE `043` = \"#{customer}\""
|
271
|
+
|
272
|
+
run_query query, database: "spend-cloud-config"
|
273
|
+
|
274
|
+
puts "Updated config values".green
|
275
|
+
|
276
|
+
run "docker exec proactive-config-php php /var/www/scripts/encryptConfigData.php -c='#{customer}' --execute"
|
277
|
+
|
278
|
+
puts "Encrypted config values".green
|
279
|
+
end
|
280
|
+
|
281
|
+
def run_query query, database: nil, volume: nil
|
282
|
+
command = "docker run --rm --network container:mysql-service"
|
283
|
+
|
284
|
+
if volume
|
285
|
+
command = "#{command} -v #{volume}"
|
286
|
+
end
|
287
|
+
|
288
|
+
command = "#{command} arey/mysql-client -h mysql-service"
|
289
|
+
|
290
|
+
if database
|
291
|
+
command = "#{command} -D #{database}"
|
292
|
+
end
|
293
|
+
|
294
|
+
run "#{command} -e '#{query}'"
|
295
|
+
end
|
174
296
|
end
|
175
297
|
end
|
data/sct/lib/sct/commands/dev.rb
CHANGED
@@ -29,15 +29,6 @@ module Sct
|
|
29
29
|
def execute args, options
|
30
30
|
services = manifest["services"].to_a
|
31
31
|
|
32
|
-
if services.length != 1
|
33
|
-
error "Currently sct only supports a single service declaration in '#{@@file}'. Contact the infra guild if you consider this a limitation."
|
34
|
-
end
|
35
|
-
|
36
|
-
service, service_spec = services.first
|
37
|
-
|
38
|
-
container = service_spec["container_name"]
|
39
|
-
command = service_spec["command"] || ""
|
40
|
-
|
41
32
|
if Sct::Helper.is_windows?
|
42
33
|
host_machine_IP = (options.wsl_debugger ? `hostname -I | awk '{print $1}'` : `powershell.exe -c '(Test-Connection -ComputerName $env:computername -count 1).ipv4address.IPAddressToString' | dos2unix`).chomp
|
43
34
|
elsif Sct::Helper.is_mac_os?
|
@@ -55,7 +46,7 @@ module Sct
|
|
55
46
|
}
|
56
47
|
|
57
48
|
if options.pull
|
58
|
-
return unless dc_dev "pull"
|
49
|
+
return unless dc_dev "pull", env
|
59
50
|
end
|
60
51
|
|
61
52
|
if options.build
|
@@ -66,11 +57,30 @@ module Sct
|
|
66
57
|
system "docker image prune -f"
|
67
58
|
end
|
68
59
|
|
69
|
-
|
60
|
+
for service, service_spec in services
|
61
|
+
return unless dc "rm --stop --force #{service}"
|
62
|
+
end
|
63
|
+
|
64
|
+
if services.length == 1
|
65
|
+
service, service_spec = services.first
|
70
66
|
|
71
|
-
|
67
|
+
container = service_spec["container_name"]
|
68
|
+
command = service_spec["command"] || ""
|
72
69
|
|
73
|
-
|
70
|
+
dc_dev "run --rm --service-ports --name #{container} #{service} #{command}", env
|
71
|
+
else
|
72
|
+
begin
|
73
|
+
dc_dev "up --remove-orphans --force-recreate --always-recreate-deps", env
|
74
|
+
rescue Interrupt
|
75
|
+
# user pressed Ctrl+C, do nothing
|
76
|
+
end
|
77
|
+
|
78
|
+
dc_dev "down --remove-orphans", env
|
79
|
+
end
|
80
|
+
|
81
|
+
for service, service_spec in services
|
82
|
+
dc "up --detach #{service}"
|
83
|
+
end
|
74
84
|
end
|
75
85
|
|
76
86
|
end
|
@@ -21,10 +21,6 @@ module Sct
|
|
21
21
|
|
22
22
|
services = manifest["services"].to_a
|
23
23
|
|
24
|
-
if services.length != 1
|
25
|
-
error "Currently sct only supports a single service declaration in '#{file}'. Contact the infra guild if you consider this a limitation."
|
26
|
-
end
|
27
|
-
|
28
24
|
service, service_spec = services.first
|
29
25
|
|
30
26
|
container = service_spec["container_name"]
|
@@ -43,6 +39,8 @@ module Sct
|
|
43
39
|
|
44
40
|
user = options.root ? "root:root" : "$(id -u):$(id -g)"
|
45
41
|
|
42
|
+
puts "Attaching to shell in container #{container.bold}".green
|
43
|
+
|
46
44
|
system "docker exec -it --user #{user} #{container} #{command}"
|
47
45
|
end
|
48
46
|
|
data/sct/lib/sct/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reshad Farid
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored
|