swarm_cluster_cli_ope 0.5.0.pre.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/swarm_cluster_cli_ope.rb +9 -1
- data/lib/swarm_cluster_cli_ope/base_configuration.rb +16 -1
- data/lib/swarm_cluster_cli_ope/configuration.rb +11 -8
- data/lib/swarm_cluster_cli_ope/configuration_concern.rb +1 -1
- data/lib/swarm_cluster_cli_ope/kubernetes/configuration.rb +15 -4
- data/lib/swarm_cluster_cli_ope/kubernetes/pod.rb +2 -2
- data/lib/swarm_cluster_cli_ope/kubernetes/sync_configs/mysql.rb +10 -0
- data/lib/swarm_cluster_cli_ope/kubernetes/sync_configs/post_gres.rb +11 -0
- data/lib/swarm_cluster_cli_ope/kubernetes/sync_configs/rsync.rb +5 -7
- data/lib/swarm_cluster_cli_ope/logger_concern.rb +1 -1
- data/lib/swarm_cluster_cli_ope/stack_sync_concern.rb +7 -0
- data/lib/swarm_cluster_cli_ope/sync_configs/mysql.rb +17 -2
- data/lib/swarm_cluster_cli_ope/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f12d8c4fc65a57146f11c422f84a977a67b3d9abe1c38c32f06738fcae3bf976
|
4
|
+
data.tar.gz: 857a0b1213e30123ad0280b157b2427ef62e9223b803dac3495305ba36f32f10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a78c8ca512ef1e6e41ce46e9edf00145f56adabe173da6a848e007c517802f0a4bee1dde9e01f43dc13ad5fb31b944c9d00ef157bfe56fc38ccca21a0958032e
|
7
|
+
data.tar.gz: 0541f04dc597e9943a3aff62a2017051d84a28f354f16964fe27474e46e57c73128bc754fe4d193b4bda1ea1e926938d7105a938da83f47af916471a45f88900
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -211,7 +211,11 @@ docker-compose -f test_folder/test_1/docker-compose-local.yml up -d
|
|
211
211
|
Per Kubernetes dobbiamo avere minikube installato.
|
212
212
|
lanciare quindi l'ambiente di test:
|
213
213
|
|
214
|
+
```shell script
|
214
215
|
kubectl apply -f test_folder/test_k8s/test.yaml
|
216
|
+
docker-compose -f test_folder/test_k8s/docker-compose-local.yml up -d
|
217
|
+
```
|
218
|
+
|
215
219
|
|
216
220
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version
|
217
221
|
number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git
|
@@ -2,7 +2,15 @@ require "zeitwerk"
|
|
2
2
|
loader = Zeitwerk::Loader.for_gem
|
3
3
|
loader.setup # ready!
|
4
4
|
|
5
|
+
require "active_support/core_ext/module/attribute_accessors"
|
5
6
|
module SwarmClusterCliOpe
|
6
7
|
class Error < StandardError; end
|
7
|
-
|
8
|
+
|
9
|
+
|
10
|
+
##
|
11
|
+
# La configurazione che viene resa disponibile a tutte le funzioni sucessivamente all'interazione con il concern
|
12
|
+
# della configurazione o con il blocco di configurazione di un determinato enviroment
|
13
|
+
mattr_accessor :current_configuration
|
14
|
+
@@current_configuration = nil
|
15
|
+
|
8
16
|
end
|
@@ -137,6 +137,8 @@ module SwarmClusterCliOpe
|
|
137
137
|
exit
|
138
138
|
end
|
139
139
|
|
140
|
+
evaluate_correct_command_usage(@_merged_configurations[@environment])
|
141
|
+
|
140
142
|
@_merged_configurations[@environment]
|
141
143
|
|
142
144
|
end
|
@@ -170,9 +172,22 @@ module SwarmClusterCliOpe
|
|
170
172
|
end
|
171
173
|
end
|
172
174
|
|
173
|
-
|
175
|
+
##
|
176
|
+
# Indica il nome del progetto locale compose, quella parte di nome che viene attaccata in fronte
|
177
|
+
# ad ogni nome di servizio locale, e che come default è il nome della cartella in cui risiede
|
178
|
+
# il docker-compose.yml file
|
179
|
+
# @return [String]
|
180
|
+
def local_compose_project_name
|
181
|
+
File.basename(FileUtils.pwd).downcase
|
182
|
+
end
|
174
183
|
|
175
184
|
private
|
185
|
+
|
186
|
+
##
|
187
|
+
# Funzione che serve per identificare se siamo nella corretta classe di configurazione e di conseguenza nel corretto
|
188
|
+
# set di comandi di configurazione. Serve per non eseguire k8s con le vecchie impostazioni o viceversa
|
189
|
+
def evaluate_correct_command_usage(configuration) end
|
190
|
+
|
176
191
|
##
|
177
192
|
# nome del file in cui salvare le configurazioni di progetto
|
178
193
|
# @return [String]
|
@@ -79,17 +79,20 @@ module SwarmClusterCliOpe
|
|
79
79
|
nodes.find { |c| c.id == node_id }
|
80
80
|
end
|
81
81
|
|
82
|
-
##
|
83
|
-
# Indica il nome del progetto locale compose, quella parte di nome che viene attaccata in fronte
|
84
|
-
# ad ogni nome di servizio locale, e che come default è il nome della cartella in cui risiede
|
85
|
-
# il docker-compose.yml file
|
86
|
-
# @return [String]
|
87
|
-
def local_compose_project_name
|
88
|
-
File.basename(FileUtils.pwd).downcase
|
89
|
-
end
|
90
82
|
|
91
83
|
private
|
92
84
|
|
85
|
+
|
86
|
+
def evaluate_correct_command_usage(configuration)
|
87
|
+
|
88
|
+
if configuration[:connections_maps].keys.include?(:context)
|
89
|
+
puts "ATTENZIONE, I COMANDI DEVONO ESSERE LANCIATI DAL SUB COMANDO K8S"
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
93
96
|
##
|
94
97
|
# Path al file dove salviamo la cache dei managers, ha un TTL legato all'orario (anno-mese-giorno-ora)
|
95
98
|
# quindi ogni ora si autoripulisce e con un md5 delle configurazioni di base
|
@@ -48,16 +48,27 @@ module SwarmClusterCliOpe
|
|
48
48
|
SyncConfigs::Sqlite3
|
49
49
|
when 'rsync'
|
50
50
|
SyncConfigs::Rsync
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
when 'mysql'
|
52
|
+
SyncConfigs::Mysql
|
53
|
+
when 'pg'
|
54
|
+
SyncConfigs::PostGres
|
55
55
|
else
|
56
56
|
logger.error { "CONFIGURAIONE NON PREVISTA: #{name}" }
|
57
57
|
nil
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
private
|
62
|
+
|
63
|
+
def evaluate_correct_command_usage(configuration)
|
64
|
+
|
65
|
+
unless configuration[:connections_maps].keys.include?(:context)
|
66
|
+
puts "ATTENZIONE, I COMANDI NON DEVONO ESSERE LANCIATI DAL SUB COMANDO K8S"
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
61
72
|
|
62
73
|
end
|
63
74
|
end
|
@@ -30,9 +30,9 @@ module SwarmClusterCliOpe
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# @param [String,Array<String>] cmd -> comando da passare a kubectl exec -- CMD
|
33
|
-
# @return [SwarmClusterCliOpe::
|
33
|
+
# @return [SwarmClusterCliOpe::ShellCommandResponse]
|
34
34
|
def exec(cmd)
|
35
|
-
base_cmd(["exec", name, "--", cmd].flatten)
|
35
|
+
base_cmd(["exec", name, "--", cmd].flatten).execute
|
36
36
|
end
|
37
37
|
|
38
38
|
##
|
@@ -47,7 +47,7 @@ module SwarmClusterCliOpe
|
|
47
47
|
end
|
48
48
|
|
49
49
|
cmd = container.exec(['bash -c "apt update && apt install -yq rsync psmisc"'])
|
50
|
-
if cmd.
|
50
|
+
if cmd.failed?
|
51
51
|
puts "Problemi nell'installazione di rsync nel pod"
|
52
52
|
else
|
53
53
|
cmd = container.cp_in(File.expand_path("../../rsync_cfgs/rsyncd.conf", __FILE__), "/tmp/.")
|
@@ -55,14 +55,14 @@ module SwarmClusterCliOpe
|
|
55
55
|
cmd = container.cp_in(File.expand_path("../../rsync_cfgs/rsyncd.secrets", __FILE__), "/tmp/.")
|
56
56
|
copy_2 = cmd.execute.failed?
|
57
57
|
cmd = container.exec(['bash -c "chmod 600 /tmp/rsyncd.secrets && chown root /tmp/*"'])
|
58
|
-
chmod = cmd.
|
58
|
+
chmod = cmd.failed?
|
59
59
|
if copy_1 or copy_2 or chmod
|
60
60
|
puts "problema nella copia dei file di configurazione nel pod"
|
61
61
|
else
|
62
62
|
|
63
63
|
begin
|
64
64
|
cmd = container.exec('bash -c "rsync --daemon --config=/tmp/rsyncd.conf --verbose --log-file=/tmp/rsync.log"')
|
65
|
-
if cmd.
|
65
|
+
if cmd.failed?
|
66
66
|
say "Rsync non Inizializzato"
|
67
67
|
else
|
68
68
|
begin
|
@@ -102,15 +102,13 @@ module SwarmClusterCliOpe
|
|
102
102
|
end
|
103
103
|
ensure
|
104
104
|
say "Tolgo il servizio di rsyn"
|
105
|
-
|
106
|
-
cmd.execute
|
105
|
+
container.exec('bash -c "killall rsync"')
|
107
106
|
end
|
108
107
|
end
|
109
108
|
|
110
109
|
ensure
|
111
110
|
say "Eseguo pulizia configurazioni caricate"
|
112
|
-
|
113
|
-
cmd.execute
|
111
|
+
container.exec('bash -c "rm -fr /tmp/rsyncd*"')
|
114
112
|
end
|
115
113
|
|
116
114
|
end
|
@@ -6,7 +6,7 @@ module SwarmClusterCliOpe
|
|
6
6
|
return LoggerConcern.const_get("LOGGER") if LoggerConcern.const_defined?("LOGGER")
|
7
7
|
logger = Logger.new(STDOUT)
|
8
8
|
LoggerConcern.const_set("LOGGER", logger)
|
9
|
-
logger.level = case
|
9
|
+
logger.level = case BaseConfiguration.instance.logger_level
|
10
10
|
when "0"
|
11
11
|
Logger::ERROR
|
12
12
|
when "1"
|
@@ -102,6 +102,13 @@ module SwarmClusterCliOpe
|
|
102
102
|
else
|
103
103
|
raise "ONLY [push|pull] action accepted"
|
104
104
|
end
|
105
|
+
|
106
|
+
if direction == :push
|
107
|
+
unless yes? "ATTENZIONE STAI FACENDO PUSH, proseguire????[y,yes]"
|
108
|
+
exit "OK, CIAO"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
105
112
|
cfgs.env(options[:environment]) do |cfgs|
|
106
113
|
sync_cfgs = cfgs.sync_configurations
|
107
114
|
if sync_cfgs.empty?
|
@@ -7,9 +7,24 @@ module SwarmClusterCliOpe
|
|
7
7
|
resume('pull')
|
8
8
|
if yes?("Confermare il comando?[y,yes]")
|
9
9
|
tmp_file = "/tmp/#{Time.now.to_i}.sql.gz"
|
10
|
-
container.exec("bash -c 'mysqldump
|
10
|
+
container.exec("bash -c 'mysqldump -u #{remote.username} --password=#{remote.password} #{remote.database_name} | gzip -c -f' > #{tmp_file}")
|
11
11
|
local_container.copy_in(tmp_file, tmp_file)
|
12
|
-
|
12
|
+
local_authentication = "-u #{local.username} --password=#{local.password}"
|
13
|
+
|
14
|
+
command = []
|
15
|
+
command << "bash -c '"
|
16
|
+
|
17
|
+
command << "mysql #{local_authentication} -e \"DROP DATABASE IF EXISTS #{local.database_name};CREATE DATABASE #{local.database_name}\""
|
18
|
+
|
19
|
+
command << "&&"
|
20
|
+
|
21
|
+
command << "zcat #{tmp_file}"
|
22
|
+
command << "|"
|
23
|
+
command << "mysql #{local_authentication} #{local.database_name}"
|
24
|
+
|
25
|
+
command << "'"
|
26
|
+
|
27
|
+
local_container.exec(command.join" ")
|
13
28
|
end
|
14
29
|
true
|
15
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swarm_cluster_cli_ope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marino Bonetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -105,6 +105,8 @@ files:
|
|
105
105
|
- lib/swarm_cluster_cli_ope/kubernetes/rsync_cfgs/rsyncd.conf
|
106
106
|
- lib/swarm_cluster_cli_ope/kubernetes/rsync_cfgs/rsyncd.secrets
|
107
107
|
- lib/swarm_cluster_cli_ope/kubernetes/sync_configs/base_decorator.rb
|
108
|
+
- lib/swarm_cluster_cli_ope/kubernetes/sync_configs/mysql.rb
|
109
|
+
- lib/swarm_cluster_cli_ope/kubernetes/sync_configs/post_gres.rb
|
108
110
|
- lib/swarm_cluster_cli_ope/kubernetes/sync_configs/rsync.rb
|
109
111
|
- lib/swarm_cluster_cli_ope/kubernetes/sync_configs/sqlite3.rb
|
110
112
|
- lib/swarm_cluster_cli_ope/logger_concern.rb
|
@@ -151,9 +153,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
153
|
version: 2.3.0
|
152
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
155
|
requirements:
|
154
|
-
- - "
|
156
|
+
- - ">="
|
155
157
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
158
|
+
version: '0'
|
157
159
|
requirements: []
|
158
160
|
rubygems_version: 3.0.8
|
159
161
|
signing_key:
|