swarm_cluster_cli_ope 0.5.0 → 0.5.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f12d8c4fc65a57146f11c422f84a977a67b3d9abe1c38c32f06738fcae3bf976
4
- data.tar.gz: 857a0b1213e30123ad0280b157b2427ef62e9223b803dac3495305ba36f32f10
3
+ metadata.gz: 3f13501680246e78bd7c7d3e6694a7ec96a46ea817f58b0a0ab98cecc394002e
4
+ data.tar.gz: d17bcf2b19090a6156e39da8171ae821b27822c308806b55daad73193ab68726
5
5
  SHA512:
6
- metadata.gz: a78c8ca512ef1e6e41ce46e9edf00145f56adabe173da6a848e007c517802f0a4bee1dde9e01f43dc13ad5fb31b944c9d00ef157bfe56fc38ccca21a0958032e
7
- data.tar.gz: 0541f04dc597e9943a3aff62a2017051d84a28f354f16964fe27474e46e57c73128bc754fe4d193b4bda1ea1e926938d7105a938da83f47af916471a45f88900
6
+ metadata.gz: 16e6068c30b780460fdd6c6b12580d5397f8162f5c9c38b1f1e74dffbe3373028b9bd5428cdcaa15386e55e5d6354d35787bf7026c965f55c028ab81cde6bb26
7
+ data.tar.gz: db7aedd27c45e08c9c9b636da84d0916d0a7ed8c2d0b27ed07f3b4bc6d77811d0a36dee141c879d76c7ac70f34cd47520309df0235e6a141214d851d43884721
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## Changelog
2
2
 
3
+ # 0.5.5
4
+ - correzione utilizzo e configurazione variabili ambiente nelle configurazioni.
5
+ - controllo di non installare rsync e killall nel caso siano già presenti.
6
+
7
+ # 0.5.4
8
+ - bug permessi sul file password dell'rsync
9
+
10
+ # 0.5.3
11
+ - bug selezione pod, ora filtra solamente per i containers che sono attivi
12
+
3
13
  # 0.4
4
14
  - implementazione push pull con il comando **stacksync** di pg
5
15
  - controllo di versione sul file caricato rispeto a gemma, con conseguente warning
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swarm_cluster_cli_ope (0.5.0)
4
+ swarm_cluster_cli_ope (0.5.5)
5
5
  activesupport
6
6
  open4
7
7
  thor (~> 1.0)
@@ -10,23 +10,22 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (6.0.3.4)
13
+ activesupport (6.1.1)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (>= 0.7, < 2)
16
- minitest (~> 5.1)
17
- tzinfo (~> 1.1)
18
- zeitwerk (~> 2.2, >= 2.2.2)
19
- concurrent-ruby (1.1.7)
20
- i18n (1.8.5)
15
+ i18n (>= 1.6, < 2)
16
+ minitest (>= 5.1)
17
+ tzinfo (~> 2.0)
18
+ zeitwerk (~> 2.3)
19
+ concurrent-ruby (1.1.8)
20
+ i18n (1.8.7)
21
21
  concurrent-ruby (~> 1.0)
22
- minitest (5.14.2)
22
+ minitest (5.14.3)
23
23
  open4 (1.3.4)
24
24
  rake (12.3.3)
25
- thor (1.0.1)
26
- thread_safe (0.3.6)
27
- tzinfo (1.2.8)
28
- thread_safe (~> 0.1)
29
- zeitwerk (2.4.1)
25
+ thor (1.1.0)
26
+ tzinfo (2.0.4)
27
+ concurrent-ruby (~> 1.0)
28
+ zeitwerk (2.4.2)
30
29
 
31
30
  PLATFORMS
32
31
  ruby
@@ -90,6 +90,7 @@ module SwarmClusterCliOpe
90
90
  base_cmd << "--context=#{context}" unless context.blank?
91
91
  base_cmd << "get pod"
92
92
  base_cmd << "--selector=#{selector}"
93
+ base_cmd << "--field-selector=status.phase=Running" #solo pod che stanno girando teniamo sotto controllo
93
94
  base_cmd << "--output=json"
94
95
 
95
96
  cmd = ShellCommandExecution.new(base_cmd)
@@ -15,7 +15,6 @@ module SwarmClusterCliOpe
15
15
  @configs[:configs][:remote]
