takelage 0.28.26 → 0.29.0

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: c5b24cafbddb28d0bc465c9b464a02d6d08c14639dfe5c58cc891828680143dc
4
- data.tar.gz: 7743c6e2f629e35838820ab439c72a6b659c674f852fe7a114e9016d771011af
3
+ metadata.gz: f4ad578971e04ab78238e26f456f1071a39dcd57ca40d08cb63f78623dbba13f
4
+ data.tar.gz: 5bc6aaf8d1d7b37ab684da509c766d040d12d37a88cc301ee24405110f4b0631
5
5
  SHA512:
6
- metadata.gz: 4135b0857fbbff72ce697309745232b1433352cd7b3a884486044aa761b9a66f15b29ab896a5406cabab35c1b8c941fed2c91c0d2344bd604cbde99ef22fbb5f
7
- data.tar.gz: 773c9fdfa99690acc118f837ddbdc343e51f1962f05bd740c312ae7b125713734eb1b591c2f411499f76728e009bc4b175ec128747319a53b614ff88b5c7e071
6
+ metadata.gz: 38d06e826c104089e3a134a7e6ce9660893f1cd2f8f103cdf2771d84ad4a82e2eda8e6dd7578da0452a98a4e808b0e55393798ac363c89d4960d34ebb83390e3
7
+ data.tar.gz: 5a98640e8c71d0be3a730de18d75e86f890e812498e53a1a7e0bb73d90536f36add90d80abc89ea06cdbfb99b208ead667aecc91f4e524b2245b68356c92f7e3
data/README.md CHANGED
@@ -90,10 +90,6 @@ tau [docker image tag check](features/cucumber/features/docker/docker.image.tag.
90
90
  tau [docker image tag latest](features/cucumber/features/docker/docker.image.tag.latest.feature) | Print latest local docker image tag
91
91
  tau [docker image tag list](features/cucumber/features/docker/docker.image.tag.list.feature) | Print local docker image tags
92
92
  tau [docker image update](features/cucumber/features/docker/docker.image.update.feature) | Get latest remote docker container
93
- tau [docker socket host](features/cucumber/features/docker/docker.socket.host.feature) | Print docker socket host ip address
94
- tau [docker socket scheme](features/cucumber/features/docker/docker.socket.scheme.feature) | Print docker socket scheme
95
- tau [docker socket start](features/cucumber/features/docker/docker.socket.start.feature) | Start sockets for docker container
96
- tau [docker socket stop](features/cucumber/features/docker/docker.socket.stop.feature) | Stop sockets for docker container
97
93
  tau [git check clean](features/cucumber/features/git/git.check.clean.feature) | Check if the git workspace is clean
98
94
  tau [git check main](features/cucumber/features/git/git.check.main.feature) | Check if we are on the git main branch
99
95
  tau [git check workspace](features/cucumber/features/git/git.check.workspace.feature) | Check if a git workspace exists
@@ -109,7 +105,7 @@ tau [info status mutagen](features/cucumber/features/info/info.status.mutagen.fe
109
105
  tau [info status ssh](features/cucumber/features/info/info.status.ssh.feature) | Check ssh status
110
106
  tau [mutagen check daemon](features/cucumber/features/mutagen/mutagen.check.daemon.feature)) | Check if mutagen host conenction is available
111
107
  tau [mutagen socket check](features/cucumber/features/mutagen/mutagen.socket.check.feature) [SOCKET] | Check if mutagen [SOCKET] exists
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
108
+ tau [mutagen socket create](features/cucumber/features/mutagen/mutagen.socket.create.feature) [NAME] [IN] [OUT] | Create a mutagen socket [NAME] from [IN] to [OUT] of the container
113
109
  tau [mutagen socket list](features/cucumber/features/mutagen/mutagen.socket.list.feature) | List mutagen sockets
114
110
  tau [mutagen socket tidy](features/cucumber/features/mutagen/mutagen.socket.tidy.feature) | Remove mutagen daemon files
115
111
  tau [mutagen socket terminate](features/cucumber/features/mutagen/mutagen.socket.terminate.feature) | Terminate a mutagen socket
data/lib/takelage.rb CHANGED
@@ -45,17 +45,12 @@ require_relative 'takelage/bit/require/cli'
45
45
  require_relative 'takelage/bit/cli'
46
46
  require_relative 'takelage/completion/cli'
47
47
  require_relative 'takelage/mutagen/check/daemon'
48
+ require_relative 'takelage/mutagen/socket/check'
48
49
  require_relative 'takelage/mutagen/socket/create'
49
50
  require_relative 'takelage/mutagen/socket/terminate'
50
51
  require_relative 'takelage/mutagen/socket/tidy'
51
52
  require_relative 'takelage/docker/check/daemon'
52
53
  require_relative 'takelage/docker/check/cli'
53
- require_relative 'takelage/docker/socket/lib'
54
- require_relative 'takelage/docker/socket/host'
55
- require_relative 'takelage/docker/socket/scheme'
56
- require_relative 'takelage/docker/socket/start'
57
- require_relative 'takelage/docker/socket/stop'
58
- require_relative 'takelage/docker/socket/cli'
59
54
  require_relative 'takelage/docker/image/tag/list'
60
55
  require_relative 'takelage/docker/image/tag/latest'
61
56
  require_relative 'takelage/docker/image/tag/check'
@@ -75,7 +70,6 @@ require_relative 'takelage/docker/container/prune'
75
70
  require_relative 'takelage/docker/container/cli'
76
71
  require_relative 'takelage/docker/cli'
77
72
  require_relative 'takelage/mutagen/check/cli'
78
- require_relative 'takelage/mutagen/socket/check'
79
73
  require_relative 'takelage/mutagen/socket/list'
80
74
  require_relative 'takelage/mutagen/socket/cli'
81
75
  require_relative 'takelage/mutagen/cli'
@@ -126,7 +120,9 @@ module Takelage
126
120
 
127
121
  # Set defaults
128
122
  @docker_daemon_running = false
129
- @socat_command_available = false
123
+ @command_available_docker = false
124
+ @mutagen_daemon_available = false
125
+ @command_available_mutagen = false
130
126
 
131
127
  # fylla bash completion code
132
128
  @bash_fylla = Fylla.bash_completion self
@@ -33,7 +33,7 @@ cmd_docker_check_daemon_docker_info: 'docker info'
33
33
  cmd_docker_container_check_existing_docker_ps: 'docker ps --filter name=^%{container}$ --quiet'
34
34
  cmd_docker_container_check_network_docker_network: 'docker network ls --quiet --filter name=^%{network}$'
35
35
  cmd_docker_container_check_orphaned_docker_exec: 'docker exec --interactive %{container} ps a'
36
- cmd_docker_container_create: 'docker run --detach --env TAKELAGE_PROJECT_BASE_DIR=%{workdir} --env TZ=%{timezone} --hostname %{container} --name %{container} --network %{container} --rm --shm-size %{shmsize} --tty --volume %{dockersock}:/var/run/docker.sock --volume %{homedir}:/hostdir --volume %{workdir}:/project %{volume_dev} --workdir /project %{addhost} %{docker_run_options} %{image} %{entrypoint} --gid %{gid} --home %{homedir} --uid %{uid} --username %{username} --gpg_agent_port %{gpg_agent_port} --gpg_ssh_agent_port %{gpg_ssh_agent_port} --extra=%{extra} %{entrypoint_options}'
36
+ cmd_docker_container_create: 'docker run --detach --env TAKELAGE_PROJECT_BASE_DIR=%{workdir} --env TZ=%{timezone} --hostname %{container} --name %{container} --network %{container} --rm --shm-size %{shmsize} --tty --volume %{dockersock}:/var/run/docker.sock --volume %{homedir}:/hostdir --volume %{workdir}:/project %{volume_dev} --workdir /project %{docker_run_options} %{image} %{entrypoint} --gid %{gid} --home %{homedir} --uid %{uid} --username %{username} --extra=%{extra} %{entrypoint_options}'
37
37
  cmd_docker_container_create_network: 'docker network create %{network}'
38
38
  cmd_docker_container_enter_container: 'docker exec --interactive --tty %{container} %{loginpoint} --username %{username}'
39
39
  cmd_docker_container_get_container_name: 'docker ps --filter id=%{container} --format "{{.Names}}"'
@@ -45,12 +45,6 @@ cmd_docker_image_tag_check_docker_images: 'docker images --quiet %{image}'
45
45
  cmd_docker_image_tag_list_docker_images: 'docker images %{docker_user}\/%{docker_repo} --format "{{.Tag}}"'
46
46
  cmd_docker_image_update_docker_pull_latest: 'docker pull %{docker_user}/%{docker_repo}:latest'
47
47
  cmd_docker_image_update_docker_remove_dangling: 'docker image prune --force'
48
- cmd_docker_socket_config_agent_socket_path: 'gpgconf --list-dirs agent-socket'
49
- cmd_docker_socket_config_agent_ssh_socket_path: 'gpgconf --list-dirs agent-ssh-socket'
50
- cmd_docker_socket_get_start: 'sudo socat TCP-LISTEN:%{port},bind=%{host},reuseaddr,fork UNIX-CLIENT:%{path}'
51
- cmd_docker_socket_start_sudo_true: 'sudo true'
52
- cmd_docker_socket_stop_docker_socket_ps: 'sudo ps a -o pid,command'
53
- cmd_docker_socket_stop_docker_socket_kill: 'sudo kill -SIGTERM %{pid}'
54
48
  cmd_git_check_clean_git_unstaged: 'git diff --exit-code'
55
49
  cmd_git_check_clean_git_uncommitted: 'git diff --cached --exit-code'
56
50
  cmd_git_check_clean_git_status: 'git status --porcelain'
@@ -65,6 +59,7 @@ cmd_info_status_gopass_root_store: 'gopass config | grep "path" | cut -d " " -f
65
59
  cmd_info_status_gpg_agent: 'gpg-connect-agent /bye'
66
60
  cmd_info_status_gpg_keys: 'gpg --list-keys'
67
61
  cmd_info_status_ssh_keys: 'ssh-add -l'
62
+ cmd_info_status_ssh_socket: 'gpgconf --list-dirs agent-ssh-socket'
68
63
  cmd_mutagen_check_daemon_host_connection: 'mutagen forward list --label-selector="%{hostlabel}"'
69
64
  cmd_mutagen_check_daemon_version: 'mutagen version'
70
65
  cmd_mutagen_forward_socket_create: 'mutagen forward create --name=%{socketname} --label=%{hostlabel} --label=%{takellabel} docker://%{username}@%{container}:unix:%{containersock} unix:%{hostsock}'
@@ -79,12 +74,12 @@ docker_registry: 'https://registry.hub.docker.com'
79
74
  docker_repo: 'takelage'
80
75
  docker_run_options: '--env GOOGLE_APPLICATION_CREDENTIALS=/hostdir/.google/default.json'
81
76
  docker_shm_size: '512M'
82
- docker_socket_gpg_agent_port: 17874
83
- docker_socket_gpg_ssh_agent_port: 17875
84
77
  docker_tag: 'latest'
85
78
  docker_user: 'takelage'
86
79
  git_main_branch: 'main'
87
80
  info_project_main: 'project.yml'
88
81
  info_project_private: 'private/project.yml'
89
- mutagen_socket_path: '~/.mutagen/daemon/daemon.sock'
82
+ mutagen_socket_path_mutagen: '~/.mutagen/daemon/daemon.sock'
83
+ mutagen_socket_path_gpg: '~/.gnupg/S.gpg-agent'
84
+ mutagen_socket_path_ssh: '~/.gnupg/S.gpg-agent.ssh'
90
85
  mutagen_socket_takelage_label: 'type=takelage-socket'
@@ -11,8 +11,5 @@ module Takelage
11
11
 
12
12
  desc 'image [COMMAND]', 'Handle docker images'
13
13
  subcommand 'image', DockerImage
14
-
15
- desc 'socket [COMMAND]', 'Handle sockets for docker containers'
16
- subcommand 'socket', DockerSocket
17
14
  end
18
15
  end
@@ -19,11 +19,8 @@ module Takelage
19
19
  include DockerImageTagLatest
20
20
  include DockerImageTagList
21
21
  include DockerImageTagCheck
22
- include DockerSocketLib
23
- include DockerSocketHost
24
- include DockerSocketScheme
25
- include DockerSocketStart
26
22
  include MutagenCheckDaemon
23
+ include MutagenSocketCheck
27
24
  include MutagenSocketCreate
28
25
  include MutagenSocketTerminate
29
26
 
@@ -43,9 +40,9 @@ module Takelage
43
40
  @hostname = _docker_container_lib_hostname
44
41
  @hostlabel = "hostname=#{@hostname}"
45
42
  @takellabel = config.active['mutagen_socket_takelage_label']
46
- @socket_host = docker_socket_host
47
- @sockets = docker_socket_scheme
48
- @mutagensock = config.active['mutagen_socket_path']
43
+ @mutagensock = config.active['mutagen_socket_path_mutagen']
44
+ @gpgsock = config.active['mutagen_socket_path_gpg']
45
+ @sshsock = config.active['mutagen_socket_path_ssh']
49
46
  end
50
47
  # rubocop:enable Metrics/MethodLength
51
48
  # rubocop:enable Metrics/AbcSize
@@ -8,10 +8,9 @@ module DockerContainerCommand
8
8
 
9
9
  return false unless docker_check_daemon
10
10
 
11
- docker_socket_start
12
11
  return false unless _docker_container_lib_create_net_and_ctr @hostname
13
12
 
14
- mutagen_socket_create @mutagensock, @mutagensock if mutagen_check_daemon
13
+ _docker_container_lib_start_sockets
15
14
 
16
15
  _docker_container_command_run_command @hostname, command
17
16
  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 @mutagensock, @mutagensock if mutagen_check_daemon
13
+ _docker_container_lib_start_sockets
14
14
 
15
15
  result
16
16
  end
@@ -6,6 +6,15 @@
6
6
  module DockerContainerLib
7
7
  private
8
8
 
9
+ # Create mutagen sockets
10
+ def _docker_container_lib_start_sockets
11
+ return false unless mutagen_check_daemon
12
+
13
+ mutagen_socket_create 'mutagen', @mutagensock, @mutagensock
14
+ mutagen_socket_create 'gpg', @gpgsock, @gpgsock
15
+ mutagen_socket_create 'ssh', @sshsock, @sshsock
16
+ end
17
+
9
18
  # Create unique docker hostname
10
19
  def _docker_container_lib_hostname
11
20
  relative_name = "#{@docker_repo}_#{File.basename(@workdir)}"
@@ -75,10 +84,6 @@ module DockerContainerLib
75
84
 
76
85
  log.debug "Using docker image \"#{image}\""
77
86
 
78
- unless @socket_host == '127.0.0.1'
79
- addhost = "--add-host host.docker.internal:#{@socket_host}"
80
- end
81
-
82
87
  docker_debug = config.active['docker_debug']
83
88
  entrypoint = '/entrypoint.py '
84
89
  volume_dev = ''
@@ -89,7 +94,6 @@ module DockerContainerLib
89
94
 
90
95
  cmd_docker_create = format(
91
96
  config.active['cmd_docker_container_create'],
92
- addhost: addhost,
93
97
  container: container,
94
98
  docker_run_options: config.active['docker_run_options'],
95
99
  dockersock: '/var/run/docker.sock',
@@ -97,8 +101,6 @@ module DockerContainerLib
97
101
  entrypoint_options: config.active['docker_entrypoint_options'],
98
102
  extra: config.active['docker_entrypoint_extra'],
99
103
  gid: Etc.getpwnam(@username).gid,
100
- gpg_agent_port: config.active['docker_socket_gpg_agent_port'],
101
- gpg_ssh_agent_port: config.active['docker_socket_gpg_ssh_agent_port'],
102
104
  homedir: ENV['HOME'] || '/tmp',
103
105
  image: image,
104
106
  shmsize: config.active['docker_shm_size'],
@@ -8,11 +8,9 @@ module DockerContainerLogin
8
8
 
9
9
  return false unless docker_check_daemon
10
10
 
11
- docker_socket_start
12
-
13
11
  return false unless _docker_container_lib_create_net_and_ctr @hostname
14
12
 
15
- mutagen_socket_create @mutagensock, @mutagensock if mutagen_check_daemon
13
+ _docker_container_lib_start_sockets
16
14
 
17
15
  run_and_exit _docker_container_login_enter_container @hostname
18
16
  end
@@ -15,6 +15,7 @@ module InfoStatusBar
15
15
  _info_status_bar_git
16
16
  _info_status_bar_gopass
17
17
  _info_status_bar_gpg
18
+ _info_status_bar_mutagen
18
19
  _info_status_bar_ssh
19
20
 
20
21
  bar = @bar_list.join(' | ')
@@ -61,6 +62,11 @@ module InfoStatusBar
61
62
  @bar_list << ("gpg: #{info_status_gpg ? 'ok'.green : 'no'.red}")
62
63
  end
63
64
 
65
+ # Add mutagen status info to bar
66
+ def _info_status_bar_mutagen
67
+ @bar_list << ("mutagen: #{mutagen_check_daemon ? 'ok'.green : 'no'.red}")
68
+ end
69
+
64
70
  # Add ssh status info to bar
65
71
  def _info_status_bar_ssh
66
72
  @bar_list << ("ssh: #{info_status_ssh ? 'ok'.green : 'no'.red}")
@@ -11,9 +11,6 @@ module Takelage
11
11
  include DockerContainerCheckNetwork
12
12
  include DockerContainerCommand
13
13
  include DockerContainerLib
14
- include DockerSocketLib
15
- include DockerSocketScheme
16
- include DockerSocketStart
17
14
  include GitCheckWorkspace
18
15
  include InfoStatusLib
19
16
  include InfoStatusGit
@@ -9,7 +9,7 @@ module InfoStatusSSH
9
9
  log.debug 'Check ssh status'
10
10
 
11
11
  ssh_auth_sock = ENV['SSH_AUTH_SOCK']
12
- gpg_ssh_socket = _socket_get_agent_ssh_socket_path
12
+ gpg_ssh_socket = _info_status_ssh_socket_path.chomp
13
13
 
14
14
  unless ssh_auth_sock == gpg_ssh_socket
15
15
  log.error 'ssh does not use gpg ssh socket'
@@ -33,6 +33,11 @@ module InfoStatusSSH
33
33
 
34
34
  private
35
35
 
36
+ # Get ssh socket path
37
+ def _info_status_ssh_socket_path
38
+ run config.active['cmd_info_status_ssh_socket']
39
+ end
40
+
36
41
  # Check ssh keys
37
42
  def _info_status_ssh_keys
38
43
  status_keys = try config.active['cmd_info_status_ssh_keys']
@@ -11,9 +11,6 @@ module Takelage
11
11
  include DockerContainerCheckNetwork
12
12
  include DockerContainerCommand
13
13
  include DockerContainerLib
14
- include DockerSocketLib
15
- include DockerSocketScheme
16
- include DockerSocketStart
17
14
  include MutagenCheckDaemon
18
15
 
19
16
  # Initialize mutagen check
@@ -7,10 +7,12 @@ module MutagenCheckDaemon
7
7
  # rubocop:disable Metrics/MethodLength
8
8
  # rubocop:disable Metrics/AbcSize
9
9
  def mutagen_check_daemon
10
- log.debug 'Check mutagen status'
10
+ return true if @mutagen_daemon_available
11
11
 
12
12
  return false unless command_available? 'mutagen'
13
13
 
14
+ log.debug 'Check mutagen status'
15
+
14
16
  # are we outside of a takelage container?
15
17
  unless _docker_container_lib_check_matrjoschka
16
18
  unless _mutagen_check_daemon_version
@@ -19,10 +21,11 @@ module MutagenCheckDaemon
19
21
  end
20
22
 
21
23
  log.debug 'The mutagen daemon is available'
24
+ @mutagen_daemon_available = true
22
25
  return true
23
26
  end
24
27
 
25
- unless _file_exists? config.active['mutagen_socket_path']
28
+ unless _file_exists? config.active['mutagen_socket_path_mutagen']
26
29
  log.error 'The mutagen socket is not available'
27
30
  return false
28
31
  end
@@ -33,6 +36,7 @@ module MutagenCheckDaemon
33
36
  end
34
37
 
35
38
  log.debug 'The mutagen daemon is available'
39
+ @mutagen_daemon_available = true
36
40
  true
37
41
  end
38
42
  # rubocop:enable Metrics/AbcSize
@@ -11,9 +11,6 @@ module Takelage
11
11
  include DockerContainerCheckNetwork
12
12
  include DockerContainerCommand
13
13
  include DockerContainerLib
14
- include DockerSocketLib
15
- include DockerSocketScheme
16
- include DockerSocketStart
17
14
  include DockerImageTagLatest
18
15
  include DockerImageTagList
19
16
  include DockerImageTagCheck
@@ -35,13 +32,9 @@ module Takelage
35
32
 
36
33
  inside = _docker_container_lib_check_matrjoschka
37
34
  @hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
38
- # See DockerContainerLib::_docker_container_lib_hostname
39
- @socketname = @hostname[-11..-1]
40
35
 
41
36
  @hostlabel = "hostname=#{@hostname}"
42
37
  @takellabel = config.active['mutagen_socket_takelage_label']
43
-
44
- @sockets = docker_socket_scheme
45
38
  end
46
39
 
47
40
  #
@@ -59,13 +52,13 @@ module Takelage
59
52
  #
60
53
  # mutagen socket create
61
54
  #
62
- desc 'create [IN] [OUT]', 'Create a mutagen socket from [IN] to [OUT] of the container'
55
+ desc 'create [NAME] [IN] [OUT]', 'Create a mutagen socket [NAME] from [IN] to [OUT] of the container'
63
56
  long_desc <<-LONGDESC.gsub("\n", "\x5")
64
- Create a mutagen socket from [IN] to [OUT] of the container
57
+ Create a mutagen socket [NAME] from [IN] to [OUT] of the container
65
58
  LONGDESC
66
- # Create a mutagen socket from [IN] to [OUT] of the container.
67
- def create(containersock, hostsock)
68
- exit mutagen_socket_create containersock, hostsock
59
+ # Create a mutagen socket [NAME] from [IN] to [OUT] of the container.
60
+ def create(name, containersock, hostsock)
61
+ exit mutagen_socket_create name, containersock, hostsock
69
62
  end
70
63
 
71
64
  #
@@ -3,31 +3,37 @@
3
3
  # takelage mutagen socket create
4
4
  module MutagenSocketCreate
5
5
  # Backend method for mutagen socket create.
6
- def mutagen_socket_create(containersock, hostsock)
7
- log.debug "Create the mutagen socket \"#{@socketname}\" in the container" \
6
+ # rubocop:disable Metrics/MethodLength
7
+ def mutagen_socket_create(name, containersock, hostsock)
8
+ # See DockerContainerLib::_docker_container_lib_hostname
9
+ socketname = "#{@hostname[-11..-1]}-#{name}"
10
+ log.debug "Create the mutagen socket \"#{socketname}\" in the container " \
8
11
  "at \"#{containersock}\" pointing to the host at \"#{hostsock}\""
9
12
 
10
13
  return false unless mutagen_check_daemon
11
14
 
12
- socket_created = _mutagen_socket_create_socket(containersock, hostsock)
15
+ return false if mutagen_socket_check socketname
16
+
17
+ socket_created = _mutagen_socket_create_socket(socketname, containersock, hostsock)
13
18
 
14
19
  unless socket_created.include? 'Created session'
15
- log.debug "Unable to create mutagen socket \"#{@socketname}\""
20
+ log.debug "Unable to create mutagen socket \"#{socketname}\""
16
21
  return false
17
22
  end
18
23
 
19
- log.debug "Created the mutagen socket \"#{@socketname}\""
24
+ log.debug "Created the mutagen socket \"#{socketname}\""
20
25
  true
21
26
  end
27
+ # rubocop:enable Metrics/MethodLength
22
28
 
23
29
  private
24
30
 
25
31
  # Get git branch.
26
32
  # rubocop:disable Metrics/MethodLength
27
- def _mutagen_socket_create_socket(containersock, hostsock)
33
+ def _mutagen_socket_create_socket(socketname, containersock, hostsock)
28
34
  cmd_create_socket = format(
29
35
  config.active['cmd_mutagen_forward_socket_create'],
30
- socketname: @socketname,
36
+ socketname: socketname,
31
37
  containersock: containersock,
32
38
  hostsock: hostsock,
33
39
  username: @username,
data/lib/takelage/version CHANGED
@@ -1 +1 @@
1
- 0.28.26
1
+ 0.29.0
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.26
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geospin
@@ -245,12 +245,6 @@ files:
245
245
  - lib/takelage/docker/image/tag/latest.rb
246
246
  - lib/takelage/docker/image/tag/list.rb
247
247
  - lib/takelage/docker/image/update.rb
248
- - lib/takelage/docker/socket/cli.rb
249
- - lib/takelage/docker/socket/host.rb
250
- - lib/takelage/docker/socket/lib.rb
251
- - lib/takelage/docker/socket/scheme.rb
252
- - lib/takelage/docker/socket/start.rb
253
- - lib/takelage/docker/socket/stop.rb
254
248
  - lib/takelage/git/check/clean.rb
255
249
  - lib/takelage/git/check/cli.rb
256
250
  - lib/takelage/git/check/main.rb
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Takelage
4
- # takelage docker socket
5
- class DockerSocket < SubCommandBase
6
- include LoggingModule
7
- include SystemModule
8
- include ConfigModule
9
- include DockerCheckDaemon
10
- include DockerSocketLib
11
- include DockerSocketHost
12
- include DockerSocketScheme
13
- include DockerSocketStart
14
- include DockerSocketStop
15
-
16
- # Initialize docker socket
17
- def initialize(args = [], local_options = {}, configuration = {})
18
- # initialize thor parent class
19
- super args, local_options, configuration
20
-
21
- @socket_host = docker_socket_host
22
- @sockets = docker_socket_scheme
23
- end
24
-
25
- #
26
- # docker socket host
27
- #
28
- desc 'host', 'Print docker socket host ip address'
29
- long_desc <<-LONGDESC.gsub("\n", "\x5")
30
- Print docker socket host ip address
31
- LONGDESC
32
- # Print docker socket host ip address.
33
- def host
34
- say @socket_host
35
- true
36
- end
37
-
38
- #
39
- # docker socket scheme
40
- #
41
- desc 'scheme', 'Print docker socket scheme'
42
- long_desc <<-LONGDESC.gsub("\n", "\x5")
43
- Print docker socket scheme
44
- LONGDESC
45
- # Print docker socket scheme.
46
- def scheme
47
- say hash_to_yaml(@sockets)
48
- true
49
- end
50
-
51
- #
52
- # docker socket start
53
- #
54
- desc 'start', 'Start sockets for docker container'
55
- long_desc <<-LONGDESC.gsub("\n", "\x5")
56
- Start sockets for docker container
57
- LONGDESC
58
- # Start sockets for docker container.
59
- def start
60
- exit docker_socket_start
61
- end
62
-
63
- #
64
- # docker socket stop
65
- #
66
- desc 'stop', 'Stop sockets for docker container'
67
- long_desc <<-LONGDESC.gsub("\n", "\x5")
68
- Stop sockets for docker container
69
- LONGDESC
70
- # Stop sockets for docker container.
71
- def stop
72
- exit docker_socket_stop
73
- end
74
- end
75
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # takelage docker socket host
4
- module DockerSocketHost
5
- # Backend method for docker socket host.
6
- def docker_socket_host
7
- log.debug 'Getting docker socket host ip address'
8
-
9
- socket_host = _docker_socket_host_get_socket_host
10
-
11
- log.debug "Docker socket host ip address is \"#{socket_host}\""
12
-
13
- socket_host
14
- end
15
-
16
- private
17
-
18
- # Get the socket host, i.e. the ip of the docker host.
19
- def _docker_socket_host_get_socket_host
20
- socket_host = '127.0.0.1'
21
-
22
- addr_infos = Socket.getifaddrs
23
-
24
- # if interface docker0 exists (== linux host)
25
- # then return the ip address
26
- addr_infos.each do |addr_info|
27
- next unless (addr_info.name == 'docker0') && addr_info.addr.ipv4?
28
-
29
- socket_host = addr_info.addr.ip_address
30
- end
31
-
32
- socket_host
33
- end
34
- end
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # takelage docker socket lib
4
- module DockerSocketLib
5
- private
6
-
7
- # Get socket start commands.
8
- # sockets_up is a boolean which defines if the sockets need to be up
9
- # to be included in the resulting array of socket start commands
10
- def _docker_socket_lib_get_socket_start_commands(mode)
11
- cmds_start_socket = []
12
-
13
- # loop over sockets
14
- @sockets.each do |socket, socket_config|
15
- host = socket_config['host']
16
- port = socket_config['port']
17
- path = socket_config['path']
18
-
19
- cmd = _docker_socket_lib_get_start_cmd(mode, socket, host, port, path)
20
- cmds_start_socket.push cmd if cmd
21
- end
22
-
23
- cmds_start_socket
24
- end
25
-
26
- # Get socket start command.
27
- def _docker_socket_lib_get_start_cmd(mode, socket, host, port, path)
28
- if mode == 'start'
29
- unless _docker_socket_lib_socket_up? socket, host, port, path
30
- return _docker_socket_lib_start_cmd(host, port, path)
31
- end
32
- elsif _docker_socket_lib_socket_up? socket, host, port, path
33
- return _docker_socket_lib_start_cmd(host, port, path)
34
- end
35
- nil
36
- end
37
-
38
- # Get socket start command.
39
- def _docker_socket_lib_start_cmd(host, port, path)
40
- format(
41
- config.active['cmd_docker_socket_get_start'],
42
- host: host,
43
- port: port,
44
- path: path
45
- )
46
- end
47
-
48
- # Check if a socket is available by trying to connect to it via TCP.
49
- def _docker_socket_lib_socket_up?(socket, host, port, path)
50
- error_message = _docker_socket_lib_error_msg socket, host, port, path
51
- begin
52
- Timeout.timeout(1) do
53
- _docker_socket_lib_socket_reachable? socket, host, port, error_message
54
- end
55
- rescue Timeout::Error
56
- log.debug "Timeout: #{error_message}"
57
- false
58
- end
59
- end
60
-
61
- # Create error message.
62
- def _docker_socket_lib_error_msg(socket, host, port, path)
63
- 'failed to connect to ' \
64
- "socket \"#{socket}\" " \
65
- "using host \"#{host}\", " \
66
- "port \"#{port}\", " \
67
- "path \"#{path}\""
68
- end
69
-
70
- # Test socket.
71
- # rubocop:disable Metrics/MethodLength
72
- def _docker_socket_lib_socket_reachable?(socket, host, port, error_message)
73
- begin
74
- s = TCPSocket.new host, port
75
- s.close
76
- log.debug "Socket \"#{socket}\" up"
77
- return true
78
- rescue Errno::ECONNREFUSED
79
- log.debug "Connection refused: #{error_message}"
80
- rescue Errno::EHOSTUNREACH
81
- log.debug "Host unreachable: #{error_message}"
82
- rescue SocketError
83
- log.debug "Socket error: #{error_message}"
84
- end
85
- false
86
- end
87
- # rubocop:enable Metrics/MethodLength
88
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # takelage docker socket scheme
4
- module DockerSocketScheme
5
- # Backend method for docker socket scheme.
6
- def docker_socket_scheme
7
- log.debug 'Getting docker socket scheme'
8
-
9
- gpg_path = _socket_get_agent_socket_path
10
- gpg_port = config.active['docker_socket_gpg_agent_port']
11
- ssh_path = _socket_get_agent_ssh_socket_path
12
- ssh_port = config.active['docker_socket_gpg_ssh_agent_port']
13
-
14
- socket_scheme = _socket_get_scheme gpg_path, gpg_port, ssh_path, ssh_port
15
- log.debug 'Docker socket scheme is ' \
16
- "\n\"\"\"\n#{hash_to_yaml socket_scheme}\"\"\""
17
-
18
- socket_scheme
19
- end
20
-
21
- private
22
-
23
- # Get gpg agent socket path.
24
- def _socket_get_agent_socket_path
25
- cmd_agent_socket_path =
26
- config.active['cmd_docker_socket_config_agent_socket_path']
27
- (run cmd_agent_socket_path).chomp
28
- end
29
-
30
- # Get gpg ssh agent socket path.
31
- def _socket_get_agent_ssh_socket_path
32
- cmd_agent_ssh_socket_path =
33
- config.active['cmd_docker_socket_config_agent_ssh_socket_path']
34
- (run cmd_agent_ssh_socket_path).chomp
35
- end
36
-
37
- # Create socket scheme.
38
- def _socket_get_scheme(gpg_path, gpg_port, ssh_path, ssh_port)
39
- { 'agent-socket' => { 'path' => gpg_path,
40
- 'host' => @socket_host,
41
- 'port' => gpg_port },
42
- 'agent-ssh-socket' => { 'path' => ssh_path,
43
- 'host' => @socket_host,
44
- 'port' => ssh_port } }
45
- end
46
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # takelage docker socket start
4
- module DockerSocketStart
5
- # Backend method for docker socket start.
6
- def docker_socket_start
7
- log.debug 'Starting sockets for docker container'
8
-
9
- return false unless docker_check_daemon
10
-
11
- return false unless command_available? 'socat'
12
-
13
- cmds_start_socket = _docker_socket_lib_get_socket_start_commands 'start'
14
-
15
- return true if cmds_start_socket.empty?
16
-
17
- _docker_socket_start_get_sudo
18
-
19
- cmds_start_socket.each do |cmd_start_socket|
20
- run_and_fork cmd_start_socket
21
- end
22
-
23
- true
24
- end
25
-
26
- private
27
-
28
- # Get sudo.
29
- def _docker_socket_start_get_sudo
30
- log.debug 'Request sudo so that ' \
31
- 'subsequent background tasks run without delay'
32
- cmd_sudo_true =
33
- config.active['cmd_docker_socket_start_sudo_true']
34
- run cmd_sudo_true
35
- end
36
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # takelage docker socket stop
4
- module DockerSocketStop
5
- # Backend method for docker socket stop.
6
- def docker_socket_stop
7
- log.debug 'Stopping sockets for docker container'
8
-
9
- return false unless docker_check_daemon
10
-
11
- return false unless command_available? 'socat'
12
-
13
- # get process list
14
- # assuming format: "pid command"
15
- cmd_ps = config.active['cmd_docker_socket_stop_docker_socket_ps']
16
-
17
- stdout_str = run cmd_ps
18
-
19
- cmds_start_socket = _docker_socket_lib_get_socket_start_commands 'stop'
20
-
21
- # loop over process list
22
- stdout_str.split(/\n+/).each do |process|
23
- _docker_socket_stop_kill_process process, cmds_start_socket
24
- end
25
-
26
- true
27
- end
28
-
29
- private
30
-
31
- # Stop process.
32
- def _docker_socket_stop_kill_process(process, cmds_start_socket)
33
- # split processes in process id and process command
34
- pid_command = process.chomp.split(/ /, 2)
35
- pid = pid_command[0]
36
- command = pid_command[1]
37
-
38
- # loop over socket start commands
39
- cmds_start_socket.each do |cmd_start_socket|
40
- next unless command == cmd_start_socket
41
-
42
- _docker_socket_stop_kill_pid pid
43
- end
44
- end
45
-
46
- # Kill process.
47
- def _docker_socket_stop_kill_pid(pid)
48
- log.debug "Killing PID #{pid}"
49
- cmd_kill =
50
- format(
51
- config.active['cmd_docker_socket_stop_docker_socket_kill'],
52
- pid: pid
53
- )
54
- run cmd_kill
55
- end
56
- end