takelage 0.28.7 → 0.28.26

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: d13748db4d561a884f90dcf21e4f43296fcaec2377ebb602b0407139d6218986
4
- data.tar.gz: e0c2075cc8fab7ab3057477baaee7fe2aa3f4304c139b38f1ab6432f9adf4366
3
+ metadata.gz: c5b24cafbddb28d0bc465c9b464a02d6d08c14639dfe5c58cc891828680143dc
4
+ data.tar.gz: 7743c6e2f629e35838820ab439c72a6b659c674f852fe7a114e9016d771011af
5
5
  SHA512:
6
- metadata.gz: 1b7ac8428fa4c5f4278f58c9ae26a77656c967503d7a10c8bfe892aca274d32129cfb81a40a2434126940b52f0756a93a6c6c01a6a18ba21c98306f8eda1ab92
7
- data.tar.gz: ae774fe3212f1712097c6476f186e1cdff6ee63f043aeec7d4b29b4862e75ecf3c4251cac00ecb83677dbaf71e01dc7ebb202947f5c6a7a704792ac93865e4da
6
+ metadata.gz: 4135b0857fbbff72ce697309745232b1433352cd7b3a884486044aa761b9a66f15b29ab896a5406cabab35c1b8c941fed2c91c0d2344bd604cbde99ef22fbb5f
7
+ data.tar.gz: 773c9fdfa99690acc118f837ddbdc343e51f1962f05bd740c312ae7b125713734eb1b591c2f411499f76728e009bc4b175ec128747319a53b614ff88b5c7e071
data/README.md CHANGED
@@ -78,7 +78,6 @@ tau [bit scope list](features/cucumber/features/bit/bit.scope.list.feature) | Li
78
78
  tau [bit scope new](features/cucumber/features/bit/bit.scope.new.feature) [SCOPE] | Init a new bit [SCOPE]
79
79
  tau [completion bash](features/cucumber/features/completion/completion.bash.feature) | Print bash completion code
80
80
  tau [docker check daemon](features/cucumber/features/docker/docker.check.daemon.feature) | Check if docker daemon is running
81
- tau [docker check socat](features/cucumber/features/docker/docker.check.socat.feature) | Check if socat command is available
82
81
  tau [docker container check existing](features/cucumber/features/docker/docker.container.check.existing.feature) [CONTAINER] | Check if docker [CONTAINER] is existing
83
82
  tau [docker container check network](features/cucumber/features/docker/docker.container.check.network.feature) [NETWORK] | Check if docker [NETWORK] is existing
84
83
  tau [docker container check orphaned](features/cucumber/features/docker/docker.container.check.orphaned.feature) [CONTAINER] | Check if docker [CONTAINER] is orphaned
@@ -106,10 +105,13 @@ tau [info status bar](features/cucumber/features/info/info.status.bar.feature) |
106
105
  tau [info status git](features/cucumber/features/info/info.status.git.feature) | Check git status
107
106
  tau [info status gopass](features/cucumber/features/info/info.status.gopass.feature) | Check gopass status
108
107
  tau [info status gpg](features/cucumber/features/info/info.status.gpg.feature) | Check gpg status
108
+ tau [info status mutagen](features/cucumber/features/info/info.status.mutagen.feature) | Check mutagen status
109
109
  tau [info status ssh](features/cucumber/features/info/info.status.ssh.feature) | Check ssh status
110
+ tau [mutagen check daemon](features/cucumber/features/mutagen/mutagen.check.daemon.feature)) | Check if mutagen host conenction is available
110
111
  tau [mutagen socket check](features/cucumber/features/mutagen/mutagen.socket.check.feature) [SOCKET] | Check if mutagen [SOCKET] exists
111
112
  tau [mutagen socket create](features/cucumber/features/mutagen/mutagen.socket.create.feature) [IN] [OUT] | Create a mutagen socket from [IN] to [OUT] of the container
112
113
  tau [mutagen socket list](features/cucumber/features/mutagen/mutagen.socket.list.feature) | List mutagen sockets
114
+ tau [mutagen socket tidy](features/cucumber/features/mutagen/mutagen.socket.tidy.feature) | Remove mutagen daemon files
113
115
  tau [mutagen socket terminate](features/cucumber/features/mutagen/mutagen.socket.terminate.feature) | Terminate a mutagen socket