16
16
  end
17
17
 
18
-
19
18
  # @return [SwarmClusterCliOpe::ShellCommandResponse]
20
19
  def push
21
20
  execute(direction: :up)
@@ -26,7 +25,6 @@ module SwarmClusterCliOpe
26
25
  execute(direction: :down)
27
26
  end
28
27
 
29
-
30
28
  private
31
29
 
32
30
  def execute(direction: :down)
@@ -36,7 +34,6 @@ module SwarmClusterCliOpe
36
34
  exit
37
35
  end
38
36
 
39
-
40
37
  if yes? "Attenzione, i dati locali o remoti verranno sovrascritti/cancellati?[y,yes]"
41
38
 
42
39
  podname = container.name
@@ -46,13 +43,30 @@ module SwarmClusterCliOpe
46
43
  exit
47
44
  end
48
45
 
49
- cmd = container.exec(['bash -c "apt update && apt install -yq rsync psmisc"'])
50
- if cmd.failed?
51
- puts "Problemi nell'installazione di rsync nel pod"
52
- else
53
- cmd = container.cp_in(File.expand_path("../../rsync_cfgs/rsyncd.conf", __FILE__), "/tmp/.")
46
+ # controllo presenza comandi necessari
47
+ command_installed = false
48
+ cmd_ricerca = container.exec(['bash -c "command -v rsync && command -v killall"'])
49
+ unless cmd_ricerca.failed?
50
+ num_commands = cmd_ricerca.raw_result[:stdout].split("\n").count rescue 0
51
+ if num_commands == 2
52
+ command_installed = true
53
+ end
54
+ end
55
+
56
+ unless command_installed
57
+ # tentiamo di installarlo
58
+ cmd = container.exec(['bash -c "apt update && apt install -yq rsync psmisc"'])
59
+ if cmd.failed?
60
+ puts "Problemi nell'installazione di rsync nel pod"
61
+ else
62
+ command_installed = true
63
+ end
64
+ end
65
+
66
+ if command_installed
67
+ cmd = container.cp_in(configs_path("rsyncd.conf"), "/tmp/.")
54
68
  copy_1 = cmd.execute.failed?
55
- cmd = container.cp_in(File.expand_path("../../rsync_cfgs/rsyncd.secrets", __FILE__), "/tmp/.")
69
+ cmd = container.cp_in(configs_path("rsyncd.secrets"), "/tmp/.")
56
70
  copy_2 = cmd.execute.failed?
57
71
  cmd = container.exec(['bash -c "chmod 600 /tmp/rsyncd.secrets && chown root /tmp/*"'])
58
72
  chmod = cmd.failed?
@@ -76,11 +90,15 @@ module SwarmClusterCliOpe
76
90
 
77
91
  sleep 1
78
92
 
93
+ # forzo i permessi sul file della password
94
+ cmd = ShellCommandExecution.new(["chmod 600 #{ configs_path("password")}"])
95
+ cmd.execute
96
+
79
97
  # lanciamo il comando quindi per far rsync
80
98
  rsync_command = [
81
99
  "rsync -az --no-o --no-g",
82
100
  "--delete",
83
- "--password-file=#{ File.expand_path("../../rsync_cfgs/password", __FILE__)}"
101
+ "--password-file=#{ configs_path("password")}"
84
102
  ]
85
103
 
86
104
  if direction == :up
@@ -119,6 +137,14 @@ module SwarmClusterCliOpe
119
137
 
120
138
  end
121
139
 
140
+ ##
141
+ # Estrapola la path al file di configurazione
142
+ # @param [String] file
143
+ # @return [String]
144
+ def configs_path(file)
145
+ File.expand_path("../../rsync_cfgs/#{file}", __FILE__)
146
+ end
147
+
122
148
  end
123
149
  end
124
150
  end
@@ -17,6 +17,7 @@ module SwarmClusterCliOpe
17
17
  ##
18
18
  # Metodo che richiama la lambda della generazione del container al momento che ne
19
19
  # è proprio necessario
20
+ # @return [SwarmClusterCliOpe::Commands::Container,SwarmClusterCliOpe::Kubernetes::Pod]
20
21
  def container
21
22
  @container ||= @lambda_container.call
22
23
  end
@@ -26,17 +27,17 @@ module SwarmClusterCliOpe
26
27
  @configs[:service] || @sync_configs.service
