takeltau 0.44.14 → 0.44.18

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +106 -97
  3. data/lib/takeltau/default.yml +5 -3
  4. data/lib/takeltau/docker/check/daemon.rb +0 -2
  5. data/lib/takeltau/docker/cli.rb +1 -1
  6. data/lib/takeltau/docker/container/cli.rb +1 -3
  7. data/lib/takeltau/docker/container/lib.rb +2 -4
  8. data/lib/takeltau/docker/container/list.rb +0 -4
  9. data/lib/takeltau/docker/image/cli.rb +1 -1
  10. data/lib/takeltau/docker/image/tag/check.rb +0 -2
  11. data/lib/takeltau/docker/image/tag/cli.rb +1 -1
  12. data/lib/takeltau/git/lib.rb +0 -2
  13. data/lib/takeltau/info/status/bar.rb +0 -2
  14. data/lib/takeltau/info/status/cli.rb +2 -2
  15. data/lib/takeltau/info/status/gopass.rb +0 -2
  16. data/lib/takeltau/info/status/gpg.rb +0 -2
  17. data/lib/takeltau/info/status/ssh.rb +1 -3
  18. data/lib/takeltau/init/packer/cli.rb +1 -1
  19. data/lib/takeltau/init/takelage/cli.rb +1 -3
  20. data/lib/takeltau/lib/config.rb +1 -9
  21. data/lib/takeltau/lib/logging.rb +2 -2
  22. data/lib/takeltau/lib/project.rb +2 -2
  23. data/lib/takeltau/lib/subcmd.rb +2 -0
  24. data/lib/takeltau/lib/system.rb +36 -26
  25. data/lib/takeltau/mutagen/check/cli.rb +2 -2
  26. data/lib/takeltau/mutagen/check/daemon.rb +1 -5
  27. data/lib/takeltau/mutagen/cli.rb +1 -1
  28. data/lib/takeltau/mutagen/socket/cli.rb +2 -2
  29. data/lib/takeltau/mutagen/socket/create.rb +1 -5
  30. data/lib/takeltau/mutagen/socket/docker.rb +1 -3
  31. data/lib/takeltau/self/commands.rb +3 -3
  32. data/lib/takeltau/ship/cli.rb +31 -20
  33. data/lib/takeltau/ship/completion/bash.rb +3 -4
  34. data/lib/takeltau/ship/container/clean.rb +0 -2
  35. data/lib/takeltau/ship/container/cli.rb +14 -0
  36. data/lib/takeltau/ship/container/lib.rb +11 -4
  37. data/lib/takeltau/ship/container/logs.rb +29 -0
  38. data/lib/takeltau/ship/ports/lib.rb +0 -6
  39. data/lib/takeltau/ship/project/cli.rb +37 -8
  40. data/lib/takeltau/ship/project/create.rb +21 -0
  41. data/lib/takeltau/ship/project/start.rb +0 -12
  42. data/lib/takeltau/version +1 -1
  43. data/lib/takeltau.rb +3 -2
  44. metadata +4 -2
  45. data/lib/takeltau/ship/project/logs.rb +0 -27
@@ -40,8 +40,8 @@ module LoggingModule
40
40
  if %w[FATAL ERROR WARN INFO DEBUG].include? loglevel
41
41
  loglevel
42
42
  else
43
- TakeltauLogger.instance.logger.error 'The parameter "loglevel"' \
44
- ' must be one of FATAL, ERROR, WARN, INFO, DEBUG'
43
+ TakeltauLogger.instance.logger.error 'The parameter "loglevel" ' \
44
+ 'must be one of FATAL, ERROR, WARN, INFO, DEBUG'
45
45
  TakeltauLogger.instance.logger.info 'Using loglevel INFO'
46
46
  Logger::INFO
47
47
  end
@@ -39,7 +39,7 @@ module ProjectModule
39
39
  def _project_read_main
40
40
  dir = TakeltauProject.instance.config.active['project_root_dir']
41
41
  main_file = "#{dir}/" \
42
- "#{TakeltauProject.instance.config.active['info_project_main']}"
42
+ "#{TakeltauProject.instance.config.active['info_project_main']}"
43
43
 
