blackstack-deployer 1.2.3 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/blackstack-deployer.rb +60 -30
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2197d07351cc7992754e1a97848f862cece1e90384b539a93d89fb765a200a7
|
4
|
+
data.tar.gz: 849d35bb7fa51c2071a9567fe2a9ab01fd75d7c50d239da9446f09c81a2db3e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67164cd4df13e59d5e3258700d7ebe2451b1b787e315968d7ea5647866138d90ac5acaee8ed2c4f660fcf179af5c6aeacfdb6aafa71ca1c9a1d14c8f0e71a63
|
7
|
+
data.tar.gz: 8893cf809bf4d011ac52e2cb161fe38cfbc700bcf418d6ca630d38696b8508f6ddb01e0749d8b2eaba0767b089d83830278b692167108541ee3da17fbd37cab2
|
data/lib/blackstack-deployer.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
require 'blackstack-nodes'
|
1
|
+
#require 'blackstack-nodes'
|
2
|
+
require'blackstack-nodes'
|
3
|
+
|
2
4
|
require 'sequel'
|
3
5
|
|
4
6
|
module BlackStack
|
@@ -8,6 +10,11 @@ module BlackStack
|
|
8
10
|
@@nodes = []
|
9
11
|
@@routines = []
|
10
12
|
|
13
|
+
# set the logger
|
14
|
+
def self.set_logger(i_logger)
|
15
|
+
@@logger = i_logger
|
16
|
+
end
|
17
|
+
|
11
18
|
# get the logger assigned to the module
|
12
19
|
def self.logger
|
13
20
|
@@logger
|
@@ -66,6 +73,10 @@ module BlackStack
|
|
66
73
|
h[:deployment_routine] = self.deployment_routine
|
67
74
|
h
|
68
75
|
end # def to_hash
|
76
|
+
|
77
|
+
def deploy()
|
78
|
+
BlackStack::Deployer::run_routine(self.name, self.deployment_routine);
|
79
|
+
end
|
69
80
|
end # module NodeModule
|
70
81
|
|
71
82
|
# define attributes and methods of a deployer routine
|
@@ -134,8 +145,8 @@ module BlackStack
|
|
134
145
|
h = c.run(node)
|
135
146
|
ret << h
|
136
147
|
|
137
|
-
BlackStack::Deployer.logger.logs "Result: "
|
138
|
-
BlackStack::Deployer.logger.logf h.to_s
|
148
|
+
#BlackStack::Deployer.logger.logs "Result: "
|
149
|
+
#BlackStack::Deployer.logger.logf h.to_s
|
139
150
|
|
140
151
|
if h[:errors].size == 0
|
141
152
|
BlackStack::Deployer.logger.done
|
@@ -291,24 +302,16 @@ module BlackStack
|
|
291
302
|
end
|
292
303
|
end
|
293
304
|
|
294
|
-
|
295
|
-
if self.sudo
|
296
|
-
# escale the single quotes in the code variable
|
297
|
-
code.gsub!(/'/, "\\\\'")
|
298
|
-
|
299
|
-
if node.ssh_private_key_file.nil?
|
300
|
-
code = "echo '#{node.ssh_password.to_s.gsub("'", "\\\\'")}' | sudo -S su root -c '#{code.to_s}'"
|
301
|
-
else
|
302
|
-
code = "sudo -S su root -c '#{code.to_s}'"
|
303
|
-
end
|
304
|
-
else
|
305
|
-
code = code.to_s
|
306
|
-
end
|
305
|
+
#puts
|
307
306
|
#puts
|
308
307
|
#puts code
|
309
308
|
#exit(0)
|
310
|
-
|
311
|
-
|
309
|
+
#puts
|
310
|
+
#puts "SUDO: #{self.sudo}"
|
311
|
+
# running the command
|
312
|
+
output = node.exec(code, self.sudo)
|
313
|
+
#puts
|
314
|
+
#puts '1'
|
312
315
|
# validation: at least one of the matches should happen
|
313
316
|
if self.matches.size > 0
|
314
317
|
i = 0
|
@@ -565,18 +568,36 @@ module BlackStack
|
|
565
568
|
# Reference: https://stackoverflow.com/questions/64066344/import-large-sql-files-with-ruby-sequel-gem
|
566
569
|
# This method is called by `BlackStack::Deployer::db_execute_file` if the filename matches with `/\.sentences\./`.
|
567
570
|
# This method should not be called directly by user code.
|
568
|
-
def self.execute_sentences(sql)
|
571
|
+
def self.execute_sentences(sql, chunk_size=200)
|
569
572
|
tlogger = BlackStack::Deployer::logger
|
570
573
|
|
571
574
|
# Fix issue: Ruby `split': invalid byte sequence in UTF-8 (ArgumentError)
|
572
575
|
# Reference: https://stackoverflow.com/questions/11065962/ruby-split-invalid-byte-sequence-in-utf-8-argumenterror
|
573
|
-
|
574
|
-
|
575
|
-
#
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
576
|
+
#
|
577
|
+
# Fix issue: `PG::SyntaxError: ERROR: at or near "��truncate": syntax error`
|
578
|
+
#
|
579
|
+
sql.encode!('UTF-8', :invalid => :replace, :replace => '')
|
580
|
+
|
581
|
+
# Remove null bytes to avoid error: `String contains null byte`
|
582
|
+
# Reference: https://stackoverflow.com/questions/29320369/coping-with-string-contains-null-byte-sent-from-users
|
583
|
+
sql.gsub!("\u0000", "")
|
584
|
+
|
585
|
+
# Get the array of sentences
|
586
|
+
tlogger.logs "Splitting the sql sentences... "
|
587
|
+
sentences = sql.split(/;/i)
|
588
|
+
tlogger.logf "done (#{sentences.size})"
|
589
|
+
|
590
|
+
# Chunk the array into parts of chunk_size elements
|
591
|
+
# Reference: https://stackoverflow.com/questions/2699584/how-to-split-chunk-a-ruby-array-into-parts-of-x-elements
|
592
|
+
tlogger.logs "Bunlding the array of sentences into chunks of #{chunk_size} each... "
|
593
|
+
chunks = sentences.each_slice(chunk_size).to_a
|
594
|
+
tlogger.logf "done (#{chunks.size})"
|
595
|
+
|
596
|
+
chunk_number = -1
|
597
|
+
chunks.each { |chunk|
|
598
|
+
chunk_number += 1
|
599
|
+
statement = chunk.join(";\n").to_s.strip
|
600
|
+
tlogger.logs "lines #{chunk_size*chunk_number+1} to #{chunk_size*chunk_number+chunk.size} of #{sentences.size}... "
|
580
601
|
begin
|
581
602
|
@@db.execute(statement) #if statement.to_s.strip.size > 0
|
582
603
|
tlogger.done
|
@@ -594,21 +615,30 @@ module BlackStack
|
|
594
615
|
tlogger = BlackStack::Deployer::logger
|
595
616
|
# get list of `.sql` files in the directory `sql_path`, with a name higher than `last_filename`, sorted by name.
|
596
617
|
Dir.entries(@@folder).select {
|
597
|
-
|
|
618
|
+
|filename| filename =~ /\.sql$/ && filename > @@checkpoint.to_s
|
598
619
|
}.uniq.sort.each { |filename|
|
599
620
|
fullfilename = "#{@@folder}/#{filename}"
|
600
|
-
|
601
|
-
#puts File.open(fullfilename).read
|
621
|
+
|
602
622
|
tlogger.logs "#{fullfilename}... "
|
603
623
|
BlackStack::Deployer::DB::execute_sentences( File.open(fullfilename).read )
|
604
624
|
tlogger.done
|
625
|
+
|
626
|
+
tlogger.logs "Updating checkpoint... "
|
627
|
+
@@checkpoint = filename
|
628
|
+
tlogger.done
|
605
629
|
}
|
606
630
|
end # def
|
607
631
|
end # module DB
|
608
632
|
|
609
633
|
# deploying all db-updates and run all routines on all nodes
|
610
634
|
def self.deploy()
|
611
|
-
|
635
|
+
tlogger = BlackStack::Deployer::logger
|
636
|
+
|
637
|
+
@@nodes.each { |n|
|
638
|
+
tlogger.logs "Node #{n.name}... "
|
639
|
+
n.deploy()
|
640
|
+
tlogger.done
|
641
|
+
}
|
612
642
|
end # def
|
613
643
|
|
614
644
|
end # module Deployer
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackstack-deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blackstack-nodes
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.
|
19
|
+
version: 1.2.5
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.2.
|
22
|
+
version: 1.2.5
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.2.
|
29
|
+
version: 1.2.5
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.2.
|
32
|
+
version: 1.2.5
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: pg
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|