27
28
  end
28
29
 
29
-
30
30
  ##
31
31
  # Costruisce i metodi che restituiscono i valori delle configurazioni
32
32
  #
33
33
  # @param [String,Symbol] name -> nome della stringa con cui viene generato il metodo
34
- # @param [String,Symbol] default_env -> nome env default nel caso non sia passato
34
+ # @param [String,Symbol,Array<String,Symbol>] default_env -> nome env default nel caso non sia passato
35
35
  # @param [String,Symbol] configuration_name -> nome della configurazione da utilizzare per estrapolare la configurazione
36
36
  # in automatico viene tenuto conto se cercare per la versione
37
37
  # con _env o senza....precedenza SENZA
38
+ # @param [Block] from_proc -> proc da utilizzare per ricavare il valore
38
39
  # @param [nil,String] default_value se non è estrapolato nessun valore, viene utilizzato il valore di default
39
- def self.define_cfgs(name, default_env:, configuration_name:,default_value:nil)
40
+ def self.define_cfgs(name, default_env:, configuration_name:, default_value: nil, from_proc: nil)
40
41
  configuration_name ||= name
41
42
 
42
43
  define_method(name) do
@@ -44,17 +45,36 @@ module SwarmClusterCliOpe
44
45
 
45
46
  #valore restituito direttamente dalla configurazione
46
47
  if @configs.key?(configuration_name)
47
- value = @configs["#{configuration_name}".to_sym] || default_value
48
- else
49
- env_var = @configs["#{configuration_name}_env".to_sym] || default_env
50
- value = find_env_file_variable(env_var) || default_value
48
+ value = @configs["#{configuration_name}".to_sym]
49
+ end
50
+ # se non abbiamo nulla dalle configurazioni utilizziamo le variabili d'ambiente
51
+ if value.nil?
52
+
53
+ #cerchiamo nella lista delle variabili ambiente possibili, la prima che ha un valore la tengo per buona
54
+ env_vars = []
55
+ env_vars << @configs["#{configuration_name}_env".to_sym]
56
+ env_vars << default_env
57
+ env_vars.flatten!
58
+ env_vars.compact!
59
+
60
+ env_vars.each do |env_var|
61
+ value = find_env_file_variable(env_var)
62
+ break unless value.nil?
63
+ end
64
+
51
65
  end
66
+ # se non abbiamo ancora nulla e abbiamo una proc proseguiamo
67
+ if value.nil? and from_proc
68
+ value = from_proc.call(container)
69
+ end
70
+
71
+ value = value || default_value
72
+
52
73
  self.instance_variable_set("@#{name}", value)
53
74
  end
54
75
 
55
76
  end
56
77
 
57
-
58
78
  private
59
79
 
60
80
  ##
@@ -2,7 +2,6 @@ module SwarmClusterCliOpe
2
2
  module SyncConfigs
3
3
  class PostGres < BaseDatabase
4
4
 
5
-
6
5
  def pull
7
6
  resume('pull')
8
7
 
@@ -13,11 +12,11 @@ module SwarmClusterCliOpe
13
12
  local.container.copy_in(tmp_file, tmp_file)
14
13
 
15
14
  # drop old db and recreate
16
- if Gem::Version.new(local.database_version) <= Gem::Version.new("12")
17
- close_connections_and_drop_cmd(local)
18
- else
19
- raise "DA ANALIZZARE QUANDO LA 13 disponibile....dropdb ha un force come parametro"
20
- end
15
+ # if Gem::Version.new(local.database_version) <= Gem::Version.new("12")
16
+ close_connections_and_drop_cmd(local)
17
+ # else
18
+ # raise "DA ANALIZZARE QUANDO LA 13 disponibile....dropdb ha un force come parametro"
19
+ # end
21
20
 
22
21
  create_cmd(local)
23
22
 
@@ -37,12 +36,8 @@ module SwarmClusterCliOpe
37
36
  dump_cmd(local, tmp_file)
38
37
  remote.container.copy_in(tmp_file, tmp_file)
39
38
 
40
- # drop old db and recreate
41
- if Gem::Version.new(local.database_version) <= Gem::Version.new("12")
42
- close_connections_and_drop_cmd(remote)
43
- else
44
- raise "DA ANALIZZARE QUANDO LA 13 disponibile....dropdb ha un force come parametro"
45
- end
39
+ close_connections_and_drop_cmd(remote)
40
+
46
41
  create_cmd(remote)