114
116
  tau [self config active](features/cucumber/features/self/self.config.active.feature) | Print active takelage configuration
115
117
  tau [self config default](features/cucumber/features/self/self.config.default.feature) | Print takelage default configuration
data/lib/takelage.rb CHANGED
@@ -44,8 +44,11 @@ require_relative 'takelage/bit/require/import'
44
44
  require_relative 'takelage/bit/require/cli'
45
45
  require_relative 'takelage/bit/cli'
46
46
  require_relative 'takelage/completion/cli'
47
+ require_relative 'takelage/mutagen/check/daemon'
48
+ require_relative 'takelage/mutagen/socket/create'
49
+ require_relative 'takelage/mutagen/socket/terminate'
50
+ require_relative 'takelage/mutagen/socket/tidy'
47
51
  require_relative 'takelage/docker/check/daemon'
48
- require_relative 'takelage/docker/check/socat'
49
52
  require_relative 'takelage/docker/check/cli'
50
53
  require_relative 'takelage/docker/socket/lib'
51
54
  require_relative 'takelage/docker/socket/host'
@@ -59,8 +62,6 @@ require_relative 'takelage/docker/image/tag/check'
59
62
  require_relative 'takelage/docker/image/tag/cli'
60
63
  require_relative 'takelage/docker/image/update'
61
64
  require_relative 'takelage/docker/image/cli'
62
- require_relative 'takelage/mutagen/socket/create'
63
- require_relative 'takelage/mutagen/socket/terminate'
64
65
  require_relative 'takelage/docker/container/check/existing'
65
66
  require_relative 'takelage/docker/container/check/network'
66
67
  require_relative 'takelage/docker/container/check/orphaned'
@@ -73,6 +74,11 @@ require_relative 'takelage/docker/container/clean'
73
74
  require_relative 'takelage/docker/container/prune'
74
75
  require_relative 'takelage/docker/container/cli'
75
76
  require_relative 'takelage/docker/cli'
77
+ require_relative 'takelage/mutagen/check/cli'
78
+ require_relative 'takelage/mutagen/socket/check'
79
+ require_relative 'takelage/mutagen/socket/list'
80
+ require_relative 'takelage/mutagen/socket/cli'
81
+ require_relative 'takelage/mutagen/cli'
76
82
  require_relative 'takelage/info/status/lib'
77
83
  require_relative 'takelage/info/status/git'
78
84
  require_relative 'takelage/info/status/gopass'
@@ -82,10 +88,6 @@ require_relative 'takelage/info/status/bar'
82
88
  require_relative 'takelage/info/status/cli'
83
89
  require_relative 'takelage/info/project/cli'
84
90
  require_relative 'takelage/info/cli'
85
- require_relative 'takelage/mutagen/socket/check'
86
- require_relative 'takelage/mutagen/socket/list'
87
- require_relative 'takelage/mutagen/socket/cli'
88
- require_relative 'takelage/mutagen/cli'
89
91
  require_relative 'takelage/self/config/cli'
90
92
  require_relative 'takelage/self/list'
91
93
  require_relative 'takelage/self/cli'
@@ -30,7 +30,6 @@ cmd_bit_scope_list_find_scopes: 'find -L %{root} -name scope.json'
30
30
  cmd_bit_scope_new_bit_init: 'mkdir -p %{root}/%{scope} && cd %{root}/%{scope} && bit init --bare'
31
31
  cmd_bit_scope_remove_scope: 'rm --force --recursive %{root}/%{scope}'
32
32
  cmd_docker_check_daemon_docker_info: 'docker info'
33
- cmd_docker_check_socat_which_socat: 'which socat'
34
33
  cmd_docker_container_check_existing_docker_ps: 'docker ps --filter name=^%{container}$ --quiet'
35
34
  cmd_docker_container_check_network_docker_network: 'docker network ls --quiet --filter name=^%{network}$'
36
35
  cmd_docker_container_check_orphaned_docker_exec: 'docker exec --interactive %{container} ps a'
@@ -66,6 +65,8 @@ cmd_info_status_gopass_root_store: 'gopass config | grep "path" | cut -d " " -f
66
65
  cmd_info_status_gpg_agent: 'gpg-connect-agent /bye'
67
66
  cmd_info_status_gpg_keys: 'gpg --list-keys'
68
67
  cmd_info_status_ssh_keys: 'ssh-add -l'
68
+ cmd_mutagen_check_daemon_host_connection: 'mutagen forward list --label-selector="%{hostlabel}"'
69
+ cmd_mutagen_check_daemon_version: 'mutagen version'
69
70
  cmd_mutagen_forward_socket_create: 'mutagen forward create --name=%{socketname} --label=%{hostlabel} --label=%{takellabel} docker://%{username}@%{container}:unix:%{containersock} unix:%{hostsock}'
70
71
  cmd_mutagen_forward_socket_check: 'mutagen forward list %{socketname}'
71
72
  cmd_mutagen_forward_socket_terminate: 'mutagen forward terminate %{socketname}'
@@ -85,3 +86,5 @@ docker_user: 'takelage'
85
86
  git_main_branch: 'main'
86
87
  info_project_main: 'project.yml'
87
88
  info_project_private: 'private/project.yml'
89
+ mutagen_socket_path: '~/.mutagen/daemon/daemon.sock'
90
+ mutagen_socket_takelage_label: 'type=takelage-socket'
@@ -7,7 +7,6 @@ module Takelage
7
7
  include SystemModule
8
8
  include ConfigModule
9
9
  include DockerCheckDaemon
10
- include DockerCheckSocat
11
10
 
12
11
  #
13
12
  # docker check daemon
@@ -20,17 +19,5 @@ module Takelage
20
19
  def daemon
21
20
  exit docker_check_daemon
22
21
  end
23
-
24
- #
25
- # docker check socat
26
- #
27
- desc 'socat', 'Check if socat command is available'
28
- long_desc <<-LONGDESC.gsub("\n", "\x5")
29
- Check if socat command is available
30
- LONGDESC
31
- # Check if socat command is available.
32
- def socat
33
- exit docker_check_socat
34
- end
35
22
  end
36
23
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # takelage docker check running
3
+ # takelage docker check daemon
4
4
  module DockerCheckDaemon
5
- # Backend method for docker check running.
5
+ # Backend method for docker check daemon.
6
6
  # @return [Boolean] is the docker daemon running?
7
+ # rubocop:disable Metrics/MethodLength
7
8
  def docker_check_daemon
8
9
  return true if @docker_daemon_running
9
10
 
11
+ return false unless command_available? 'docker'
12
+
10
13
  log.debug 'Check if the docker daemon is running'
11
14
 
12
15
  status = try config.active['cmd_docker_check_daemon_docker_info']
@@ -20,4 +23,5 @@ module DockerCheckDaemon
20
23
  @docker_daemon_running = true
21
24
  true
22
25
  end
26
+ # rubocop:enable Metrics/MethodLength
23
27
  end
@@ -7,7 +7,6 @@ module Takelage
7
7
  include SystemModule
8
8
  include ConfigModule
9
9
  include DockerCheckDaemon
10
- include DockerCheckSocat
11
10
  include DockerContainerCheckExisting
12
11
  include DockerContainerCheckNetwork
13
12
  include DockerContainerCheckOrphaned
@@ -10,9 +10,9 @@ module DockerContainerClean
10
10
 
11
11
  return false if _docker_container_clean_harakiri?
12
12
 
13
+ mutagen_socket_terminate "--label-selector='#{@takellabel}'"
13
14
  networks = _docker_container_clean_kill_existing_containers
14
15
  _docker_container_lib_remove_networks networks
15
- mutagen_socket_terminate "--label-selector='#{@takellabel}'"
16
16
  end
17
17
 
18
18
  private
@@ -7,7 +7,6 @@ module Takelage
7
7
  include SystemModule
8
8
  include ConfigModule
9
9
  include DockerCheckDaemon
10
- include DockerCheckSocat
11
10
  include DockerContainerCheckExisting
12
11
  include DockerContainerCheckNetwork
13
12
  include DockerContainerCheckOrphaned
@@ -24,6 +23,7 @@ module Takelage
24
23
  include DockerSocketHost
25
24
  include DockerSocketScheme
26
25
  include DockerSocketStart
26
+ include MutagenCheckDaemon
27
27
  include MutagenSocketCreate
28
28
  include MutagenSocketTerminate
29
29
 
@@ -42,9 +42,10 @@ module Takelage
42
42
  @workdir = Dir.getwd
43
43
  @hostname = _docker_container_lib_hostname
44
44
  @hostlabel = "hostname=#{@hostname}"
45
- @takellabel = 'type=takelage-socket'
45
+ @takellabel = config.active['mutagen_socket_takelage_label']
46
46
  @socket_host = docker_socket_host
47
47
  @sockets = docker_socket_scheme
48
+ @mutagensock = config.active['mutagen_socket_path']
48
49
  end
49
50
  # rubocop:enable Metrics/MethodLength
50
51
  # rubocop:enable Metrics/AbcSize
@@ -11,7 +11,7 @@ module DockerContainerCommand
11
11
  docker_socket_start
12
12
  return false unless _docker_container_lib_create_net_and_ctr @hostname
13
13
 
14
- mutagen_socket_create '~/.mutagen/daemon/daemon.sock', '~/.mutagen/daemon/daemon.sock'
14
+ mutagen_socket_create @mutagensock, @mutagensock if mutagen_check_daemon
15
15
 
16
16
  _docker_container_command_run_command @hostname, command
17
17
  end
@@ -10,7 +10,7 @@ module DockerContainerDaemon
10
10
 
11
11
  result = _docker_container_lib_create_net_and_ctr @hostname
12
12
 
13
- mutagen_socket_create '~/.mutagen/daemon/daemon.sock', '~/.mutagen/daemon/daemon.sock'
13
+ mutagen_socket_create @mutagensock, @mutagensock if mutagen_check_daemon
14
14
 
15
15
  result
16
16
  end
@@ -12,7 +12,7 @@ module DockerContainerLogin
12
12
 
13
13
  return false unless _docker_container_lib_create_net_and_ctr @hostname
14
14
 
15
- mutagen_socket_create '~/.mutagen/daemon/daemon.sock', '~/.mutagen/daemon/daemon.sock'
15
+ mutagen_socket_create @mutagensock, @mutagensock if mutagen_check_daemon
16
16
 
17
17
  run_and_exit _docker_container_login_enter_container @hostname
18
18
  end
@@ -7,7 +7,6 @@ module Takelage
7
7
  include SystemModule
8
8
  include ConfigModule
9
9
  include DockerCheckDaemon
10
- include DockerCheckSocat
11
10
  include DockerSocketLib
12
11
  include DockerSocketHost
13
12
  include DockerSocketScheme
@@ -8,7 +8,7 @@ module DockerSocketStart
8
8
 
9
9
  return false unless docker_check_daemon
10
10
 
11
- return false unless docker_check_socat
11
+ return false unless command_available? 'socat'
12
12
 
13
13
  cmds_start_socket = _docker_socket_lib_get_socket_start_commands 'start'
14
14
 
@@ -8,7 +8,7 @@ module DockerSocketStop
8
8
 
9
9
  return false unless docker_check_daemon
10
10
 
11
- return false unless docker_check_socat
11
+ return false unless command_available? 'socat'
12
12
 
13
13
  # get process list
14
14
  # assuming format: "pid command"
@@ -6,7 +6,14 @@ module Takelage
6
6
  include LoggingModule
7
7
  include SystemModule
8
8
  include ConfigModule
9
+ include DockerCheckDaemon
10
+ include DockerContainerCheckExisting
11
+ include DockerContainerCheckNetwork
12
+ include DockerContainerCommand
13
+ include DockerContainerLib
14
+ include DockerSocketLib
9
15
  include DockerSocketScheme
16
+ include DockerSocketStart
10
17
  include GitCheckWorkspace
11
18
  include InfoStatusLib
12
19
  include InfoStatusGit
@@ -14,6 +21,19 @@ module Takelage
14
21
  include InfoStatusGPG
15
22
  include InfoStatusSSH
16
23
  include InfoStatusBar
24
+ include MutagenCheckDaemon
25
+
26
+ # Initialize info status
27
+ def initialize(args = [], local_options = {}, configuration = {})
28
+ # initialize thor parent class
29
+ super args, local_options, configuration
30
+
31
+ @workdir = Dir.getwd
32
+
33
+ inside = _docker_container_lib_check_matrjoschka
34
+ @hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
35
+ @hostlabel = "hostname=#{@hostname}"
36
+ end
17
37
 
18
38
  #
19
39
  # info status bar
@@ -63,6 +83,18 @@ module Takelage
63
83
  exit info_status_gpg
64
84
  end
65
85
 
86
+ #
87
+ # info status mutagen
88
+ #
89
+ desc 'mutagen', 'Check mutagen status info'
90
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
91
+ Check mutagen status info
92
+ LONGDESC
93
+ # Check mutagen status info.
94
+ def mutagen
95
+ exit mutagen_check_daemon
96
+ end
97
+
66
98
  #
67
99
  # info status ssh
68
100
  #
@@ -5,7 +5,26 @@ require 'open3'
5
5
  require 'yaml'
6
6
 
7
7
  # Interaction with the operating system
8
+ # rubocop:disable Metrics/ModuleLength
8
9
  module SystemModule
10
+ # Check if a command is available
11
+ # @return [Boolean] is the command available?
12
+ def command_available?(command)
13
+ return true if instance_variable_get("@command_available_#{command}")
14
+
15
+ log.debug "Check if the command \"#{command}\" is available"
16
+
17
+ status = try "which #{command}"
18
+
19
+ unless status.exitstatus.zero?
20
+ log.debug "The command \"#{command}\" is not available"
21
+ return false
22
+ end
23
+
24
+ log.debug "The command \"#{command}\" is available"
25
+ instance_variable_set("@command_available_#{command}", true)
26
+ end
27
+
9
28
  # Convert hash to yaml.
10
29
  # @return [String] yaml of hash
11
30
  def hash_to_yaml(hash)
@@ -51,12 +70,26 @@ module SystemModule
51
70
  # @return [String] stdout of command
52
71
  def run(command)
53
72
  log.debug "Running command \"#{command}\""
54
- stdout_str, stderr_str = Open3.capture3 command
73
+ stdout_str, stderr_str, status = Open3.capture3 command
55
74
  log.debug "Command \"#{command}\" has stdout:\n\"\"\"\n#{stdout_str}\"\"\""
56
75
  log.debug "Command \"#{command}\" has stderr:\n\"\"\"\n#{stderr_str}\"\"\""
76
+ log.debug "Command \"#{command}\" has exit status: \"#{status.exitstatus}\""
57
77
  stdout_str
58
78
  end
59
79
 
80
+ # Run a command and return the standard output
81
+ # the standard error and the exit status
82
+ # @return [[String, String, Integer]] array of
83
+ # stdout, stderr, exitstatus of command
84
+ def run_and_capture(command)
85
+ log.debug "Running amd 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]
91
+ end
92
+
60
93
  # Use Kernel#exec to replace the ruby process with a command.
61
94
  def run_and_exit(command)
62
95
  log.debug "Running command \"#{command}\" and exiting afterwards"
@@ -76,8 +109,10 @@ module SystemModule
76
109
  # @return [Boolean] success of command run
77
110
  def try(command)
78
111
  log.debug "Running command \"#{command}\""
79
- _, _, status = Open3.capture3 command
80
- log.debug "Command \"#{command}\" has exit status \"#{status.exitstatus}\""
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}\""
81
116
  status
82
117
  end
83
118
 
@@ -85,7 +120,7 @@ module SystemModule
85
120
 
86
121
  # Check if file exists.
87
122
  def _file_exists?(file)
88
- unless File.exist? file
123
+ unless File.exist? File.expand_path(file)
89
124
  log.debug "File \"#{file}\" doesn't exist"
90
125
  return false
91
126
  end
@@ -95,7 +130,7 @@ module SystemModule
95
130
  # Read yaml file.
96
131
  def _file_read(file)
97
132
  begin
98
- @content_file = File.read file
133
+ @content_file = File.read File.expand_path(file)
99
134
  rescue SystemCallError
100
135
  log.debug "Unable to read file \"#{file}\""
101
136
  return false
@@ -128,3 +163,4 @@ module SystemModule
128
163
  true
129
164
  end
130
165
  end
166
+ # rubocop:enable Metrics/ModuleLength
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Takelage
4
+ # takelage mutagen check
5
+ class MutagenCheck < SubCommandBase
6
+ include LoggingModule
7
+ include SystemModule
8
+ include ConfigModule
9
+ include DockerCheckDaemon
10
+ include DockerContainerCheckExisting
11
+ include DockerContainerCheckNetwork
12
+ include DockerContainerCommand
13
+ include DockerContainerLib
14
+ include DockerSocketLib
15
+ include DockerSocketScheme
16
+ include DockerSocketStart
17
+ include MutagenCheckDaemon
18
+
19
+ # Initialize mutagen check
20
+ def initialize(args = [], local_options = {}, configuration = {})
21
+ # initialize thor parent class
22
+ super args, local_options, configuration
23
+
24
+ @workdir = Dir.getwd
25
+
26
+ inside = _docker_container_lib_check_matrjoschka
27
+ @hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
28
+ @hostlabel = "hostname=#{@hostname}"
29
+ end
30
+
31
+ #
32
+ # mutagen check daemon
33
+ #
34
+ desc 'daemon', 'Check if mutagen host conenction is available'
35
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
36
+ Check if mutagen host conenction is available
37
+ LONGDESC
38
+ # Check if mutagen host conenction is available.
39
+ def daemon
40
+ exit mutagen_check_daemon
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takelage info status mutagen
4
+ module MutagenCheckDaemon
5
+ # Backend method for mutagen check daemon.
6
+ # @return [Boolean] is mutagen available?
7
+ # rubocop:disable Metrics/MethodLength
8
+ # rubocop:disable Metrics/AbcSize
9
+ def mutagen_check_daemon
10
+ log.debug 'Check mutagen status'
11
+
12
+ return false unless command_available? 'mutagen'
13
+
14
+ # are we outside of a takelage container?
15
+ unless _docker_container_lib_check_matrjoschka
16
+ unless _mutagen_check_daemon_version
17
+ log.error 'The mutagen daemon is not available'
18
+ return false
19
+ end
20
+
21
+ log.debug 'The mutagen daemon is available'
22
+ return true
23
+ end
24
+
25
+ unless _file_exists? config.active['mutagen_socket_path']
26
+ log.error 'The mutagen socket is not available'
27
+ return false
28
+ end
29
+
30
+ unless _mutagen_check_daemon_host_connection
31
+ log.error 'A mutagen host connection is not available'
32
+ return false
33
+ end
34
+
35
+ log.debug 'The mutagen daemon is available'
36
+ true
37
+ end
38
+ # rubocop:enable Metrics/AbcSize
39
+ # rubocop:enable Metrics/MethodLength
40
+
41
+ private
42
+
43
+ # Check mutagen host connection
44
+ # rubocop:disable Metrics/MethodLength
45
+ def _mutagen_check_daemon_host_connection
46
+ check_host_connection = format(
47
+ config.active['cmd_mutagen_check_daemon_host_connection'],
48
+ hostlabel: @hostlabel
49
+ )
50
+ stdout, _, exitstatus = run_and_capture check_host_connection
51
+
52
+ unless exitstatus.zero?
53
+ log.debug 'There is no mutagen forward connection to the host'
54
+ return false
55
+ end
56
+
57
+ unless stdout.include? 'Status: Forwarding connections'
58
+ log.debug 'The mutagen forward connection to the host ' \
59
+ 'is not forwarding connections'
60
+ return false
61
+ end
62
+
63
+ true
64
+ end
65
+ # rubocop:enable Metrics/MethodLength
66
+
67
+ # Check mutagen version
68
+ def _mutagen_check_daemon_version
69
+ version = try config.active['cmd_mutagen_check_daemon_version']
70
+ version.exitstatus.zero?
71
+ end
72
+ end
@@ -3,6 +3,9 @@
3
3
  module Takelage
4
4
  # takelage git
5
5
  class Mutagen < SubCommandBase
6
+ desc 'check [COMMAND]', 'Check mutagen'
7
+ subcommand 'check', MutagenCheck
8
+
6
9
  desc 'socket [COMMAND]', 'Manage mutagen socket'
7
10
  subcommand 'socket', MutagenSocket
8
11
  end
@@ -7,6 +7,8 @@ module MutagenSocketCheck
7
7
  def mutagen_socket_check(socket)
8
8
  log.debug "Check if the mutagen socket \"#{socket}\" exists"
9
9
 
10
+ return false unless mutagen_check_daemon
11
+
10
12
  socket_exists = _mutagen_socket_check_socket(socket)
11
13
 
12
14
  unless socket_exists.exitstatus.zero?
@@ -7,7 +7,6 @@ module Takelage
7
7
  include SystemModule
8
8
  include ConfigModule
9
9
  include DockerCheckDaemon
10
- include DockerCheckSocat
11
10
  include DockerContainerCheckExisting
12
11
  include DockerContainerCheckNetwork
13
12
  include DockerContainerCommand
@@ -15,12 +14,17 @@ module Takelage
15
14
  include DockerSocketLib
16
15
  include DockerSocketScheme
17
16
  include DockerSocketStart
17
+ include DockerImageTagLatest
18
+ include DockerImageTagList
19
+ include DockerImageTagCheck
20
+ include MutagenCheckDaemon
18
21
  include MutagenSocketCheck
19
22
  include MutagenSocketCreate
20
23
  include MutagenSocketList
24
+ include MutagenSocketTidy
21
25
  include MutagenSocketTerminate
22
26
 
23
- # Initialize mtagen socket
27
+ # Initialize mutagen socket
24
28
  def initialize(args = [], local_options = {}, configuration = {})
25
29
  # initialize thor parent class
26
30
  super args, local_options, configuration
@@ -28,10 +32,15 @@ module Takelage
28
32
  @docker_repo = config.active['docker_repo']
29
33
  @username = ENV['USER'] || 'noname'
30
34
  @workdir = Dir.getwd
35
+
31
36
  inside = _docker_container_lib_check_matrjoschka
32
37
  @hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
38
+ # See DockerContainerLib::_docker_container_lib_hostname
39
+ @socketname = @hostname[-11..-1]
40
+
33
41
  @hostlabel = "hostname=#{@hostname}"
34
- @takellabel = 'type=takelage-socket'
42
+ @takellabel = config.active['mutagen_socket_takelage_label']
43
+
35
44
  @sockets = docker_socket_scheme
36
45
  end
37
46
 
@@ -85,5 +94,17 @@ module Takelage
85
94
  def terminate(socket)
86
95
  exit mutagen_socket_terminate socket
87
96
  end
97
+
98
+ #
99
+ # mutagen socket tidy
100
+ #
101
+ desc 'tidy', 'Remove mutagen daemon files'
102
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
103
+ Remove mutagen daemon files
104
+ LONGDESC
105
+ # Remove mutagen daemon files.
106
+ def tidy
107
+ exit mutagen_socket_tidy
108
+ end
88
109
  end
89
110
  end
@@ -4,18 +4,19 @@
4
4
  module MutagenSocketCreate
5
5
  # Backend method for mutagen socket create.
6
6
  def mutagen_socket_create(containersock, hostsock)
7
- socketname = @hostname[-11..-1]
8
- log.debug "Create the mutagen socket \"#{socketname}\" in the container" \
7
+ log.debug "Create the mutagen socket \"#{@socketname}\" in the container" \
9
8
  "at \"#{containersock}\" pointing to the host at \"#{hostsock}\""
10
9
 
11
- socket_created = _mutagen_socket_create_socket(socketname, containersock, hostsock)
10
+ return false unless mutagen_check_daemon
11
+
12
+ socket_created = _mutagen_socket_create_socket(containersock, hostsock)
12
13
 
13
14
  unless socket_created.include? 'Created session'
14
- log.debug "Unable to create mutagen socket \"#{socketname}\""
15
+ log.debug "Unable to create mutagen socket \"#{@socketname}\""
15
16
  return false
16
17
  end
17
18
 
18
- log.debug "Created the mutagen socket \"#{socketname}\""
19
+ log.debug "Created the mutagen socket \"#{@socketname}\""
19
20
  true
20
21
  end
21
22
 
@@ -23,10 +24,10 @@ module MutagenSocketCreate
23
24
 
24
25
  # Get git branch.
25
26
  # rubocop:disable Metrics/MethodLength
26
- def _mutagen_socket_create_socket(socketname, containersock, hostsock)
27
+ def _mutagen_socket_create_socket(containersock, hostsock)
27
28
  cmd_create_socket = format(
28
29
  config.active['cmd_mutagen_forward_socket_create'],
29
- socketname: socketname,
30
+ socketname: @socketname,
30
31
  containersock: containersock,
31
32
  hostsock: hostsock,
32
33
  username: @username,
@@ -7,6 +7,8 @@ module MutagenSocketList
7
7
  def mutagen_socket_list
8
8
  log.debug 'List the mutagen takelage sockets'
9
9
 
10
+ return false unless mutagen_check_daemon
11
+
10
12
  sockets = _mutagen_socket_list
11
13
 
12
14
  if sockets.to_s.empty?
@@ -6,10 +6,9 @@ module MutagenSocketTerminate
6
6
  def mutagen_socket_terminate(socket)
7
7
  log.debug "Terminate the mutagen socket \"#{socket}\""
8
8
 
9
- socket_terminated = _mutagen_socket_terminate_socket socket
9
+ return false unless mutagen_check_daemon
10
10
 
11
- cmd_remove = config.active['cmd_mutagen_forward_socket_remove']
12
- docker_container_command cmd_remove if cmd_remove && socket_terminated.exitstatus.zero?
11
+ socket_terminated = _mutagen_socket_terminate_socket socket
13
12
 
14
13
  unless socket_terminated.exitstatus.zero?
15
14
  log.debug "Unable to terminated mutagen socket \"#{socket}\""
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takelage mutagen socket tidy
4
+ module MutagenSocketTidy
5
+ # Backend method for mutagen socket tidy.
6
+ def mutagen_socket_tidy
7
+ log.debug "Remove the mutagen daemon files in container \"#{@hostname}\""
8
+
9
+ container_existing = docker_container_check_existing @hostname
10
+ cmd_remove = config.active['cmd_mutagen_forward_socket_remove']
11
+ return false unless container_existing && cmd_remove.empty?
12
+
13
+ unless docker_container_command cmd_remove
14
+ log.error "Unable to remove the mutagen daemon files in container \"#{@hostname}\""
15
+ return false
16
+ end
17
+
18
+ log.debug "Removed the mutagen daemon files in container \"#{@hostname}\""
19
+ true
20
+ end
21
+ end
data/lib/takelage/version CHANGED
@@ -1 +1 @@
1
- 0.28.7
1
+ 0.28.26
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takelage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.7
4
+ version: 0.28.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geospin
@@ -227,7 +227,6 @@ files:
227
227
  - lib/takelage/default.yml
228
228
  - lib/takelage/docker/check/cli.rb
229
229
  - lib/takelage/docker/check/daemon.rb
230
- - lib/takelage/docker/check/socat.rb
231
230
  - lib/takelage/docker/cli.rb
232
231
  - lib/takelage/docker/container/check/cli.rb
233
232
  - lib/takelage/docker/container/check/existing.rb
@@ -271,12 +270,15 @@ files:
271
270
  - lib/takelage/lib/project.rb
272
271
  - lib/takelage/lib/subcmd.rb
273
272
  - lib/takelage/lib/system.rb
273
+ - lib/takelage/mutagen/check/cli.rb
274
+ - lib/takelage/mutagen/check/daemon.rb
274
275
  - lib/takelage/mutagen/cli.rb
275
276
  - lib/takelage/mutagen/socket/check.rb
276
277
  - lib/takelage/mutagen/socket/cli.rb
277
278
  - lib/takelage/mutagen/socket/create.rb
278
279
  - lib/takelage/mutagen/socket/list.rb
279
280
  - lib/takelage/mutagen/socket/terminate.rb
281
+ - lib/takelage/mutagen/socket/tidy.rb
280
282
  - lib/takelage/self/cli.rb
281
283
  - lib/takelage/self/config/cli.rb
282
284
  - lib/takelage/self/list.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # takelage docker check running
4
- module DockerCheckSocat
5
- # Backend method for docker check socat.
6
- # @return [Boolean] is the socat command available?
7
- def docker_check_socat
8
- return true if @socat_command_available
9
-
10
- log.debug 'Check if the socat command is available'
11
-
12
- status = try config.active['cmd_docker_check_socat_which_socat']
13
-
14
- unless status.exitstatus.zero?
15
- log.debug 'The socat command is not available'
16
- return false
17
- end
18
-
19
- log.debug 'The socat command is available'
20
- @socat_command_available = true
21
- true
22
- end
23
- end