44
44
  return {} unless File.exist? main_file
45
45
 
@@ -50,7 +50,7 @@ module ProjectModule
50
50
  def _project_read_private
51
51
  dir = TakeltauProject.instance.config.active['project_root_dir']
52
52
  private_file = "#{dir}/" \
53
- "#{TakeltauProject.instance.config.active['info_project_private']}"
53
+ "#{TakeltauProject.instance.config.active['info_project_private']}"
54
54
 
55
55
  return {} unless File.exist? private_file
56
56
 
@@ -4,6 +4,7 @@
4
4
  class SubCommandBase < Thor
5
5
  # Set the subcommand banner.
6
6
  # rubocop:disable Style/OptionalBooleanParameter
7
+ # rubocop:disable Lint/EmptyBlock
7
8
  def self.banner(command, _namespace = nil, _subcommand = false)
8
9
  subcommand = subcommand_prefix
9
10
  name = $PROGRAM_NAME
@@ -12,6 +13,7 @@ class SubCommandBase < Thor
12
13
  name = File.basename(name)
13
14
  [name, subcommand, command.usage].reject(&:empty?).join(' ')
14
15
  end
16
+ # rubocop:enable Lint/EmptyBlock
15
17
  # rubocop:enable Style/OptionalBooleanParameter
16
18
 
17
19
  # Set the subcommand prefix.
@@ -69,12 +69,14 @@ module SystemModule
69
69
  # Run a command and return the standard output.
70
70
  # @return [String] stdout of command
71
71
  def run(command)
72
- log.debug "Running command \"#{command}\""
73
- stdout_str, stderr_str, status = Open3.capture3 command
74
- log.debug "Command \"#{command}\" has stdout:\n\"\"\"\n#{stdout_str}\"\"\""
75
- log.debug "Command \"#{command}\" has stderr:\n\"\"\"\n#{stderr_str}\"\"\""
76
- log.debug "Command \"#{command}\" has exit status: \"#{status.exitstatus}\""
77
- stdout_str
72
+ Dir.chdir(config.active['project_root_dir']) do
73
+ log.debug "Running command \"#{command}\""
74
+ stdout_str, stderr_str, status = Open3.capture3 command
75
+ log.debug "Command \"#{command}\" has stdout:\n\"\"\"\n#{stdout_str}\"\"\""
76
+ log.debug "Command \"#{command}\" has stderr:\n\"\"\"\n#{stderr_str}\"\"\""
77
+ log.debug "Command \"#{command}\" has exit status: \"#{status.exitstatus}\""
78
+ stdout_str
79
+ end
78
80
  end
79
81
 
80
82
  # Run a command and return the standard output
@@ -82,25 +84,31 @@ module SystemModule
82
84
  # @return [[String, String, Integer]] array of
83
85
  # stdout, stderr, exitstatus of command
84
86
  def run_and_capture(command)
85
- log.debug "Running and capturing command \"#{command}\""
86
- stdout_str, stderr_str, status = Open3.capture3 command
87
- log.debug "Command \"#{command}\" has stdout:\n\"\"\"\n#{stdout_str}\"\"\""
88
- log.debug "Command \"#{command}\" has stderr:\n\"\"\"\n#{stderr_str}\"\"\""
89
- log.debug "Command \"#{command}\" has exit status: \"#{status.exitstatus}\""
90
- [stdout_str, stderr_str, status.exitstatus]
87
+ Dir.chdir(config.active['project_root_dir']) do
88
+ log.debug "Running and capturing command \"#{command}\""
89
+ stdout_str, stderr_str, status = Open3.capture3 command
90
+ log.debug "Command \"#{command}\" has stdout:\n\"\"\"\n#{stdout_str}\"\"\""
91
+ log.debug "Command \"#{command}\" has stderr:\n\"\"\"\n#{stderr_str}\"\"\""
92
+ log.debug "Command \"#{command}\" has exit status: \"#{status.exitstatus}\""
93
+ [stdout_str, stderr_str, status.exitstatus]
94
+ end
91
95
  end
92
96
 
93
97
  # Use Kernel#exec to replace the ruby process with a command.
94
98
  def run_and_exit(command)
95
- log.debug "Running command \"#{command}\" and exiting afterwards"
96
- exec command
99
+ Dir.chdir(config.active['project_root_dir']) do
100
+ log.debug "Running command \"#{command}\" and exiting afterwards"
101
+ exec command
102
+ end
97
103
  end
98
104
 
99
105
  # Use Kernel#fork and Kernel#exec to run a command as a background process.
100
106
  def run_and_fork(command)
101
107
  log.debug "Running command \"#{command}\" as a background process"
102
108
  job = fork do
103
- exec command
109
+ Dir.chdir(config.active['project_root_dir']) do
110
+ exec command
111
+ end
104
112
  end
105
113
  Process.detach(job)
106
114
  end
@@ -108,25 +116,28 @@ module SystemModule
108
116
  # Run a command and return the result.
109
117
  # @return [Boolean] success of command run
110
118
  def try(command)
111
- log.debug "Running command \"#{command}\""
112
- stdout_str, stderr_str, status = Open3.capture3 command
113
- log.debug "Command \"#{command}\" has stdout:\n\"\"\"\n#{stdout_str}\"\"\""
114
- log.debug "Command \"#{command}\" has stderr:\n\"\"\"\n#{stderr_str}\"\"\""
115
- log.debug "Command \"#{command}\" has exit status: \"#{status.exitstatus}\""
116
- status
119
+ Dir.chdir(config.active['project_root_dir']) do
120
+ log.debug "Running command \"#{command}\""
121
+ stdout_str, stderr_str, status = Open3.capture3 command
122
+ log.debug "Command \"#{command}\" has stdout:\n\"\"\"\n#{stdout_str}\"\"\""
123
+ log.debug "Command \"#{command}\" has stderr:\n\"\"\"\n#{stderr_str}\"\"\""
124
+ log.debug "Command \"#{command}\" has exit status: \"#{status.exitstatus}\""
125
+ status
126
+ end
117
127
  end
118
128
 
119
129
  private
120
130
 
121
131
  # Check if command is available
122
- # rubocop:disable Metrics/MethodLength
123
132
  def _command_available?(command)
124
133
  return true if _command_already_checked command
125
134
 
126
135
  log.debug "Check if the command \"#{command}\" is available"
127
136
  begin
128
- status = try command
129
- return false unless status.exitstatus.zero?
137
+ Dir.chdir(config.active['project_root_dir']) do
138
+ status = try command
139
+ return false unless status.exitstatus.zero?
140
+ end
130
141
  rescue Errno::ENOENT => e
131
142
  log.debug 'The command failed with an error.'
132
143
  log.debug "Class of error: #{e.class}"
@@ -135,7 +146,6 @@ module SystemModule
135
146
  end
136
147
  true
137
148
  end
138
- # rubocop:enable Metrics/MethodLength
139
149
 
140
150
  # Check if command has already been checked
141
151
  def _command_already_checked(command)
@@ -181,7 +191,7 @@ module SystemModule
181
191
  rescue StandardError => e
182
192
  log.debug e.class
183
193
  log.debug "Invalid ERB in YAML file \"#{file}\". " \
184
- "#{e.class}: \"#{e.message}\""
194
+ "#{e.class}: \"#{e.message}\""
185
195
  return false
186
196
  end
187
197
  true
@@ -16,12 +16,12 @@ module Takeltau
16
16
  # Initialize mutagen check
17
17
  def initialize(args = [], local_options = {}, configuration = {})
18
18
  # initialize thor parent class
19
- super args, local_options, configuration
19
+ super
20
20
 
21
21
  @workdir = Dir.getwd
22
22
 
23
23
  inside = _docker_container_lib_check_matrjoschka
24
- @hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
24
+ @hostname = inside ? ENV.fetch('HOSTNAME', nil) : _docker_container_lib_hostname
25
25
  @hostlabel = "hostname=#{@hostname}"
26
26
  end
27
27
 
@@ -4,7 +4,6 @@
4
4
  module MutagenCheckDaemon
5
5
  # Backend method for mutagen check daemon.
6
6
  # @return [Boolean] is mutagen available?
7
- # rubocop:disable Metrics/MethodLength
8
7
  # rubocop:disable Metrics/AbcSize
9
8
  def mutagen_check_daemon
10
9
  log.debug 'Check mutagen status'
@@ -36,12 +35,10 @@ module MutagenCheckDaemon
36
35
  true
37
36
  end
38
37
  # rubocop:enable Metrics/AbcSize
39
- # rubocop:enable Metrics/MethodLength
40
38
 
41
39
  private
42
40
 
43
41
  # Check mutagen host connection
44
- # rubocop:disable Metrics/MethodLength
45
42
  def _mutagen_check_daemon_host_connection
46
43
  check_host_connection = format(
47
44
  config.active['cmd_mutagen_check_daemon_host_connection'],
@@ -56,11 +53,10 @@ module MutagenCheckDaemon
56
53
 
57
54
  unless stdout.include? 'Status: Forwarding'
58
55
  log.debug 'The mutagen forward connection to the host ' \
59
- 'is not forwarding connections'
56
+ 'is not forwarding connections'
60
57
  return false
61
58
  end
62
59
 
63
60
  true
64
61
  end
65
- # rubocop:enable Metrics/MethodLength
66
62
  end
@@ -12,7 +12,7 @@ module Takeltau
12
12
 
13
13
  def initialize(args = [], local_options = {}, configuration = {})
14
14
  # initialize thor parent class
15
- super args, local_options, configuration
15
+ super
16
16
 
17
17
  log.debug 'Check docker dameon for mutagen subcommand'
18
18
  exit false unless docker_check_daemon
@@ -25,14 +25,14 @@ module Takeltau
25
25
  # Initialize mutagen socket
26
26
  def initialize(args = [], local_options = {}, configuration = {})
27
27
  # initialize thor parent class
28
- super args, local_options, configuration
28
+ super
29
29
 
30
30
  @docker_repo = config.active['docker_repo']
31
31
  @username = ENV['USER'] || 'noname'
32
32
  @workdir = Dir.getwd
33
33
 
34
34
  inside = _docker_container_lib_check_matrjoschka
35
- @hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
35
+ @hostname = inside ? ENV.fetch('HOSTNAME', nil) : _docker_container_lib_hostname
36
36
 
37
37
  @hostlabel = "hostname=#{@hostname}"
38
38
  @takellabel = config.active['mutagen_socket_takelage_label']
@@ -3,12 +3,11 @@
3
3
  # tau mutagen socket create
4
4
  module MutagenSocketCreate
5
5
  # Backend method for mutagen socket create.
6
- # rubocop:disable Metrics/MethodLength
7
6
  def mutagen_socket_create(name, containersock, hostsock)
8
7
  # See DockerContainerLib::_docker_container_lib_hostname
9
8
  socketname = "#{@hostname[-11..]}-#{name}"
10
9
  log.debug "Create the mutagen socket \"#{socketname}\" in the container " \
11
- "at \"#{containersock}\" pointing to the host at \"#{hostsock}\""
10
+ "at \"#{containersock}\" pointing to the host at \"#{hostsock}\""
12
11
 
13
12
  return false if mutagen_socket_check socketname
14
13
 
@@ -22,12 +21,10 @@ module MutagenSocketCreate
22
21
  log.debug "Created the mutagen socket \"#{socketname}\""
23
22
  true
24
23
  end
25
- # rubocop:enable Metrics/MethodLength
26
24
 
27
25
  private
28
26
 
29
27
  # Get git branch.
30
- # rubocop:disable Metrics/MethodLength
31
28
  def _mutagen_socket_create_socket(socketname, containersock, hostsock)
32
29
  cmd_create_socket = format(
33
30
  config.active['cmd_mutagen_forward_socket_create'],
@@ -41,5 +38,4 @@ module MutagenSocketCreate
41
38
  )
42
39
  run cmd_create_socket
43
40
  end
44
- # rubocop:enable Metrics/MethodLength
45
41
  end
@@ -3,12 +3,11 @@
3
3
  # tau mutagen socket docker
4
4
  module MutagenSocketDocker
5
5
  # Backend method for mutagen socket docker.
6
- # rubocop:disable Metrics/MethodLength
7
6
  def mutagen_socket_docker(hostsock)
8
7
  # See DockerContainerLib::_docker_container_lib_hostname
9
8
  socketname = "#{@hostname[-11..]}-docker"
10
9
  log.debug "Create the mutagen docker socket \"#{socketname}\" in the container " \
11
- "pointing to the host at \"#{hostsock}\""
10
+ "pointing to the host at \"#{hostsock}\""
12
11
 
13
12
  return false if mutagen_socket_check socketname
14
13
 
@@ -22,7 +21,6 @@ module MutagenSocketDocker
22
21
  log.debug "Created the mutagen docker socket \"#{socketname}\""
23
22
  true
24
23
  end
25
- # rubocop:enable Metrics/MethodLength
26
24
 
27
25
  private
28
26
 
@@ -16,9 +16,9 @@ module SelfCommands
16
16
 
17
17
  # use thor list to get the list of commands and subcommands
18
18
  cmd_thor_list = "bash -c '" \
19
- "cd #{thorfile_dir} && " \
20
- 'thor list' \
21
- "'"
19
+ "cd #{thorfile_dir} && " \
20
+ 'thor list' \
21
+ "'"
22
22
 
23
23
  # call thor list command
24
24
  `#{cmd_thor_list}`
@@ -11,7 +11,7 @@ module Takeltau
11
11
 
12
12
  def initialize(args = [], local_options = {}, configuration = {})
13
13
  # initialize thor parent class
14
- super args, local_options, configuration
14
+ super
15
15
 
16
16
  log.debug 'Check docker dameon for ship subcommand'
17
17
  exit false unless docker_check_daemon 'cmd_ship_docker', 'cmd_ship_docker_check'
@@ -53,7 +53,7 @@ module Takeltau
53
53
  LONGDESC
54
54
  # ship command: {Takeltau::ShipContainer#command}
55
55
  def command(*args)
56
- Takeltau::ShipContainer.new.command args
56
+ Takeltau::ShipContainer.new.command(*args)
57
57
  end
58
58
 
59
59
  desc 'list', 'List takelships'
@@ -66,14 +66,24 @@ module Takeltau
66
66
  Takeltau::ShipContainer.new.list
67
67
  end
68
68
 
69
- desc 'logs [PROJECT]', 'Follow logs of takelship [PROJECT]'
69
+ desc 'login', 'Log in to a takelship'
70
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
71
+ Log in to a takelship as root.
72
+ Alias for ship container login.
73
+ LONGDESC
74
+ # ship login: {Takeltau::ShipContainer#login}
75
+ def login
76
+ Takeltau::ShipContainer.new.login
77
+ end
78
+
79
+ desc 'logs [OPTIONS]', 'Print the takelship logs'
70
80
  long_desc <<-LONGDESC.gsub("\n", "\x5")
71
- Follow logs of project [PROJECT] in a takelship project.
72
- Alias for ship project logs.
81
+ Print the takelship logs.
82
+ Alias for ship container logs.
73
83
  LONGDESC
74
- # ship logs: {Takeltau::ShipProject#logs}
75
- def logs(project = 'default')
76
- Takeltau::ShipProject.new.logs(project)
84
+ # ship logs: {Takeltau::ShipContainer#logs}
85
+ def logs(*args)
86
+ Takeltau::ShipContainer.new.logs(*args)
77
87
  end
78
88
 
79
89
  desc 'ls', 'List takelships'
@@ -86,16 +96,6 @@ module Takeltau
86
96
  Takeltau::ShipContainer.new.list
87
97
  end
88
98
 
89
- desc 'login', 'Log in to a takelship'
90
- long_desc <<-LONGDESC.gsub("\n", "\x5")
91
- Log in to a takelship as root.
92
- Alias for ship container login.
93
- LONGDESC
94
- # ship login: {Takeltau::ShipContainer#login}
95
- def login
96
- Takeltau::ShipContainer.new.login
97
- end
98
-
99
99
  desc 'podman [COMMAND]', 'Run a podman [COMMAND] in a takelship'
100
100
  long_desc <<-LONGDESC.gsub("\n", "\x5")
101
101
  Run a podman command as user podman in a takelship container.
@@ -103,7 +103,18 @@ module Takeltau
103
103
  LONGDESC
104
104
  # ship podman: {Takeltau::ShipContainer#podman}
105
105
  def podman(*args)
106
- Takeltau::ShipContainer.new.podman args
106
+ Takeltau::ShipContainer.new.podman(*args)
107
+ end
108
+
109
+ desc 'restart [PROJECT]', 'Restart takelship [PROJECT]'
110
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
111
+ Restart a takelship and run project [PROJECT] in it.
112
+ Alias for ship project restart which is an
113
+ alias for ship project stop and then ship project start.
114
+ LONGDESC
115
+ # ship restart: {Takeltau::ShipProject#restart}
116
+ def restart(project = 'default')
117
+ Takeltau::ShipProject.new.restart project
107
118
  end
108
119
 
109
120
  desc 'sudo [COMMAND]', 'Run a sudo [COMMAND] in a takelship'
@@ -113,7 +124,7 @@ module Takeltau
113
124
  LONGDESC
114
125
  # ship sudo: {Takeltau::ShipContainer#sudo}
115
126
  def sudo(*args)
116
- Takeltau::ShipContainer.new.sudo args
127
+ Takeltau::ShipContainer.new.sudo(*args)
117
128
  end
118
129
 
119
130
  desc 'start [PROJECT]', 'Start takelship [PROJECT]'
@@ -27,9 +27,8 @@ module ShipCompletionBash
27
27
  functions =
28
28
  completion
29
29
  .split(/_tau[^_]*/)
30
- .select { |f| f =~ /_ship/ }
31
- .reject { |f| f =~ /_ship\n/ }
32
- .reject { |f| f.include? 'help ()' }
33
- functions.join('')
30
+ .grep(/_ship/)
31
+ .grep_v(/_ship\n/)
32
+ functions.join
34
33
  end
35
34
  end
@@ -10,7 +10,6 @@ module ShipContainerClean
10
10
  private
11
11
 
12
12
  # Remove all takelship containers
13
- # rubocop:disable Metrics/MethodLength
14
13
  def _ship_container_clean_remove_containers
15
14
  ship_name = config.active['ship_name']
16
15
  log.debug "Getting all #{ship_name} containers"
@@ -26,5 +25,4 @@ module ShipContainerClean
26
25
  _ship_container_lib_remove_container container
27
26
  end
28
27
  end
29
- # rubocop:enable Metrics/MethodLength
30
28
  end
@@ -13,6 +13,7 @@ module Takeltau
13
13
  include ShipContainerClean
14
14
  include ShipContainerList
15
15
  include ShipContainerLogin
16
+ include ShipContainerLogs
16
17
  include ShipContainerPodman
17
18
  include ShipContainerCommand
18
19
  include ShipContainerSudo
@@ -66,6 +67,19 @@ module Takeltau
66
67
  ship_container_login
67
68
  end
68
69
 
70
+ #
71
+ # ship container logs
72
+ #
73
+ desc 'logs [OPTIONS]', 'Print the takelship logs'
74
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
75
+ Print the takelship logs.
76
+ Accepts docker logs options.
77
+ See: docker help logs
78
+ LONGDESC
79
+ def logs(*args)
80
+ ship_container_logs args
81
+ end
82
+
69
83
  #
70
84
  # ship container podman
71
85
  #
@@ -5,10 +5,13 @@ module ShipContainerLib
5
5
  private
6
6
 
7
7
  # Run nonprivileged docker command
8
- def _ship_container_lib_docker_nonprivileged(command)
8
+ def _ship_container_lib_docker_nonprivileged(command, args = '')
9
+ args_nonprivileged = config.active['ship_run_args_nonprivileged']
10
+ args = "#{args} #{args_nonprivileged}" if config.active['ship_run_args_nonprivileged']
9
11
  cmd_docker_run_command = format(
10
12
  config.active['cmd_ship_project_start_docker_run_nonprivileged'],
11
13
  ship_docker: config.active['cmd_ship_docker'],
14
+ ship_run_args_nonprivileged: args,
12
15
  image: _ship_container_lib_image,
13
16
  command: command
14
17
  )
@@ -18,7 +21,9 @@ module ShipContainerLib
18
21
  # Run privileged docker command
19
22
  # rubocop:disable Metrics/AbcSize
20
23
  # rubocop:disable Metrics/MethodLength
21
- def _ship_container_lib_docker_privileged(ports, command)
24
+ def _ship_container_lib_docker_privileged(ports, command, args = '')
25
+ args_privileged = config.active['ship_run_args_privileged']
26
+ args = "#{args} #{args_privileged}" if config.active['ship_run_args_privileged']
22
27
  ship_data_dir = config.active['ship_data_dir']
23
28
  ship_env = [config.active['ship_env']]
24
29
  ports.each do |key, port|
@@ -33,7 +38,9 @@ module ShipContainerLib
33
38
  ship_hostname: _ship_container_lib_ship_hostname,
34
39
  ship_env: ship_env.join(' '),
35
40
  ports: ports,
41
+ project_root_dir: config.active['project_root_dir'],
36
42
  ship_data_dir: ship_data_dir,
43
+ ship_run_args_privileged: args,
37
44
  image: _ship_container_lib_image,
38
45
  command: command
39
46
  )
@@ -66,7 +73,7 @@ module ShipContainerLib
66
73
  # Create unique docker hostname
67
74
  def _ship_container_lib_ship_hostname
68
75
  ship_name = config.active['ship_name']
69
- workdir = Dir.getwd
76
+ workdir = config.active['project_root_dir']
70
77
  unique_name = "#{ship_name}_#{workdir}"
71
78
  digest = Digest::SHA256.bubblebabble unique_name
72
79
  unique = digest[0..10]
@@ -110,7 +117,7 @@ module ShipContainerLib
110
117
  def _ship_container_lib_get_mounted_dir
111
118
  ship_hostname = _ship_container_lib_ship_hostname
112
119
  log.debug 'Getting mounted directory from ' \
113
- "takelship container \"#{ship_hostname}\""
120
+ "takelship container \"#{ship_hostname}\""
114
121
 
115
122
  cmd_get_mounted_dir = format(
116
123
  config.active['cmd_docker_container_get_mounted_dir'],
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # tau ship container logs
4
+ module ShipContainerLogs
5
+ # Start a takelship
6
+ def ship_container_logs(args)
7
+ ship_hostname = _ship_container_lib_ship_hostname
8
+
9
+ unless ship_container_check_existing
10
+ say "The takelship #{ship_hostname} is not sailing."
11
+ return false
12
+ end
13
+
14
+ log.debug 'Printing docker logs'
15
+ _ship_container_logs_print(ship_hostname, args.join(' '))
16
+ end
17
+
18
+ private
19
+
20
+ def _ship_container_logs_print(ship_hostname, args)
21
+ cmd_follow_logs = format(
22
+ config.active['cmd_ship_container_logs'],
23
+ ship_docker: config.active['cmd_ship_docker'],
24
+ ship_hostname: ship_hostname,
25
+ args: args
26
+ )
27
+ run_and_exit cmd_follow_logs
28
+ end
29
+ end
@@ -5,7 +5,6 @@ module ShipPortsLib
5
5
  private
6
6
 
7
7
  # get the ports of a takelship
8
- # rubocop:disable Metrics/MethodLength
9
8
  def _ship_ports_lib_get_ports(takelship, takelproject)
10
9
  ports = _ship_ports_lib_get_ports_docker(takelship)
11
10
  takelship['projects'].each do |project|
@@ -22,7 +21,6 @@ module ShipPortsLib
22
21
  end
23
22
  ports
24
23
  end
25
- # rubocop:enable Metrics/MethodLength
26
24
 
27
25
  # write ports to project takelage.yml
28
26
  def _ship_ports_lib_write_ports(ports, project)
@@ -48,7 +46,6 @@ module ShipPortsLib
48
46
 
49
47
  # map the podman socket port (aka "DOCKER_HOST")
50
48
  # returns a hash unlike the get_port method
51
- # rubocop:disable Metrics/MethodLength
52
49
  def _ship_ports_lib_get_ports_docker(takelship)
53
50
  takel_docker = takelship['docker_host']
54
51
  docker_key = "ship_ports_docker_host_docker_#{takel_docker}"
@@ -64,10 +61,8 @@ module ShipPortsLib
64
61
  }