47
42
 
48
43
  restore_cmd(remote, tmp_file)
@@ -55,11 +50,14 @@ module SwarmClusterCliOpe
55
50
  # Classe interna che rappresenta le configurazioni del DB
56
51
  class EnvConfigs < BaseDatabase::EnvConfigs
57
52
 
58
- define_cfgs :database_name, default_env: "POSTGRES_DB", configuration_name: :database_name
59
- define_cfgs :username, default_env: "POSTGRES_USER", configuration_name: :pg_user, default_value: 'postgres'
60
- define_cfgs :password, default_env: "POSTGRES_PASSWORD", configuration_name: :pg_password
53
+ define_cfgs :database_name, default_env: ["POSTGRES_DB", "POSTGRESQL_DATABASE"], configuration_name: :database_name
54
+ define_cfgs :username, default_env: ["POSTGRES_USER", "POSTGRESQL_USERNAME"], configuration_name: :pg_user, default_value: 'postgres'
55
+ define_cfgs :password, default_env: ["POSTGRES_PASSWORD", "POSTGRESQL_PASSWORD"], configuration_name: :pg_password
61
56
 
62
- define_cfgs :database_version, default_env: "PG_MAJOR", configuration_name: :pg_version
57
+ define_cfgs :database_version, default_env: "PG_MAJOR", configuration_name: :pg_version,
58
+ from_proc: ->(container) {
59
+ container.exec("postgres -V").raw_result[:stdout].strip.match(/((\d+\.)?(\d+\.)?(\*|\d+))$/)[1] rescue nil
60
+ }
63
61
 
64
62
  end
65
63
 
@@ -125,23 +123,31 @@ module SwarmClusterCliOpe
125
123
 
126
124
  end
127
125
 
128
-
129
126
  # @param [EnvConfigs] config
130
127
  def close_connections_and_drop_cmd(config)
128
+
131
129
  cmd = []
132
- cmd << "PGPASSWORD=\"#{config.password}\""
133
130
 
134
- sql = []
135
- sql << "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '\"'\"'#{config.database_name}'\"'\"' AND pid <> pg_backend_pid();;"
136
- sql << "DROP DATABASE IF EXISTS #{config.database_name};"
131
+ if Gem::Version.new(config.database_version) >= Gem::Version.new("13")
132
+ cmd << "export PGPASSWORD=\"#{config.password}\" &&"
133
+ cmd << 'dropdb --force --if-exists'
134
+ cmd << "-U #{config.username}"
135
+ cmd << config.database_name
137
136
 
138
- cmd << "echo \"#{sql.join(" ")}\" "
139
- cmd << '|'
140
- cmd << 'psql'
141
- cmd << "-U #{config.username}"
142
- cmd << "postgres"
143
- cmd
137
+ else
138
+ cmd << "export PGPASSWORD=\"#{config.password}\" &&"
144
139
 
140
+ sql = []
141
+ sql << "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '\"'\"'#{config.database_name}'\"'\"' AND pid <> pg_backend_pid();;"
142
+ sql << "DROP DATABASE IF EXISTS #{config.database_name};"
143
+
144
+ cmd << "echo \"#{sql.join(" ")}\" "
145
+ cmd << '|'
146
+ cmd << 'psql'
147
+ cmd << "-U #{config.username}"
148
+ cmd << "postgres"
149
+
150
+ end
145
151
  logger.info { "CLOSE CONNECTIONS COMMAND: #{cmd.join(' ')}" }
146
152
  config.container.exec("bash -c '#{cmd.join(' ')}'")
147
153
  end
@@ -153,7 +159,6 @@ module SwarmClusterCliOpe
153
159
  # PGPASSWORD='root' createdb -U root -h 0.0.0.0 -p 32790 development;
154
160
  # PGPASSWORD='root' psql -U root -h 0.0.0.0 -p 32790 -d development < ./cortobio_production_new_2020-09-10-171742.sql
155
161
 
156
-
157
162
  end
158
163
  end
159
164
  end
@@ -1,3 +1,3 @@
1
1
  module SwarmClusterCliOpe
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.5"
3
3
  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.5
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-13 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor