swarm_cluster_cli_ope 0.5.0.pre.2 → 0.5.1
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/Gemfile.lock +1 -45
- data/README.md +11 -2
- data/lib/swarm_cluster_cli_ope.rb +9 -1
- data/lib/swarm_cluster_cli_ope/base_configuration.rb +226 -0
- data/lib/swarm_cluster_cli_ope/cli.rb +2 -129
- data/lib/swarm_cluster_cli_ope/configuration.rb +10 -186
- data/lib/swarm_cluster_cli_ope/configuration_concern.rb +10 -9
- data/lib/swarm_cluster_cli_ope/k8s.rb +59 -83
- data/lib/swarm_cluster_cli_ope/kubernetes/configuration.rb +75 -0
- data/lib/swarm_cluster_cli_ope/kubernetes/pod.rb +144 -0
- data/lib/swarm_cluster_cli_ope/{k8s_rsync → kubernetes/rsync_cfgs}/password +0 -0
- data/lib/swarm_cluster_cli_ope/{k8s_rsync → kubernetes/rsync_cfgs}/rsyncd.conf +0 -0
- data/lib/swarm_cluster_cli_ope/{k8s_rsync → kubernetes/rsync_cfgs}/rsyncd.secrets +0 -0
- data/lib/swarm_cluster_cli_ope/kubernetes/sync_configs/base_decorator.rb +28 -0
- 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 +125 -0
- data/lib/swarm_cluster_cli_ope/kubernetes/sync_configs/sqlite3.rb +9 -0
- data/lib/swarm_cluster_cli_ope/logger_concern.rb +1 -1
- data/lib/swarm_cluster_cli_ope/shell_command_response.rb +18 -5
- data/lib/swarm_cluster_cli_ope/stack_sync_concern.rb +135 -0
- data/lib/swarm_cluster_cli_ope/sync_configs/base.rb +1 -1
- data/lib/swarm_cluster_cli_ope/sync_configs/mysql.rb +17 -2
- data/lib/swarm_cluster_cli_ope/sync_configs/post_gres.rb +1 -1
- data/lib/swarm_cluster_cli_ope/thor_configuration_concern.rb +29 -0
- data/lib/swarm_cluster_cli_ope/version.rb +1 -1
- data/swarm_cluster_cli_ope.gemspec +0 -1
- metadata +17 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deeeb31f5b17f54bd476bb6cc8100c91dbba91386188ee468e14b1d50c36b99a
|
4
|
+
data.tar.gz: d6cd6932874bd1d393b4c975e1978f64db2870f3705bb3e243f4792114c60a42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 694ec83f00a6c979fbb1f525d02194d3bdb58cd6a91239a511774d1d3ef9a3a38cd9068edcd3757a2318cc3f863b6c362692519500cd4d4436f431fa3a091320
|
7
|
+
data.tar.gz: 3bcb05e5402cf1750908310b29fa930424da6afb74f2157978989e0a7872f94b6090122e0d7bd1568b8ef408bf75d1dc0cc1ac12abadda1416b1bc372985346e
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
swarm_cluster_cli_ope (0.5.
|
4
|
+
swarm_cluster_cli_ope (0.5.1)
|
5
5
|
activesupport
|
6
|
-
kubeclient (~> 4.9)
|
7
6
|
open4
|
8
7
|
thor (~> 1.0)
|
9
8
|
zeitwerk (~> 2.3)
|
@@ -17,59 +16,16 @@ GEM
|
|
17
16
|
minitest (~> 5.1)
|
18
17
|
tzinfo (~> 1.1)
|
19
18
|
zeitwerk (~> 2.2, >= 2.2.2)
|
20
|
-
addressable (2.7.0)
|
21
|
-
public_suffix (>= 2.0.2, < 5.0)
|
22
19
|
concurrent-ruby (1.1.7)
|
23
|
-
domain_name (0.5.20190701)
|
24
|
-
unf (>= 0.0.5, < 1.0.0)
|
25
|
-
ffi (1.13.1)
|
26
|
-
ffi-compiler (1.0.1)
|
27
|
-
ffi (>= 1.0.0)
|
28
|
-
rake
|
29
|
-
http (4.4.1)
|
30
|
-
addressable (~> 2.3)
|
31
|
-
http-cookie (~> 1.0)
|
32
|
-
http-form_data (~> 2.2)
|
33
|
-
http-parser (~> 1.2.0)
|
34
|
-
http-accept (1.7.0)
|
35
|
-
http-cookie (1.0.3)
|
36
|
-
domain_name (~> 0.5)
|
37
|
-
http-form_data (2.3.0)
|
38
|
-
http-parser (1.2.1)
|
39
|
-
ffi-compiler (>= 1.0, < 2.0)
|
40
20
|
i18n (1.8.5)
|
41
21
|
concurrent-ruby (~> 1.0)
|
42
|
-
jsonpath (1.0.5)
|
43
|
-
multi_json
|
44
|
-
to_regexp (~> 0.2.1)
|
45
|
-
kubeclient (4.9.1)
|
46
|
-
http (>= 3.0, < 5.0)
|
47
|
-
jsonpath (~> 1.0)
|
48
|
-
recursive-open-struct (~> 1.1, >= 1.1.1)
|
49
|
-
rest-client (~> 2.0)
|
50
|
-
mime-types (3.3.1)
|
51
|
-
mime-types-data (~> 3.2015)
|
52
|
-
mime-types-data (3.2020.1104)
|
53
22
|
minitest (5.14.2)
|
54
|
-
multi_json (1.15.0)
|
55
|
-
netrc (0.11.0)
|
56
23
|
open4 (1.3.4)
|
57
|
-
public_suffix (4.0.6)
|
58
24
|
rake (12.3.3)
|
59
|
-
recursive-open-struct (1.1.3)
|
60
|
-
rest-client (2.1.0)
|
61
|
-
http-accept (>= 1.7.0, < 2.0)
|
62
|
-
http-cookie (>= 1.0.2, < 2.0)
|
63
|
-
mime-types (>= 1.16, < 4.0)
|
64
|
-
netrc (~> 0.8)
|
65
25
|
thor (1.0.1)
|
66
26
|
thread_safe (0.3.6)
|
67
|
-
to_regexp (0.2.1)
|
68
27
|
tzinfo (1.2.8)
|
69
28
|
thread_safe (~> 0.1)
|
70
|
-
unf (0.1.4)
|
71
|
-
unf_ext
|
72
|
-
unf_ext (0.0.7.7)
|
73
29
|
zeitwerk (2.4.1)
|
74
30
|
|
75
31
|
PLATFORMS
|
data/README.md
CHANGED
@@ -110,7 +110,7 @@ ogni configurazione è composta da:
|
|
110
110
|
}
|
111
111
|
```
|
112
112
|
|
113
|
-
- service è il nome del servizio
|
113
|
+
- service è il nome del servizio (o nel caso di k8s una stringa da utilizzare come selettore labels)
|
114
114
|
- how è il come sincronizzare, definendo la tipologia:
|
115
115
|
- pg -> DB TODO
|
116
116
|
- mysql -> DB: dump del db con mysqldump
|
@@ -193,7 +193,7 @@ Esempio di sincronizzazione di un file sqlite3 e una cartella
|
|
193
193
|
|
194
194
|
nel file di configurazione creato nella home aggiungere la chiave "dev_mode":1 per collegarsi localmente
|
195
195
|
|
196
|
-
### Abbiamo due tasks
|
196
|
+
### Abbiamo due tasks SWARM di simulazione
|
197
197
|
```shell script
|
198
198
|
docker stack deploy -c test_folder/test_1/docker-compose.yml test_1_stack
|
199
199
|
docker stack deploy -c test_folder/test_1/docker-compose.yml test1_staging
|
@@ -207,6 +207,15 @@ docker-compose -f test_folder/test_1/docker-compose-local.yml up -d
|
|
207
207
|
```
|
208
208
|
|
209
209
|
|
210
|
+
### K8s
|
211
|
+
Per Kubernetes dobbiamo avere minikube installato.
|
212
|
+
lanciare quindi l'ambiente di test:
|
213
|
+
|
214
|
+
```shell script
|
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
|
+
|
210
219
|
|
211
220
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version
|
212
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
|
@@ -0,0 +1,226 @@
|
|
1
|
+
module SwarmClusterCliOpe
|
2
|
+
##
|
3
|
+
# Classe Base delle configurazioni, utilizzabile per swarm e kubernetes
|
4
|
+
class BaseConfiguration
|
5
|
+
include Singleton
|
6
|
+
include LoggerConcern
|
7
|
+
|
8
|
+
#@return [String] nome dello stack con cui lavoriamo
|
9
|
+
attr_accessor :stack_name
|
10
|
+
|
11
|
+
#@return [String] in che enviroment siamo, altrimenti siamo nel default
|
12
|
+
attr_accessor :environment
|
13
|
+
|
14
|
+
NoBaseConfigurations = Class.new(Error)
|
15
|
+
|
16
|
+
##
|
17
|
+
# Serve per entrare nell'env corretto.
|
18
|
+
# passando l'env, tutto quello eseguito nello yield sarà gestito in quell'env.
|
19
|
+
# Verrà controllato quindi che esista il relativo file di configurazion
|
20
|
+
def env(enviroment = nil)
|
21
|
+
unless enviroment.nil?
|
22
|
+
@environment = enviroment.to_s.to_sym
|
23
|
+
end
|
24
|
+
logger.info { "ENV: #{@environment ? @environment : "BASE"}" }
|
25
|
+
yield self
|
26
|
+
@environment = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String,NilClass] nome dello stack del progetto se configurato
|
30
|
+
def stack_name
|
31
|
+
return nil unless self.class.exist_base?
|
32
|
+
@stack_name ||= Hash.new do |hash, key|
|
33
|
+
hash[key] = merged_configurations[:stack_name] if merged_configurations.key?(:stack_name)
|
34
|
+
end
|
35
|
+
@stack_name[environment]
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Imposta il nome dello stack
|
40
|
+
def stack_name=(objs)
|
41
|
+
stack_name #lo richiamo per fargli generare la variabile di classe
|
42
|
+
@stack_name[environment] = objs
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Livello di logging
|
47
|
+
# @return [Integer]
|
48
|
+
def logger_level
|
49
|
+
merged_configurations[:log_level].to_s || "0"
|
50
|
+
rescue SwarmClusterCliOpe::Configuration::NoBaseConfigurations
|
51
|
+
# quando andiamo in errore durante l'installazione per avere le informazioni per il logger.
|
52
|
+
# Usiamo lo standard
|
53
|
+
"0"
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Siamo in sviluppo?
|
58
|
+
# @return [TrueClass, FalseClass]
|
59
|
+
def development_mode?
|
60
|
+
return false unless self.class.exist_base?
|
61
|
+
merged_configurations.key?(:dev_mode)
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Controlla se esiste il file di configurazione base, nella home dell'utente
|
66
|
+
def self.exist_base?
|
67
|
+
File.exist?(base_cfg_path)
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# @return [String] path to base home configurations
|
72
|
+
def self.base_cfg_path
|
73
|
+
File.join(ENV['HOME'], '.swarm_cluster', 'config.json')
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
##
|
78
|
+
# Elenco di tutte le configurazioni di sincronizzazione
|
79
|
+
# @return [Array]
|
80
|
+
def sync_configurations
|
81
|
+
cfgs = merged_configurations[:sync_configs]
|
82
|
+
return [] if cfgs.nil? or !cfgs.is_a?(Array)
|
83
|
+
cfgs.collect do |c|
|
84
|
+
|
85
|
+
if self.get_syncro(c[:how])
|
86
|
+
self.get_syncro(c[:how]).new(self, c)
|
87
|
+
end
|
88
|
+
|
89
|
+
end.compact
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Funzione per la restituzione della classe di sincro corretta
|
94
|
+
# @return [Class<SwarmClusterCliOpe::SyncConfigs::PostGres>, Class<SwarmClusterCliOpe::SyncConfigs::Mysql>, Class<SwarmClusterCliOpe::SyncConfigs::Rsync>, Class<SwarmClusterCliOpe::SyncConfigs::Sqlite3>, nil]
|
95
|
+
def get_syncro(name)
|
96
|
+
case name
|
97
|
+
when 'sqlite3'
|
98
|
+
SyncConfigs::Sqlite3
|
99
|
+
when 'rsync'
|
100
|
+
SyncConfigs::Rsync
|
101
|
+
when 'mysql'
|
102
|
+
SyncConfigs::Mysql
|
103
|
+
when 'pg'
|
104
|
+
SyncConfigs::PostGres
|
105
|
+
else
|
106
|
+
logger.error { "CONFIGURAIONE NON PREVISTA: #{name}" }
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
## Cerca le configurazioni di progetto e le mergia se sono presenti
|
112
|
+
# @return [Hash]
|
113
|
+
def merged_configurations
|
114
|
+
return @_merged_configurations[@environment] if @_merged_configurations
|
115
|
+
|
116
|
+
@_merged_configurations = Hash.new do |hash, key|
|
117
|
+
folder = FileUtils.pwd
|
118
|
+
default_file = looped_file(folder, self.class.cfgs_project_file_name)
|
119
|
+
enviroment_file = looped_file(folder, self.class.cfgs_project_file_name(with_env: key))
|
120
|
+
|
121
|
+
project_cfgs = {}
|
122
|
+
unless default_file.nil?
|
123
|
+
project_cfgs = JSON.parse(File.read(default_file)).deep_symbolize_keys
|
124
|
+
end
|
125
|
+
|
126
|
+
unless enviroment_file.nil?
|
127
|
+
project_cfgs.merge!(JSON.parse(File.read(enviroment_file)).deep_symbolize_keys)
|
128
|
+
end
|
129
|
+
|
130
|
+
hash[key] = self.class.read_base.merge(project_cfgs)
|
131
|
+
end
|
132
|
+
|
133
|
+
configuration_version = @_merged_configurations[@environment][:version]
|
134
|
+
if Gem::Version.new(configuration_version) > Gem::Version.new(VERSION)
|
135
|
+
puts "WARNING: Versione del file di configurazione [#{configuration_version}] più aggiornata della gemma [#{VERSION}], eseguire upgrade
|
136
|
+
gem update swarm_cluster_cli_ope"
|
137
|
+
exit
|
138
|
+
end
|
139
|
+
|
140
|
+
evaluate_correct_command_usage(@_merged_configurations[@environment])
|
141
|
+
|
142
|
+
@_merged_configurations[@environment]
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
##
|
148
|
+
# Si occupa del salvataggio delle configurazioni di progetto, se abbiamo lo stack_name
|
149
|
+
def save_project_cfgs
|
150
|
+
if stack_name
|
151
|
+
File.open(File.join(FileUtils.pwd, self.class.cfgs_project_file_name(with_env: @environment)), "wb") do |f|
|
152
|
+
f.write({
|
153
|
+
stack_name: stack_name,
|
154
|
+
version: VERSION
|
155
|
+
}.to_json)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
##
|
162
|
+
# Salva le configurazioni base in HOME
|
163
|
+
def save_base_cfgs
|
164
|
+
FileUtils.mkdir_p(File.dirname(self.class.base_cfg_path))
|
165
|
+
File.open(self.class.base_cfg_path, "wb") do |f|
|
166
|
+
obj= {
|
167
|
+
version: SwarmClusterCliOpe::VERSION,
|
168
|
+
}
|
169
|
+
obj = yield(obj) if block_given?
|
170
|
+
|
171
|
+
f.write(obj.to_json)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
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
|
183
|
+
|
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
|
+
|
191
|
+
##
|
192
|
+
# nome del file in cui salvare le configurazioni di progetto
|
193
|
+
# @return [String]
|
194
|
+
# @param [nil|String] with_env nome dell'env da cercare
|
195
|
+
def self.cfgs_project_file_name(with_env: nil)
|
196
|
+
".swarm_cluster_project#{with_env ? ".#{with_env}" : ""}"
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# Legge le configurazioni base
|
201
|
+
#
|
202
|
+
# @return [Hash]
|
203
|
+
def self.read_base
|
204
|
+
raise NoBaseConfigurations if !exist_base? or File.size(self.base_cfg_path)==0
|
205
|
+
JSON.parse(File.read(self.base_cfg_path)).deep_symbolize_keys
|
206
|
+
end
|
207
|
+
|
208
|
+
def looped_file(start_folder, file)
|
209
|
+
project_file = nil
|
210
|
+
loop do
|
211
|
+
|
212
|
+
if File.exist?(File.join(start_folder, file))
|
213
|
+
project_file = File.join(start_folder, file)
|
214
|
+
end
|
215
|
+
|
216
|
+
break unless project_file.nil?
|
217
|
+
break if start_folder == '/'
|
218
|
+
start_folder = File.expand_path("..", start_folder)
|
219
|
+
end
|
220
|
+
|
221
|
+
project_file
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
end
|
226
|
+
end
|
@@ -5,6 +5,7 @@ module SwarmClusterCliOpe
|
|
5
5
|
class Cli < Thor
|
6
6
|
include LoggerConcern
|
7
7
|
include ConfigurationConcern
|
8
|
+
include ThorConfigurationConcern
|
8
9
|
include Thor::Actions
|
9
10
|
|
10
11
|
def self.exit_on_failure?
|
@@ -44,14 +45,6 @@ module SwarmClusterCliOpe
|
|
44
45
|
|
45
46
|
end
|
46
47
|
|
47
|
-
desc "config", "Visualizza le configurazioni mergiate (HOME + Project configuration[#{Configuration.cfgs_project_file_name}])"
|
48
|
-
|
49
|
-
def config
|
50
|
-
cfgs.env(options[:environment]) do
|
51
|
-
puts JSON.pretty_generate(cfgs.merged_configurations)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
48
|
|
56
49
|
# DOCKER_HOST=ssh://swarm_node_1 docker stack ls --format="{{json .}}"
|
57
50
|
desc "stacks", "Lista degli stacks nel cluster"
|
@@ -191,16 +184,6 @@ module SwarmClusterCliOpe
|
|
191
184
|
end
|
192
185
|
|
193
186
|
|
194
|
-
desc "configure_project STACK_NAME", "Genera il file di configurazione del progetto contenente il nome dello stack"
|
195
|
-
|
196
|
-
def configure_project(stack_name)
|
197
|
-
cfgs.env(options[:environment]) do |c|
|
198
|
-
c.stack_name = stack_name
|
199
|
-
c.save_project_cfgs
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
187
|
desc "service_shell SERVICE_NAME", "apre una shell [default bash] dentro al container"
|
205
188
|
option :stack_name, required: false, type: :string
|
206
189
|
option :shell, required: false, type: :string, default: 'bash'
|
@@ -252,117 +235,7 @@ module SwarmClusterCliOpe
|
|
252
235
|
say VERSION
|
253
236
|
end
|
254
237
|
|
255
|
-
|
256
|
-
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
257
|
-
le configurazioni sono contenute nell'array: sync_configs.
|
258
|
-
ogni configurazione è composta da:
|
259
|
-
{
|
260
|
-
service:""
|
261
|
-
how:""
|
262
|
-
configs:{ }
|
263
|
-
}
|
264
|
-
- service è il nome del servizio
|
265
|
-
- how è il come sincronizzare, definendo la tipologia:
|
266
|
-
---- pg -> DB TODO
|
267
|
-
---- mysql -> DB dump con mysql
|
268
|
-
---- sqlite3 -> DB: viene eseguita una copia del file
|
269
|
-
---- rsync -> RSYNC
|
270
|
-
- configs: è un hash con le configurazioni per ogni tipo di sincronizzazione
|
271
|
-
|
272
|
-
Possibili CFGS per tipologia:
|
273
|
-
rsync:
|
274
|
-
--local: -> path cartella locale
|
275
|
-
--remote: -> path cartella remota (contesto del container)
|
276
|
-
|
277
|
-
sqlite3:
|
278
|
-
--local: -> path al file
|
279
|
-
--remote: -> path al file remoto (contesto del container)
|
280
|
-
|
281
|
-
mysql:
|
282
|
-
--local: -> hash di configurazioni per il DB locale
|
283
|
-
- service: "db" -> nome del servizio nel compose locale, DEFAULT: quello definito sopra
|
284
|
-
- mysql_password_env: "MYSQL_PASSWORD" -> variabile ambiente interna al servizio contenente PASSWORD, DEFAULT: MYSQL_PASSWORD
|
285
|
-
- mysql_password: "root" -> valore in chiaro, in sostituzione della variabile ambiente, DEFAULT: root
|
286
|
-
- mysql_user_env: "MYSQL_USER" -> variabile ambiente interna al servizio contenente USERNAME, DEFAULT: MYSQL_USER
|
287
|
-
- mysql_user: "root" -> valore in chiaro, in sostituzione della variabile ambiente, DEFAULT: root
|
288
|
-
- database_name_env: "MYSQL_DATABASE" -> variabile ambiente interna al servizio contenente NOME DB, DEFAULT: MYSQL_DATABASE
|
289
|
-
- database_name: "nome_db" -> valore in chiaro, in sostituzione della variabile ambiente
|
290
|
-
--remote: -> hash di configurazioni per il DB remoto
|
291
|
-
- service: "db" -> nome del servizio nel compose locale, DEFAULT: quello definito sopra
|
292
|
-
- mysql_password_env: "MYSQL_PASSWORD" -> variabile ambiente interna al servizio contenente PASSWORD, DEFAULT: MYSQL_PASSWORD
|
293
|
-
- mysql_password: "root" -> valore in chiaro, in sostituzione della variabile ambiente, DEFAULT: root
|
294
|
-
- mysql_user_env: "MYSQL_USER" -> variabile ambiente interna al servizio contenente USERNAME, DEFAULT: MYSQL_USER
|
295
|
-
- mysql_user: "root" -> valore in chiaro, in sostituzione della variabile ambiente, DEFAULT: root
|
296
|
-
- database_name_env: "MYSQL_DATABASE" -> variabile ambiente interna al servizio contenente NOME DB, DEFAULT: MYSQL_DATABASE
|
297
|
-
- database_name: "MYSQL_DATABASE" -> valore in chiaro, in sostituzione della variabile ambiente
|
298
|
-
pg:
|
299
|
-
--local: -> hash di configurazioni per il DB locale
|
300
|
-
- service: "db" -> nome del servizio nel compose locale, DEFAULT: quello definito sopra
|
301
|
-
- pg_password_env: "POSTGRES_USER" -> variabile ambiente interna al servizio contenente PASSWORD, DEFAULT: POSTGRES_PASSWORD
|
302
|
-
- pg_password: "" -> valore in chiaro, in sostituzione della variabile ambiente
|
303
|
-
- pg_user_env: "POSTGRES_USER" -> variabile ambiente interna al servizio contenente USERNAME, DEFAULT: POSTGRES_USER
|
304
|
-
- pg_user: "postgres" -> valore in chiaro, in sostituzione della variabile ambiente, DEFAULT: postgres
|
305
|
-
- database_name_env: "POSTGRES_DB" -> variabile ambiente interna al servizio contenente NOME DB, DEFAULT: POSTGRES_DB
|
306
|
-
- database_name: "nome_db" -> valore in chiaro, in sostituzione della variabile ambiente
|
307
|
-
--remote: -> hash di configurazioni per il DB remoto
|
308
|
-
- service: "db" -> nome del servizio nel compose locale, DEFAULT: quello definito sopra
|
309
|
-
- pg_password_env: "POSTGRES_USER" -> variabile ambiente interna al servizio contenente PASSWORD, DEFAULT: POSTGRES_PASSWORD
|
310
|
-
- pg_password: "" -> valore in chiaro, in sostituzione della variabile ambiente
|
311
|
-
- pg_user_env: "POSTGRES_USER" -> variabile ambiente interna al servizio contenente USERNAME, DEFAULT: POSTGRES_USER
|
312
|
-
- pg_user: "postgres" -> valore in chiaro, in sostituzione della variabile ambiente, DEFAULT: postgres
|
313
|
-
- database_name_env: "POSTGRES_DB" -> variabile ambiente interna al servizio contenente NOME DB, DEFAULT: POSTGRES_DB
|
314
|
-
- database_name: "nome_db" -> valore in chiaro, in sostituzione della variabile ambiente
|
315
|
-
|
316
|
-
|
317
|
-
EXAMPLE:
|
318
|
-
Esempio di sincronizzazione di un file sqlite3 e una cartella
|
319
|
-
{
|
320
|
-
"stack_name": "test1",
|
321
|
-
"sync_configs": [
|
322
|
-
{
|
323
|
-
"service": "second",
|
324
|
-
"how": "rsync",
|
325
|
-
"configs": {
|
326
|
-
"remote": "/test_bind",
|
327
|
-
"local": "./uploads"
|
328
|
-
}
|
329
|
-
},
|
330
|
-
{
|
331
|
-
"service": "test_sqlite3",
|
332
|
-
"how": "sqlite3",
|
333
|
-
"configs": {
|
334
|
-
"remote": "/cartella_sqlite3/esempio.sqlite3",
|
335
|
-
"local": "./development.sqlite3"
|
336
|
-
}
|
337
|
-
}
|
338
|
-
]
|
339
|
-
}
|
340
|
-
LONGDESC
|
341
|
-
|
342
|
-
def stacksync(direction)
|
343
|
-
direction = case direction
|
344
|
-
when 'push'
|
345
|
-
:push
|
346
|
-
when 'pull'
|
347
|
-
:pull
|
348
|
-
else
|
349
|
-
raise "ONLY [push|pull] action accepted"
|
350
|
-
end
|
351
|
-
cfgs.env(options[:environment]) do |cfgs|
|
352
|
-
sync_cfgs = cfgs.sync_configurations
|
353
|
-
if sync_cfgs.empty?
|
354
|
-
say "Attenzione, configurazioni di sincronizzazione vuoto. Leggere la documentazione"
|
355
|
-
else
|
356
|
-
sync_cfgs.each do |sync|
|
357
|
-
say "----------->>>>>>"
|
358
|
-
say "[ #{sync.class.name} ]"
|
359
|
-
sync.send(direction)
|
360
|
-
say "COMPLETE"
|
361
|
-
say "<<<<<<-----------"
|
362
|
-
end
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
238
|
+
include StackSyncConcern
|
366
239
|
|
367
240
|
private
|
368
241
|
|