65
62
  }
66
63
  end
67
- # rubocop:enable Metrics/MethodLength
68
64
 
69
65
  # map a takelship port
70
- # rubocop:disable Metrics/MethodLength
71
66
  def _ship_ports_lib_get_port(key, port, service)
72
67
  localhost = _ship_ports_lib_get_localhost_port key, port['port']
73
68
  unless port.key?('description')
@@ -87,7 +82,6 @@ module ShipPortsLib
87
82
  'description' => port['description']
88
83
  }
89
84
  end
90
- # rubocop:enable Metrics/MethodLength
91
85
 
92
86
  # get new port on localhost for takelport
93
87
  def _ship_ports_lib_get_localhost_port(key, port)
@@ -13,12 +13,25 @@ module Takeltau
13
13
  include ShipContainerStop
14
14
  include ShipInfoLib
15
15
  include ShipPortsLib
16
+ include ShipProjectCreate
16
17
  include ShipProjectList
17
- include ShipProjectLogs
18
18
  include ShipProjectStart
19
19
 
20
20
  #
21
- # ship container list
21
+ # ship project dump
22
+ #
23
+ desc 'create [PROJECT]', 'Create a takelship [PROJECT]'
24
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
25
+ Create a takelship [PROJECT].
26
+ This command will create the configuration files of a takelship [PROJECT].
27
+ It will neither run the [PROJECT] in a takelship nor create service data.
28
+ LONGDESC
29
+ def create(project = 'default')
30
+ say ship_project_create project
31
+ end
32
+
33
+ #
34
+ # ship project list
22
35
  #
23
36
  desc 'list', 'List takelship projects'
24
37
  long_desc <<-LONGDESC.gsub("\n", "\x5")
@@ -29,18 +42,21 @@ module Takeltau
29
42
  end
30
43
 
31
44
  #
32
- # ship container logs
45
+ # ship project restart
33
46
  #
34
- desc 'logs [PROJECT]', 'Follow logs of [PROJECT]'
47
+ desc 'restart [PROJECT]', 'Restart takelship [PROJECT]'
35
48
  long_desc <<-LONGDESC.gsub("\n", "\x5")
36
- Follow logs of project [PROJECT] in a takelship project.
49
+ Restart a takelship and run the project [PROJECT] in it.
50
+ Alias for ship project stop and ship project start.
37
51
  LONGDESC
38
- def logs(project = 'default')
39
- ship_project_logs project
52
+ # ship restart: {Takeltau::ShipProject#restart}
53
+ def restart(project = 'default')
54
+ Takeltau::ShipProject.new.stop
55
+ Takeltau::ShipProject.new.start project
40
56
  end
41
57
 
42
58
  #
43
- # ship container start
59
+ # ship project start
44
60
  #
45
61
  desc 'start [PROJECT]', 'Start takelship [PROJECT]'
46
62
  long_desc <<-LONGDESC.gsub("\n", "\x5")
@@ -61,5 +77,18 @@ module Takeltau
61
77
  def stop
62
78
  say ship_container_stop
63
79
  end
80
+
81
+ #
82
+ # ship project update
83
+ #
84
+ desc 'update [PROJECT]', 'Update a takelship [PROJECT]'
85
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
86
+ Update a takelship [PROJECT].
87
+ This command will update the configuration files of a takelship [PROJECT].
88
+ It will neither run the [PROJECT] in a takelship nor touch the service data.
89
+ LONGDESC
90
+ def update(project = 'default')
91
+ say ship_project_create project, 'Updated'
92
+ end
64
93
  end
65
94
  end