yadecli 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +2 -3
- data/Gemfile +5 -0
- data/Gemfile.lock +44 -2
- data/lib/yadecli/cli/application.rb +19 -4
- data/lib/yadecli/cli/composer.rb +70 -14
- data/lib/yadecli/cli/host.rb +19 -5
- data/lib/yadecli/cli/module.rb +14 -3
- data/lib/yadecli/cli/project.rb +30 -8
- data/lib/yadecli/cli/response/project_start_response.rb +21 -0
- data/lib/yadecli/cli/task.rb +9 -5
- data/lib/yadecli/client/gitlab_client.rb +4 -6
- data/lib/yadecli/command/composer/composer_install_command.rb +166 -0
- data/lib/yadecli/command/composer/composer_list_command.rb +63 -0
- data/lib/yadecli/command/composer/composer_log_command.rb +53 -0
- data/lib/yadecli/command/composer/composer_setup_command.rb +28 -0
- data/lib/yadecli/command/composer/composer_start_command.rb +70 -0
- data/lib/yadecli/command/composer/composer_stop_command.rb +60 -0
- data/lib/yadecli/command/composer/composer_switch_command.rb +51 -0
- data/lib/yadecli/command/composer/composer_uninstall_command.rb +44 -0
- data/lib/yadecli/command/connect_command.rb +29 -0
- data/lib/yadecli/command/host/host_bootstrap_command.rb +132 -0
- data/lib/yadecli/command/host/host_list_command.rb +36 -0
- data/lib/yadecli/command/host/host_provision_command.rb +59 -0
- data/lib/yadecli/command/login_command.rb +26 -0
- data/lib/yadecli/command/module/module_install_command.rb +79 -0
- data/lib/yadecli/command/module/module_list_command.rb +47 -0
- data/lib/yadecli/command/project/project_install_command.rb +58 -0
- data/lib/yadecli/command/project/project_list_command.rb +50 -0
- data/lib/yadecli/command/project/project_setup_command.rb +66 -0
- data/lib/yadecli/command/project/project_start_command.rb +110 -0
- data/lib/yadecli/command/project/project_uninstall_command.rb +44 -0
- data/lib/yadecli/command/task/task_list_command.rb +56 -0
- data/lib/yadecli/io/user_input.rb +1 -1
- data/lib/yadecli/util/cli_util.rb +11 -1
- data/lib/yadecli/util/maven_util.rb +35 -0
- data/lib/yadecli/version.rb +1 -1
- data/lib/yadecli.rb +38 -41
- data/scripts/setup-terminal.sh +1 -1
- data/yadecli.gemspec +6 -2
- metadata +81 -46
- data/lib/.DS_Store +0 -0
- data/lib/yadecli/.DS_Store +0 -0
- data/lib/yadecli/client/authentication_client.rb +0 -24
- data/lib/yadecli/client/base_client.rb +0 -78
- data/lib/yadecli/client/composer_container_client.rb +0 -27
- data/lib/yadecli/client/composer_project_client.rb +0 -27
- data/lib/yadecli/client/composer_service_client.rb +0 -27
- data/lib/yadecli/client/domain_client.rb +0 -23
- data/lib/yadecli/client/host_client.rb +0 -45
- data/lib/yadecli/client/maven_build_step_client.rb +0 -23
- data/lib/yadecli/client/maven_build_task_client.rb +0 -23
- data/lib/yadecli/client/nvm_runtime_client.rb +0 -23
- data/lib/yadecli/client/project_client.rb +0 -28
- data/lib/yadecli/client/project_module_client.rb +0 -35
- data/lib/yadecli/client/pyenv_runtime_client.rb +0 -23
- data/lib/yadecli/client/role_client.rb +0 -23
- data/lib/yadecli/client/rvm_runtime_client.rb +0 -23
- data/lib/yadecli/client/sdk_package_client.rb +0 -28
- data/lib/yadecli/client/vcs_client.rb +0 -23
- data/lib/yadecli/config/app_config.rb +0 -70
- data/lib/yadecli/model/composer_container.rb +0 -19
- data/lib/yadecli/model/composer_project.rb +0 -37
- data/lib/yadecli/model/composer_service.rb +0 -19
- data/lib/yadecli/model/domain.rb +0 -24
- data/lib/yadecli/model/host.rb +0 -24
- data/lib/yadecli/model/ide_type.rb +0 -7
- data/lib/yadecli/model/maven_build_step.rb +0 -19
- data/lib/yadecli/model/maven_build_task.rb +0 -19
- data/lib/yadecli/model/nvm_runtime.rb +0 -18
- data/lib/yadecli/model/project.rb +0 -26
- data/lib/yadecli/model/project_module.rb +0 -29
- data/lib/yadecli/model/pyenv_runtime.rb +0 -18
- data/lib/yadecli/model/role.rb +0 -24
- data/lib/yadecli/model/rvm_runtime.rb +0 -18
- data/lib/yadecli/model/sdk_package.rb +0 -18
- data/lib/yadecli/model/vcs.rb +0 -19
- data/lib/yadecli/service/authentication_service.rb +0 -31
- data/lib/yadecli/service/build_step_service.rb +0 -24
- data/lib/yadecli/service/build_task_service.rb +0 -70
- data/lib/yadecli/service/composer_service.rb +0 -416
- data/lib/yadecli/service/connect_service.rb +0 -19
- data/lib/yadecli/service/host_service.rb +0 -191
- data/lib/yadecli/service/module_service.rb +0 -78
- data/lib/yadecli/service/project_service.rb +0 -205
@@ -1,416 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'colorize'
|
4
|
-
require 'tty-command'
|
5
|
-
require 'tty-prompt'
|
6
|
-
require 'tty-table'
|
7
|
-
require 'fileutils'
|
8
|
-
require 'yaml'
|
9
|
-
require 'uri'
|
10
|
-
require 'dotenv'
|
11
|
-
|
12
|
-
# composer service
|
13
|
-
module Yadecli
|
14
|
-
module Service
|
15
|
-
class ComposerService
|
16
|
-
|
17
|
-
def initialize
|
18
|
-
@composer_project_client = Yadecli::Client::ComposerProjectClient.new
|
19
|
-
@composer_service_client = Yadecli::Client::ComposerServiceClient.new
|
20
|
-
@composer_container_client = Yadecli::Client::ComposerContainerClient.new
|
21
|
-
end
|
22
|
-
|
23
|
-
def setup
|
24
|
-
CliUtil.print_header('YadeCli Composer Setup',
|
25
|
-
['Answer the following questions to setup Composer on this host:', ''])
|
26
|
-
|
27
|
-
AppConfig[:git_api_url] = UserInput.ask(' * Gitlab API Url?', :git_api_url)
|
28
|
-
AppConfig[:git_username] = UserInput.ask(' * Gitlab Username?', :git_username)
|
29
|
-
AppConfig[:git_password] = UserInput.ask(' * Gitlab Password?', :git_password)
|
30
|
-
AppConfig[:git_token] = UserInput.ask(' * Gitlab Api Token?', :git_token)
|
31
|
-
AppConfig[:docker_registry_url] = UserInput.ask(' * Docker Registry Url?', :docker_registry_url)
|
32
|
-
AppConfig[:docker_registry_username] = UserInput.ask(' * Docker Registry Username?', :docker_registry_username)
|
33
|
-
AppConfig[:docker_registry_password] = UserInput.ask(' * Docker Registry Password?', :docker_registry_password)
|
34
|
-
|
35
|
-
AppConfig.write!
|
36
|
-
end
|
37
|
-
|
38
|
-
# list composer projects from gitlab
|
39
|
-
def list
|
40
|
-
CliUtil.print_header('YadeCli Composer List',
|
41
|
-
['This are the available Yade composer projects you can install', ''])
|
42
|
-
|
43
|
-
composer_projects = @composer_project_client.list
|
44
|
-
|
45
|
-
# print table
|
46
|
-
table = TTY::Table.new header: ['Id', 'Name', 'Services', 'Installed', 'Branches', 'Git Url']
|
47
|
-
|
48
|
-
# add as rows to table
|
49
|
-
composer_projects.each do |p|
|
50
|
-
project_id = p.id
|
51
|
-
project_name = p.name
|
52
|
-
project_installed = p.installed?
|
53
|
-
|
54
|
-
composer_services = @composer_service_client.get_by_composer_project_id(project_id)
|
55
|
-
service_names = composer_services.collect(&:name).join(', ')
|
56
|
-
|
57
|
-
gitlab_client = Yadecli::Client::GitlabClient.new
|
58
|
-
|
59
|
-
branches = gitlab_client.get_branch_names(p.git_repo_name)
|
60
|
-
default_branch = gitlab_client.get_default_branch(p.git_repo_name)
|
61
|
-
|
62
|
-
if project_installed
|
63
|
-
current_branch = FileUtil.git_current_branch(p.install_dir)
|
64
|
-
else
|
65
|
-
current_branch = nil
|
66
|
-
end
|
67
|
-
|
68
|
-
branches = branches.map do |b|
|
69
|
-
if b == default_branch && b == current_branch
|
70
|
-
"#{b} (Default, Current)"
|
71
|
-
elsif b == default_branch && b != current_branch
|
72
|
-
"#{b} (Default)"
|
73
|
-
elsif b == current_branch && b != default_branch
|
74
|
-
"#{b} (Current)"
|
75
|
-
else
|
76
|
-
b
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
table << [project_id, project_name, service_names , project_installed, branches.join(', '), p.gitUrl]
|
81
|
-
end
|
82
|
-
|
83
|
-
renderer = TTY::Table::Renderer::ASCII.new(table, padding: [0, 1])
|
84
|
-
puts renderer.render
|
85
|
-
|
86
|
-
puts ''
|
87
|
-
puts 'You can install any of the listed project with the following command:'
|
88
|
-
puts ''
|
89
|
-
puts ' bin/yadecli composer install <name> <branch> [--pull] [--setup] [--clean]'.colorize(:mode => :bold)
|
90
|
-
puts ''
|
91
|
-
end
|
92
|
-
|
93
|
-
# install composer project with name
|
94
|
-
def install(project_name, branch_name = nil, options)
|
95
|
-
CliUtil.print_header('YadeCli Composer Install',
|
96
|
-
["Going to install Yade composer project #{project_name}", ''])
|
97
|
-
|
98
|
-
composer_project = @composer_project_client.get_by_name(project_name)
|
99
|
-
|
100
|
-
# # delete already installed when option --clean given
|
101
|
-
# uninstall(options, true) if options[:clean]
|
102
|
-
|
103
|
-
# # truncate log file
|
104
|
-
# File.open(@log_file, 'w') { |file| file.truncate(0) }
|
105
|
-
|
106
|
-
# check preconditions
|
107
|
-
check_install_preconditions(options)
|
108
|
-
|
109
|
-
# check already installed
|
110
|
-
already_installed = composer_project.installed?
|
111
|
-
|
112
|
-
# ask for branch if not given from commandline
|
113
|
-
branch_name = UserInput.select_branch(composer_project.git_repo_name) if branch_name == nil && !already_installed && !options[:yes]
|
114
|
-
|
115
|
-
if already_installed
|
116
|
-
puts "Composer project #{project_name} already installed.".colorize(color: :blue, mode: :bold)
|
117
|
-
puts ' ↳ Doing a git pull.'
|
118
|
-
|
119
|
-
pull_repository(composer_project, options)
|
120
|
-
else
|
121
|
-
puts "Composer project #{project_name} will be installed.".colorize(color: :blue, mode: :bold)
|
122
|
-
puts ' ↳ Doing a git clone.'
|
123
|
-
|
124
|
-
clone_repository(composer_project, branch_name)
|
125
|
-
end
|
126
|
-
|
127
|
-
puts ''
|
128
|
-
if already_installed
|
129
|
-
puts " Successfully updated '#{composer_project.name}' at #{composer_project.install_dir}."
|
130
|
-
else
|
131
|
-
puts " Successfully installed '#{composer_project.name}' to #{composer_project.install_dir}."
|
132
|
-
end
|
133
|
-
|
134
|
-
composer_services = @composer_service_client.get_by_composer_project_id(composer_project.id)
|
135
|
-
service_names = composer_services.collect(&:name).join(' | ')
|
136
|
-
|
137
|
-
puts ''
|
138
|
-
puts ' Use the following commands to manage the service(s)'
|
139
|
-
puts " Start : bin/yadecli composer start #{composer_project.name} #{service_names}"
|
140
|
-
puts " Stop : bin/yadecli composer stop #{composer_project.name} #{service_names}"
|
141
|
-
|
142
|
-
pull_container(composer_project) if options[:pull]
|
143
|
-
|
144
|
-
# if options[:setup]
|
145
|
-
# if SystemUtil.os == :linux
|
146
|
-
# setup_services
|
147
|
-
# else
|
148
|
-
# puts ''
|
149
|
-
# puts 'WARNING: Setting up services on systems other then linux is not supported.'.colorize(:yellow)
|
150
|
-
# end
|
151
|
-
# end
|
152
|
-
end
|
153
|
-
|
154
|
-
# switch to branch
|
155
|
-
def switch(project_name, target_branch, options)
|
156
|
-
CliUtil.print_header('Composer Switch',
|
157
|
-
["Going to switch branch of composer project #{project_name} to #{target_branch}", ''])
|
158
|
-
|
159
|
-
composer_project = @composer_project_client.get_by_name(project_name)
|
160
|
-
|
161
|
-
message = "Switching to branch #{target_branch}"
|
162
|
-
message += ' and pull changes' if options[:pull]
|
163
|
-
|
164
|
-
print message
|
165
|
-
|
166
|
-
cmdline = "git fetch && git checkout -B #{target_branch}"
|
167
|
-
cmdline += " && git pull origin #{target_branch}" if options[:pull]
|
168
|
-
|
169
|
-
begin
|
170
|
-
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
171
|
-
|
172
|
-
cmd.run(cmdline, chdir: composer_project.install_dir)
|
173
|
-
|
174
|
-
puts ' done'.colorize(:green)
|
175
|
-
rescue TTY::Command::ExitError => e
|
176
|
-
puts ' failed'.colorize(:red)
|
177
|
-
puts e
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
# uninstall a composer project
|
182
|
-
def uninstall(name, options, suppress_header = false)
|
183
|
-
CliUtil.print_header('YadeCli Composer Uninstall',
|
184
|
-
["Going to uninstall composer project #{name}", '']) unless suppress_header
|
185
|
-
|
186
|
-
composer_project = @composer_project_client.get_by_name(name)
|
187
|
-
|
188
|
-
# unless CliUtil.check_root
|
189
|
-
# puts ''
|
190
|
-
# puts 'ERROR: The composer uninstall must run with sudo.'.colorize(:red)
|
191
|
-
# exit 2
|
192
|
-
# end
|
193
|
-
|
194
|
-
answer = false
|
195
|
-
unless options[:yes]
|
196
|
-
prompt = TTY::Prompt.new
|
197
|
-
answer = prompt.yes?("Do you really want to uninstall the #{composer_project.name} composer project?".colorize(:mode => :bold))
|
198
|
-
end
|
199
|
-
|
200
|
-
if options[:yes] || answer
|
201
|
-
FileUtils.rm_rf(composer_project.install_dir)
|
202
|
-
# FileUtils.rm_f("/etc/systemd/system/#{@name}.service")
|
203
|
-
else
|
204
|
-
puts 'There is nothing more I can do for you. Bye.'
|
205
|
-
exit(1)
|
206
|
-
end
|
207
|
-
|
208
|
-
puts ''
|
209
|
-
puts 'Composer project successfully uninstalled'.colorize(:color => :green, :mode => :bold)
|
210
|
-
puts ''
|
211
|
-
end
|
212
|
-
|
213
|
-
# starts the composer service with the given name
|
214
|
-
def start_service(project_name, service_name)
|
215
|
-
CliUtil.print_header('YadeCli Composer Start',
|
216
|
-
['Going to start composer service:',
|
217
|
-
" ↳ Composer Project : #{project_name}",
|
218
|
-
" ↳ Service Name : #{service_name}"])
|
219
|
-
|
220
|
-
begin
|
221
|
-
composer_project = @composer_project_client.get_by_name(project_name)
|
222
|
-
composer_services = @composer_service_client.get_by_composer_project_id(composer_project.id)
|
223
|
-
|
224
|
-
# load project dotenv
|
225
|
-
dotenv_file = "#{composer_project.install_dir}/.env"
|
226
|
-
Dotenv.load(dotenv_file)
|
227
|
-
|
228
|
-
# check required envs are set fom .env file or system environment variables
|
229
|
-
|
230
|
-
composer_service = composer_services.select { |s| s.name == service_name }.first
|
231
|
-
|
232
|
-
composer_service.requiredEnvs&.split(',').each do |re|
|
233
|
-
if ENV[re] == nil
|
234
|
-
puts ''
|
235
|
-
puts "Unable to start service. Required environment variable #{re} is not set.".colorize(:red)
|
236
|
-
puts "Either specify the variable and a value in #{dotenv_file} or as a system environment variable an try to run again.".colorize(:red)
|
237
|
-
|
238
|
-
exit 1
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
composer_containers = @composer_container_client.get_by_composer_service_id(composer_service.id)
|
243
|
-
|
244
|
-
cmdline = "docker-compose up -d #{composer_containers.map(&:name).join(' ')}"
|
245
|
-
|
246
|
-
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
247
|
-
|
248
|
-
puts ''
|
249
|
-
print "Executing command '#{cmdline}'... "
|
250
|
-
|
251
|
-
cmd.run(cmdline, chdir: composer_project.install_dir)
|
252
|
-
|
253
|
-
puts 'done'.colorize(:green)
|
254
|
-
rescue TTY::Command::ExitError => e
|
255
|
-
puts 'failed'.colorize(:red)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
# stops the composer service with the given name
|
260
|
-
def stop_service(project_name, service_name, options)
|
261
|
-
CliUtil.print_header('Composer Service Stop',['Going to stop composer service:',
|
262
|
-
" ↳ Composer Project : #{project_name}",
|
263
|
-
" ↳ Service Name : #{service_name}"])
|
264
|
-
|
265
|
-
begin
|
266
|
-
composer_project = @composer_project_client.get_by_name(project_name)
|
267
|
-
composer_services = @composer_service_client.get_by_composer_project_id(composer_project.id)
|
268
|
-
|
269
|
-
composer_service = composer_services.select { |s| s.name == service_name }.first
|
270
|
-
|
271
|
-
composer_containers = @composer_container_client.get_by_composer_service_id(composer_service.id)
|
272
|
-
|
273
|
-
container_names = composer_containers.map(&:name).join(' ')
|
274
|
-
|
275
|
-
cmdline = "docker-compose stop #{container_names}"
|
276
|
-
cmdline += " && docker-compose rm -f #{container_names}" if options[:rm]
|
277
|
-
cmdline += ' && docker-compose down -v' if options[:down]
|
278
|
-
|
279
|
-
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
280
|
-
|
281
|
-
puts ''
|
282
|
-
print "Executing command '#{cmdline}'... "
|
283
|
-
|
284
|
-
cmd.run(cmdline, chdir: composer_project.install_dir)
|
285
|
-
|
286
|
-
puts 'done'.colorize(:green)
|
287
|
-
rescue TTY::Command::ExitError => e
|
288
|
-
puts 'failed'.colorize(:red)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
# log the containers output of the composer service with the given name
|
293
|
-
def log_service(project_name, service_name, options)
|
294
|
-
CliUtil.print_header('Composer Service Log',["Going to show logs for composer service #{service_name}.",
|
295
|
-
'Hit ctrl + c to stopp when you use the -f option'])
|
296
|
-
|
297
|
-
sleep 1
|
298
|
-
|
299
|
-
composer_project = @composer_project_client.get_by_name(project_name)
|
300
|
-
composer_services = @composer_service_client.get_by_composer_project_id(composer_project.id)
|
301
|
-
|
302
|
-
composer_service = composer_services.select { |s| s.name == service_name }.first
|
303
|
-
|
304
|
-
composer_containers = @composer_container_client.get_by_composer_service_id(composer_service.id)
|
305
|
-
|
306
|
-
container_names = composer_containers.map(&:name).join(' ')
|
307
|
-
|
308
|
-
begin
|
309
|
-
cmdline = 'docker-compose logs'
|
310
|
-
cmdline += ' -f' if options[:follow]
|
311
|
-
cmdline += " #{container_names}"
|
312
|
-
|
313
|
-
cmd = TTY::Command.new(uuid: false)
|
314
|
-
|
315
|
-
cmd.run(cmdline, chdir: install_dir)
|
316
|
-
rescue TTY::Command::ExitError => e
|
317
|
-
puts e
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
private
|
322
|
-
|
323
|
-
# pull container
|
324
|
-
def pull_container(composer_project)
|
325
|
-
# make shure we are logged in to the docker registry
|
326
|
-
docker_login
|
327
|
-
|
328
|
-
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
329
|
-
|
330
|
-
puts ''
|
331
|
-
puts 'Pulling docker images:'.colorize(color: :blue)
|
332
|
-
|
333
|
-
doco = YAML.load_file("#{composer_project.install_dir}/docker-compose.yml")
|
334
|
-
|
335
|
-
has_failed_pulls = false
|
336
|
-
doco['services'].each do |k, v|
|
337
|
-
cmdline = "docker-compose pull #{k}"
|
338
|
-
|
339
|
-
print " ↳ #{cmdline}... "
|
340
|
-
begin
|
341
|
-
cmd.run(cmdline, chdir: composer_project.install_dir)
|
342
|
-
|
343
|
-
puts 'done'.colorize(:green)
|
344
|
-
rescue TTY::Command::ExitError => e
|
345
|
-
puts 'failed'.colorize(:red)
|
346
|
-
has_failed_pulls = true
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
puts ''
|
351
|
-
puts 'Successfully pulled all docker containers.'.colorize(:green) unless has_failed_pulls
|
352
|
-
puts "Failed to pull for at least on container. See log at #{Dir.pwd}/composer.log".colorize(:red) if has_failed_pulls
|
353
|
-
puts ''
|
354
|
-
end
|
355
|
-
|
356
|
-
# docker login
|
357
|
-
def docker_login
|
358
|
-
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
359
|
-
|
360
|
-
cmdline = "docker login #{AppConfig[:docker_registry_url]} -u #{AppConfig[:docker_registry_username]} -p #{AppConfig[:docker_registry_password]}"
|
361
|
-
|
362
|
-
cmd.run(cmdline, only_output_on_error: true)
|
363
|
-
end
|
364
|
-
|
365
|
-
# clone repository
|
366
|
-
def clone_repository(composer_project, branch_name)
|
367
|
-
username = AppConfig[:git_username]
|
368
|
-
password = AppConfig[:git_password]
|
369
|
-
|
370
|
-
git_url = URI.parse(composer_project.gitUrl)
|
371
|
-
|
372
|
-
scheme = git_url.scheme
|
373
|
-
host = git_url.host
|
374
|
-
path = git_url.path
|
375
|
-
|
376
|
-
url_with_auth = "#{scheme}://#{username}:#{password}@#{host}#{path}"
|
377
|
-
|
378
|
-
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
379
|
-
cmdline = "git clone --depth=1 "
|
380
|
-
cmdline += "-b #{branch_name} " if branch_name != nil
|
381
|
-
cmdline += "#{url_with_auth} #{composer_project.install_dir}"
|
382
|
-
|
383
|
-
cmd.run(cmdline, only_output_on_error: true)
|
384
|
-
end
|
385
|
-
|
386
|
-
# pull repository
|
387
|
-
def pull_repository(composer_project, options)
|
388
|
-
if options[:yes]
|
389
|
-
answer = true
|
390
|
-
else
|
391
|
-
puts ''
|
392
|
-
answer = TTY::Prompt.new.yes?('Do you want to pull the changes for the repository?')
|
393
|
-
end
|
394
|
-
|
395
|
-
if answer
|
396
|
-
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
397
|
-
cmd.run('git pull', only_output_on_error: true, chdir: composer_project.install_dir)
|
398
|
-
else
|
399
|
-
puts 'There is nothing more I can do for you. Bye.'
|
400
|
-
exit(1)
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
# check install preconditions
|
405
|
-
def check_install_preconditions(options)
|
406
|
-
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
407
|
-
|
408
|
-
cmd.run('test -x /usr/bin/docker') if SystemUtil.os == 'linux'
|
409
|
-
cmd.run('test -x /usr/local/bin/docker') if SystemUtil.os == 'macosx'
|
410
|
-
|
411
|
-
cmd.run('test -x /usr/local/bin/docker-compose')
|
412
|
-
end
|
413
|
-
|
414
|
-
end
|
415
|
-
end
|
416
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# yadecli cli
|
4
|
-
module Yadecli
|
5
|
-
module Service
|
6
|
-
|
7
|
-
# connect
|
8
|
-
class ConnectService
|
9
|
-
def connect(url)
|
10
|
-
CliUtil.print_header('Yade Connect',
|
11
|
-
["Going to connect to yade backend at #{url}", ''])
|
12
|
-
|
13
|
-
AppConfig[:url] = url
|
14
|
-
|
15
|
-
AppConfig.write!
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,191 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tty-table'
|
4
|
-
require 'net/ssh'
|
5
|
-
require 'fileutils'
|
6
|
-
|
7
|
-
# yadecli cli
|
8
|
-
module Yadecli
|
9
|
-
module Service
|
10
|
-
|
11
|
-
# host service
|
12
|
-
class HostService
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@host_client = Yadecli::Client::HostClient.new
|
16
|
-
@domain_client = Yadecli::Client::DomainClient.new
|
17
|
-
@role_client = Yadecli::Client::RoleClient.new
|
18
|
-
end
|
19
|
-
|
20
|
-
# list the available hosts
|
21
|
-
def list
|
22
|
-
CliUtil.print_header'Yade List Hosts', ['This are the available hosts', '']
|
23
|
-
|
24
|
-
hosts = @host_client.list
|
25
|
-
|
26
|
-
table = TTY::Table.new header: ['Name', 'Domain', 'Role', 'Ip', 'OsType', 'Environment']
|
27
|
-
|
28
|
-
hosts.each do |h|
|
29
|
-
domain_id = h.domainId
|
30
|
-
domain = @domain_client.get(domain_id)
|
31
|
-
|
32
|
-
role_id = h.roleId
|
33
|
-
role = @role_client.get(role_id)
|
34
|
-
|
35
|
-
table << [h.name, domain.name, role.name, h.ip, h.osType, h.environmentType]
|
36
|
-
end
|
37
|
-
|
38
|
-
puts table.render(:ascii, width: 100, resize: true, padding: [0, 1])
|
39
|
-
puts ''
|
40
|
-
end
|
41
|
-
|
42
|
-
# bootstrap a host
|
43
|
-
def bootstrap(host_fqdn, options)
|
44
|
-
CliUtil.print_header'Yade bootstrap Host',
|
45
|
-
["Going to bootstrap Yade host #{host_fqdn}", '']
|
46
|
-
|
47
|
-
master_host = @host_client.master
|
48
|
-
host = @host_client.host_by_fqdn(host_fqdn)
|
49
|
-
|
50
|
-
domain_id = host.domainId
|
51
|
-
domain = @domain_client.get(domain_id)
|
52
|
-
|
53
|
-
role_id = host.roleId
|
54
|
-
role = @role_client.get(role_id)
|
55
|
-
|
56
|
-
username = 'administrator'
|
57
|
-
port = 22
|
58
|
-
|
59
|
-
Net::SSH.start(host.hostName, username, port: port) do |ssh|
|
60
|
-
checkout_dir = "/home/#{username}/.yade"
|
61
|
-
local_repo = "#{checkout_dir}/yade-puppet-bootstrap"
|
62
|
-
|
63
|
-
# clone or update
|
64
|
-
output = ssh.exec!("mkdir -p #{checkout_dir}")
|
65
|
-
puts output if options[:verbose]
|
66
|
-
|
67
|
-
output = ssh.exec!("git clone -b test --depth 1 https://gitlab.com/yadedev/yade-puppet-bootstrap.git #{local_repo} || (cd #{local_repo} ; git pull)")
|
68
|
-
puts output if options[:verbose]
|
69
|
-
|
70
|
-
# setup
|
71
|
-
if options[:setup]
|
72
|
-
output = ssh.exec!("mkdir -p #{local_repo}")
|
73
|
-
puts output if options[:verbose]
|
74
|
-
|
75
|
-
output = ssh.exec!("sudo #{local_repo}/scripts/ubuntu/setup-managed-host.sh #{host.hostName} #{domain.name} #{host.ip}")
|
76
|
-
puts output if options[:verbose]
|
77
|
-
|
78
|
-
output = ssh.exec!("sudo #{local_repo}/scripts/ubuntu/local-bootstrap.sh \"mc nano\"")
|
79
|
-
puts output if options[:verbose]
|
80
|
-
|
81
|
-
output = ssh.exec!("sudo #{local_repo}/scripts/ubuntu/puppet-install.sh")
|
82
|
-
puts output if options[:verbose]
|
83
|
-
|
84
|
-
# noinspection RubyLiteralArrayInspection
|
85
|
-
modules = {
|
86
|
-
'puppetlabs/ntp': '7.1.1',
|
87
|
-
'saz/timezone': '4.1.1',
|
88
|
-
'cjtoolseram/puppetconf': '0.2.7',
|
89
|
-
'puppetlabs/puppet_authorization': '0.4.0',
|
90
|
-
'puppetlabs/puppetdb': '7.0.1',
|
91
|
-
'puppetlabs-puppetserver_gem': '1.0.0',
|
92
|
-
'puppet-r10k': '6.6.1',
|
93
|
-
'abrader-gms': '1.0.3',
|
94
|
-
'theforeman-puppet': '9.1.0',
|
95
|
-
#'theforeman-foreman': '9.2.0'
|
96
|
-
}
|
97
|
-
|
98
|
-
FileUtils.rm_rf 'modules'
|
99
|
-
FileUtils.mkdir_p 'modules'
|
100
|
-
|
101
|
-
modules.each do |mod, version|
|
102
|
-
cmd = "puppet module install --modulepath #{local_repo}/modules --version #{version} #{mod}"
|
103
|
-
|
104
|
-
output = ssh.exec!(cmd)
|
105
|
-
puts output if options[:verbose]
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# provision
|
110
|
-
cmd_a = [
|
111
|
-
'FACTER_vagrant=1',
|
112
|
-
"FACTER_host_ip=#{host.ip}",
|
113
|
-
"FACTER_host_name=#{host.hostName}",
|
114
|
-
"FACTER_host_domain=#{domain.name}",
|
115
|
-
"FACTER_master_ip=#{master_host.ip}",
|
116
|
-
"FACTER_master_host_name=#{master_host.hostName}",
|
117
|
-
"FACTER_role=#{role.name}",
|
118
|
-
"FACTER_datacenter=#{host.datacenter}",
|
119
|
-
"FACTER_zone=#{host.zone}",
|
120
|
-
"FACTER_is_master=#{host.isMaster}",
|
121
|
-
"FACTER_username=#{username}",
|
122
|
-
'sudo --preserve-env puppet apply',
|
123
|
-
"--hiera_config=#{local_repo}/config/hiera.yml",
|
124
|
-
"--modulepath=#{local_repo}/modules:#{local_repo}/dist",
|
125
|
-
"#{local_repo}/environments/production/manifests/default.pp"
|
126
|
-
]
|
127
|
-
|
128
|
-
cmd_line = cmd_a.join(' ')
|
129
|
-
|
130
|
-
puts cmd_line if options[:verbose]
|
131
|
-
|
132
|
-
channel = ssh.open_channel do |ch|
|
133
|
-
ch.exec cmd_line do |ch, success|
|
134
|
-
raise "could not execute command" unless success
|
135
|
-
|
136
|
-
# "on_data" is called when the process writes something to stdout
|
137
|
-
ch.on_data do |c, data|
|
138
|
-
$stdout.print data if options[:verbose]
|
139
|
-
end
|
140
|
-
|
141
|
-
# "on_extended_data" is called when the process writes something to stderr
|
142
|
-
ch.on_extended_data do |c, type, data|
|
143
|
-
$stderr.print data if options[:verbose]
|
144
|
-
end
|
145
|
-
|
146
|
-
ch.on_close { puts "done!" }
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
channel.wait
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# provision a host
|
155
|
-
def provision(host_fqdn, options)
|
156
|
-
CliUtil.print_header'Yade provision Host',
|
157
|
-
["Going to provision Yade host #{host_fqdn}", '']
|
158
|
-
|
159
|
-
host = @host_client.host_by_fqdn(host_fqdn)
|
160
|
-
|
161
|
-
username = 'administrator'
|
162
|
-
port = 22
|
163
|
-
|
164
|
-
Net::SSH.start(host.hostName, username, port: port) do |ssh|
|
165
|
-
# clone or update
|
166
|
-
cmd_line = "sudo puppet agent -t --environment=#{host.environmentType.downcase}"
|
167
|
-
|
168
|
-
channel = ssh.open_channel do |ch|
|
169
|
-
ch.exec cmd_line do |ch, success|
|
170
|
-
raise "could not execute command" unless success
|
171
|
-
|
172
|
-
# "on_data" is called when the process writes something to stdout
|
173
|
-
ch.on_data do |c, data|
|
174
|
-
$stdout.print data if options[:verbose]
|
175
|
-
end
|
176
|
-
|
177
|
-
# "on_extended_data" is called when the process writes something to stderr
|
178
|
-
ch.on_extended_data do |c, type, data|
|
179
|
-
$stderr.print data if options[:verbose]
|
180
|
-
end
|
181
|
-
|
182
|
-
ch.on_close { puts "done!" }
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
channel.wait
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|