takelage 0.28.8 → 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 +4 -4
- data/README.md +2 -6
- data/lib/takelage.rb +6 -10
- data/lib/takelage/default.yml +6 -11
- data/lib/takelage/docker/check/cli.rb +0 -13
- data/lib/takelage/docker/check/daemon.rb +6 -2
- data/lib/takelage/docker/cli.rb +0 -3
- data/lib/takelage/docker/container/check/cli.rb +0 -1
- data/lib/takelage/docker/container/clean.rb +1 -1
- data/lib/takelage/docker/container/cli.rb +5 -8
- data/lib/takelage/docker/container/command.rb +1 -2
- data/lib/takelage/docker/container/daemon.rb +1 -1
- data/lib/takelage/docker/container/lib.rb +9 -7
- data/lib/takelage/docker/container/login.rb +1 -3
- data/lib/takelage/info/status/bar.rb +6 -0
- data/lib/takelage/info/status/cli.rb +2 -4
- data/lib/takelage/info/status/ssh.rb +6 -1
- data/lib/takelage/lib/system.rb +39 -3
- data/lib/takelage/mutagen/check/cli.rb +2 -4
- data/lib/takelage/mutagen/check/daemon.rb +45 -6
- data/lib/takelage/mutagen/socket/check.rb +2 -0
- data/lib/takelage/mutagen/socket/cli.rb +22 -13
- data/lib/takelage/mutagen/socket/create.rb +15 -7
- data/lib/takelage/mutagen/socket/list.rb +2 -0
- data/lib/takelage/mutagen/socket/terminate.rb +2 -3
- data/lib/takelage/mutagen/socket/tidy.rb +21 -0
- data/lib/takelage/version +1 -1
- metadata +2 -8
- data/lib/takelage/docker/check/socat.rb +0 -23
- data/lib/takelage/docker/socket/cli.rb +0 -76
- data/lib/takelage/docker/socket/host.rb +0 -34
- data/lib/takelage/docker/socket/lib.rb +0 -88
- data/lib/takelage/docker/socket/scheme.rb +0 -46
- data/lib/takelage/docker/socket/start.rb +0 -36
- data/lib/takelage/docker/socket/stop.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4ad578971e04ab78238e26f456f1071a39dcd57ca40d08cb63f78623dbba13f
|
4
|
+
data.tar.gz: 5bc6aaf8d1d7b37ab684da509c766d040d12d37a88cc301ee24405110f4b0631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38d06e826c104089e3a134a7e6ce9660893f1cd2f8f103cdf2771d84ad4a82e2eda8e6dd7578da0452a98a4e808b0e55393798ac363c89d4960d34ebb83390e3
|
7
|
+
data.tar.gz: 5a98640e8c71d0be3a730de18d75e86f890e812498e53a1a7e0bb73d90536f36add90d80abc89ea06cdbfb99b208ead667aecc91f4e524b2245b68356c92f7e3
|
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
|
@@ -91,10 +90,6 @@ tau [docker image tag check](features/cucumber/features/docker/docker.image.tag.
|
|
91
90
|
tau [docker image tag latest](features/cucumber/features/docker/docker.image.tag.latest.feature) | Print latest local docker image tag
|
92
91
|
tau [docker image tag list](features/cucumber/features/docker/docker.image.tag.list.feature) | Print local docker image tags
|
93
92
|
tau [docker image update](features/cucumber/features/docker/docker.image.update.feature) | Get latest remote docker container
|
94
|
-
tau [docker socket host](features/cucumber/features/docker/docker.socket.host.feature) | Print docker socket host ip address
|
95
|
-
tau [docker socket scheme](features/cucumber/features/docker/docker.socket.scheme.feature) | Print docker socket scheme
|
96
|
-
tau [docker socket start](features/cucumber/features/docker/docker.socket.start.feature) | Start sockets for docker container
|
97
|
-
tau [docker socket stop](features/cucumber/features/docker/docker.socket.stop.feature) | Stop sockets for docker container
|
98
93
|
tau [git check clean](features/cucumber/features/git/git.check.clean.feature) | Check if the git workspace is clean
|
99
94
|
tau [git check main](features/cucumber/features/git/git.check.main.feature) | Check if we are on the git main branch
|
100
95
|
tau [git check workspace](features/cucumber/features/git/git.check.workspace.feature) | Check if a git workspace exists
|
@@ -110,8 +105,9 @@ tau [info status mutagen](features/cucumber/features/info/info.status.mutagen.fe
|
|
110
105
|
tau [info status ssh](features/cucumber/features/info/info.status.ssh.feature) | Check ssh status
|
111
106
|
tau [mutagen check daemon](features/cucumber/features/mutagen/mutagen.check.daemon.feature)) | Check if mutagen host conenction is available
|
112
107
|
tau [mutagen socket check](features/cucumber/features/mutagen/mutagen.socket.check.feature) [SOCKET] | Check if mutagen [SOCKET] exists
|
113
|
-
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
|
114
109
|
tau [mutagen socket list](features/cucumber/features/mutagen/mutagen.socket.list.feature) | List mutagen sockets
|
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
|
116
112
|
tau [self config active](features/cucumber/features/self/self.config.active.feature) | Print active takelage configuration
|
117
113
|
tau [self config default](features/cucumber/features/self/self.config.default.feature) | Print takelage default configuration
|
data/lib/takelage.rb
CHANGED
@@ -44,17 +44,13 @@ 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/check'
|
47
49
|
require_relative 'takelage/mutagen/socket/create'
|
48
50
|
require_relative 'takelage/mutagen/socket/terminate'
|
51
|
+
require_relative 'takelage/mutagen/socket/tidy'
|
49
52
|
require_relative 'takelage/docker/check/daemon'
|
50
|
-
require_relative 'takelage/docker/check/socat'
|
51
53
|
require_relative 'takelage/docker/check/cli'
|
52
|
-
require_relative 'takelage/docker/socket/lib'
|
53
|
-
require_relative 'takelage/docker/socket/host'
|
54
|
-
require_relative 'takelage/docker/socket/scheme'
|
55
|
-
require_relative 'takelage/docker/socket/start'
|
56
|
-
require_relative 'takelage/docker/socket/stop'
|
57
|
-
require_relative 'takelage/docker/socket/cli'
|
58
54
|
require_relative 'takelage/docker/image/tag/list'
|
59
55
|
require_relative 'takelage/docker/image/tag/latest'
|
60
56
|
require_relative 'takelage/docker/image/tag/check'
|
@@ -73,9 +69,7 @@ require_relative 'takelage/docker/container/clean'
|
|
73
69
|
require_relative 'takelage/docker/container/prune'
|
74
70
|
require_relative 'takelage/docker/container/cli'
|
75
71
|
require_relative 'takelage/docker/cli'
|
76
|
-
require_relative 'takelage/mutagen/check/daemon'
|
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
|
-
@
|
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
|
data/lib/takelage/default.yml
CHANGED
@@ -30,11 +30,10 @@ 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'
|
37
|
-
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 %{
|
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}'
|
38
37
|
cmd_docker_container_create_network: 'docker network create %{network}'
|
39
38
|
cmd_docker_container_enter_container: 'docker exec --interactive --tty %{container} %{loginpoint} --username %{username}'
|
40
39
|
cmd_docker_container_get_container_name: 'docker ps --filter id=%{container} --format "{{.Names}}"'
|
@@ -46,12 +45,6 @@ cmd_docker_image_tag_check_docker_images: 'docker images --quiet %{image}'
|
|
46
45
|
cmd_docker_image_tag_list_docker_images: 'docker images %{docker_user}\/%{docker_repo} --format "{{.Tag}}"'
|
47
46
|
cmd_docker_image_update_docker_pull_latest: 'docker pull %{docker_user}/%{docker_repo}:latest'
|
48
47
|
cmd_docker_image_update_docker_remove_dangling: 'docker image prune --force'
|
49
|
-
cmd_docker_socket_config_agent_socket_path: 'gpgconf --list-dirs agent-socket'
|
50
|
-
cmd_docker_socket_config_agent_ssh_socket_path: 'gpgconf --list-dirs agent-ssh-socket'
|
51
|
-
cmd_docker_socket_get_start: 'sudo socat TCP-LISTEN:%{port},bind=%{host},reuseaddr,fork UNIX-CLIENT:%{path}'
|
52
|
-
cmd_docker_socket_start_sudo_true: 'sudo true'
|
53
|
-
cmd_docker_socket_stop_docker_socket_ps: 'sudo ps a -o pid,command'
|
54
|
-
cmd_docker_socket_stop_docker_socket_kill: 'sudo kill -SIGTERM %{pid}'
|
55
48
|
cmd_git_check_clean_git_unstaged: 'git diff --exit-code'
|
56
49
|
cmd_git_check_clean_git_uncommitted: 'git diff --cached --exit-code'
|
57
50
|
cmd_git_check_clean_git_status: 'git status --porcelain'
|
@@ -66,7 +59,9 @@ cmd_info_status_gopass_root_store: 'gopass config | grep "path" | cut -d " " -f
|
|
66
59
|
cmd_info_status_gpg_agent: 'gpg-connect-agent /bye'
|
67
60
|
cmd_info_status_gpg_keys: 'gpg --list-keys'
|
68
61
|
cmd_info_status_ssh_keys: 'ssh-add -l'
|
62
|
+
cmd_info_status_ssh_socket: 'gpgconf --list-dirs agent-ssh-socket'
|
69
63
|
cmd_mutagen_check_daemon_host_connection: 'mutagen forward list --label-selector="%{hostlabel}"'
|
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}'
|
71
66
|
cmd_mutagen_forward_socket_check: 'mutagen forward list %{socketname}'
|
72
67
|
cmd_mutagen_forward_socket_terminate: 'mutagen forward terminate %{socketname}'
|
@@ -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
|
-
|
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'
|
@@ -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
|
3
|
+
# takelage docker check daemon
|
4
4
|
module DockerCheckDaemon
|
5
|
-
# Backend method for docker check
|
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
|
data/lib/takelage/docker/cli.rb
CHANGED
@@ -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
|
@@ -20,10 +19,8 @@ module Takelage
|
|
20
19
|
include DockerImageTagLatest
|
21
20
|
include DockerImageTagList
|
22
21
|
include DockerImageTagCheck
|
23
|
-
include
|
24
|
-
include
|
25
|
-
include DockerSocketScheme
|
26
|
-
include DockerSocketStart
|
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
|
-
@
|
47
|
-
@
|
48
|
-
@
|
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
|
-
|
13
|
+
_docker_container_lib_start_sockets
|
15
14
|
|
16
15
|
_docker_container_command_run_command @hostname, command
|
17
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
|
-
|
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}")
|
@@ -7,14 +7,10 @@ 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
|
14
13
|
include DockerContainerLib
|
15
|
-
include DockerSocketLib
|
16
|
-
include DockerSocketScheme
|
17
|
-
include DockerSocketStart
|
18
14
|
include GitCheckWorkspace
|
19
15
|
include InfoStatusLib
|
20
16
|
include InfoStatusGit
|
@@ -29,6 +25,8 @@ module Takelage
|
|
29
25
|
# initialize thor parent class
|
30
26
|
super args, local_options, configuration
|
31
27
|
|
28
|
+
@workdir = Dir.getwd
|
29
|
+
|
32
30
|
inside = _docker_container_lib_check_matrjoschka
|
33
31
|
@hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
|
34
32
|
@hostlabel = "hostname=#{@hostname}"
|
@@ -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 =
|
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']
|
data/lib/takelage/lib/system.rb
CHANGED
@@ -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
|
-
|
80
|
-
log.debug "Command \"#{command}\" has
|
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
|
|
@@ -128,3 +163,4 @@ module SystemModule
|
|
128
163
|
true
|
129
164
|
end
|
130
165
|
end
|
166
|
+
# rubocop:enable Metrics/ModuleLength
|
@@ -7,14 +7,10 @@ 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
|
14
13
|
include DockerContainerLib
|
15
|
-
include DockerSocketLib
|
16
|
-
include DockerSocketScheme
|
17
|
-
include DockerSocketStart
|
18
14
|
include MutagenCheckDaemon
|
19
15
|
|
20
16
|
# Initialize mutagen check
|
@@ -22,6 +18,8 @@ module Takelage
|
|
22
18
|
# initialize thor parent class
|
23
19
|
super args, local_options, configuration
|
24
20
|
|
21
|
+
@workdir = Dir.getwd
|
22
|
+
|
25
23
|
inside = _docker_container_lib_check_matrjoschka
|
26
24
|
@hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
|
27
25
|
@hostlabel = "hostname=#{@hostname}"
|
@@ -5,33 +5,72 @@ module MutagenCheckDaemon
|
|
5
5
|
# Backend method for mutagen check daemon.
|
6
6
|
# @return [Boolean] is mutagen available?
|
7
7
|
# rubocop:disable Metrics/MethodLength
|
8
|
+
# rubocop:disable Metrics/AbcSize
|
8
9
|
def mutagen_check_daemon
|
10
|
+
return true if @mutagen_daemon_available
|
11
|
+
|
12
|
+
return false unless command_available? 'mutagen'
|
13
|
+
|
9
14
|
log.debug 'Check mutagen status'
|
10
15
|
|
11
|
-
|
12
|
-
|
16
|
+
# are we outside of a takelage container?
|
17
|
+
unless _docker_container_lib_check_matrjoschka
|
18
|
+
unless _mutagen_check_daemon_version
|
19
|
+
log.error 'The mutagen daemon is not available'
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
|
23
|
+
log.debug 'The mutagen daemon is available'
|
24
|
+
@mutagen_daemon_available = true
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
|
28
|
+
unless _file_exists? config.active['mutagen_socket_path_mutagen']
|
29
|
+
log.error 'The mutagen socket is not available'
|
13
30
|
return false
|
14
31
|
end
|
15
32
|
|
16
33
|
unless _mutagen_check_daemon_host_connection
|
17
|
-
log.error 'mutagen host connection is not available'
|
34
|
+
log.error 'A mutagen host connection is not available'
|
18
35
|
return false
|
19
36
|
end
|
20
37
|
|
21
|
-
log.debug 'mutagen is available'
|
38
|
+
log.debug 'The mutagen daemon is available'
|
39
|
+
@mutagen_daemon_available = true
|
22
40
|
true
|
23
41
|
end
|
42
|
+
# rubocop:enable Metrics/AbcSize
|
24
43
|
# rubocop:enable Metrics/MethodLength
|
25
44
|
|
26
45
|
private
|
27
46
|
|
28
47
|
# Check mutagen host connection
|
48
|
+
# rubocop:disable Metrics/MethodLength
|
29
49
|
def _mutagen_check_daemon_host_connection
|
30
50
|
check_host_connection = format(
|
31
51
|
config.active['cmd_mutagen_check_daemon_host_connection'],
|
32
52
|
hostlabel: @hostlabel
|
33
53
|
)
|
34
|
-
|
35
|
-
|
54
|
+
stdout, _, exitstatus = run_and_capture check_host_connection
|
55
|
+
|
56
|
+
unless exitstatus.zero?
|
57
|
+
log.debug 'There is no mutagen forward connection to the host'
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
|
61
|
+
unless stdout.include? 'Status: Forwarding connections'
|
62
|
+
log.debug 'The mutagen forward connection to the host ' \
|
63
|
+
'is not forwarding connections'
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
|
67
|
+
true
|
68
|
+
end
|
69
|
+
# rubocop:enable Metrics/MethodLength
|
70
|
+
|
71
|
+
# Check mutagen version
|
72
|
+
def _mutagen_check_daemon_version
|
73
|
+
version = try config.active['cmd_mutagen_check_daemon_version']
|
74
|
+
version.exitstatus.zero?
|
36
75
|
end
|
37
76
|
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,17 +7,18 @@ 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
|
14
13
|
include DockerContainerLib
|
15
|
-
include
|
16
|
-
include
|
17
|
-
include
|
14
|
+
include DockerImageTagLatest
|
15
|
+
include DockerImageTagList
|
16
|
+
include DockerImageTagCheck
|
17
|
+
include MutagenCheckDaemon
|
18
18
|
include MutagenSocketCheck
|
19
19
|
include MutagenSocketCreate
|
20
20
|
include MutagenSocketList
|
21
|
+
include MutagenSocketTidy
|
21
22
|
include MutagenSocketTerminate
|
22
23
|
|
23
24
|
# Initialize mutagen socket
|
@@ -31,13 +32,9 @@ module Takelage
|
|
31
32
|
|
32
33
|
inside = _docker_container_lib_check_matrjoschka
|
33
34
|
@hostname = inside ? ENV['HOSTNAME'] : _docker_container_lib_hostname
|
34
|
-
# See DockerContainerLib::_docker_container_lib_hostname
|
35
|
-
@socketname = @hostname[-11..-1]
|
36
35
|
|
37
36
|
@hostlabel = "hostname=#{@hostname}"
|
38
37
|
@takellabel = config.active['mutagen_socket_takelage_label']
|
39
|
-
|
40
|
-
@sockets = docker_socket_scheme
|
41
38
|
end
|
42
39
|
|
43
40
|
#
|
@@ -55,13 +52,13 @@ module Takelage
|
|
55
52
|
#
|
56
53
|
# mutagen socket create
|
57
54
|
#
|
58
|
-
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'
|
59
56
|
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
60
|
-
Create a mutagen socket from [IN] to [OUT] of the container
|
57
|
+
Create a mutagen socket [NAME] from [IN] to [OUT] of the container
|
61
58
|
LONGDESC
|
62
|
-
# Create a mutagen socket from [IN] to [OUT] of the container.
|
63
|
-
def create(containersock, hostsock)
|
64
|
-
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
|
65
62
|
end
|
66
63
|
|
67
64
|
#
|
@@ -90,5 +87,17 @@ module Takelage
|
|
90
87
|
def terminate(socket)
|
91
88
|
exit mutagen_socket_terminate socket
|
92
89
|
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# mutagen socket tidy
|
93
|
+
#
|
94
|
+
desc 'tidy', 'Remove mutagen daemon files'
|
95
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
96
|
+
Remove mutagen daemon files
|
97
|
+
LONGDESC
|
98
|
+
# Remove mutagen daemon files.
|
99
|
+
def tidy
|
100
|
+
exit mutagen_socket_tidy
|
101
|
+
end
|
93
102
|
end
|
94
103
|
end
|
@@ -3,29 +3,37 @@
|
|
3
3
|
# takelage mutagen socket create
|
4
4
|
module MutagenSocketCreate
|
5
5
|
# Backend method for mutagen socket create.
|
6
|
-
|
7
|
-
|
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
|
14
|
+
|
15
|
+
return false if mutagen_socket_check socketname
|
16
|
+
|
17
|
+
socket_created = _mutagen_socket_create_socket(socketname, containersock, hostsock)
|
11
18
|
|
12
19
|
unless socket_created.include? 'Created session'
|
13
|
-
log.debug "Unable to create mutagen socket \"#{
|
20
|
+
log.debug "Unable to create mutagen socket \"#{socketname}\""
|
14
21
|
return false
|
15
22
|
end
|
16
23
|
|
17
|
-
log.debug "Created the mutagen socket \"#{
|
24
|
+
log.debug "Created the mutagen socket \"#{socketname}\""
|
18
25
|
true
|
19
26
|
end
|
27
|
+
# rubocop:enable Metrics/MethodLength
|
20
28
|
|
21
29
|
private
|
22
30
|
|
23
31
|
# Get git branch.
|
24
32
|
# rubocop:disable Metrics/MethodLength
|
25
|
-
def _mutagen_socket_create_socket(containersock, hostsock)
|
33
|
+
def _mutagen_socket_create_socket(socketname, containersock, hostsock)
|
26
34
|
cmd_create_socket = format(
|
27
35
|
config.active['cmd_mutagen_forward_socket_create'],
|
28
|
-
socketname:
|
36
|
+
socketname: socketname,
|
29
37
|
containersock: containersock,
|
30
38
|
hostsock: hostsock,
|
31
39
|
username: @username,
|
@@ -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
|
-
|
9
|
+
return false unless mutagen_check_daemon
|
10
10
|
|
11
|
-
|
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.
|
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.
|
4
|
+
version: 0.29.0
|
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
|
@@ -246,12 +245,6 @@ files:
|
|
246
245
|
- lib/takelage/docker/image/tag/latest.rb
|
247
246
|
- lib/takelage/docker/image/tag/list.rb
|
248
247
|
- lib/takelage/docker/image/update.rb
|
249
|
-
- lib/takelage/docker/socket/cli.rb
|
250
|
-
- lib/takelage/docker/socket/host.rb
|
251
|
-
- lib/takelage/docker/socket/lib.rb
|
252
|
-
- lib/takelage/docker/socket/scheme.rb
|
253
|
-
- lib/takelage/docker/socket/start.rb
|
254
|
-
- lib/takelage/docker/socket/stop.rb
|
255
248
|
- lib/takelage/git/check/clean.rb
|
256
249
|
- lib/takelage/git/check/cli.rb
|
257
250
|
- lib/takelage/git/check/main.rb
|
@@ -279,6 +272,7 @@ files:
|
|
279
272
|
- lib/takelage/mutagen/socket/create.rb
|
280
273
|
- lib/takelage/mutagen/socket/list.rb
|
281
274
|
- lib/takelage/mutagen/socket/terminate.rb
|
275
|
+
- lib/takelage/mutagen/socket/tidy.rb
|
282
276
|
- lib/takelage/self/cli.rb
|
283
277
|
- lib/takelage/self/config/cli.rb
|
284
278
|
- 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
|
@@ -1,76 +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 DockerCheckSocat
|
11
|
-
include DockerSocketLib
|
12
|
-
include DockerSocketHost
|
13
|
-
include DockerSocketScheme
|
14
|
-
include DockerSocketStart
|
15
|
-
include DockerSocketStop
|
16
|
-
|
17
|
-
# Initialize docker socket
|
18
|
-
def initialize(args = [], local_options = {}, configuration = {})
|
19
|
-
# initialize thor parent class
|
20
|
-
super args, local_options, configuration
|
21
|
-
|
22
|
-
@socket_host = docker_socket_host
|
23
|
-
@sockets = docker_socket_scheme
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# docker socket host
|
28
|
-
#
|
29
|
-
desc 'host', 'Print docker socket host ip address'
|
30
|
-
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
31
|
-
Print docker socket host ip address
|
32
|
-
LONGDESC
|
33
|
-
# Print docker socket host ip address.
|
34
|
-
def host
|
35
|
-
say @socket_host
|
36
|
-
true
|
37
|
-
end
|
38
|
-
|
39
|
-
#
|
40
|
-
# docker socket scheme
|
41
|
-
#
|
42
|
-
desc 'scheme', 'Print docker socket scheme'
|
43
|
-
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
44
|
-
Print docker socket scheme
|
45
|
-
LONGDESC
|
46
|
-
# Print docker socket scheme.
|
47
|
-
def scheme
|
48
|
-
say hash_to_yaml(@sockets)
|
49
|
-
true
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
# docker socket start
|
54
|
-
#
|
55
|
-
desc 'start', 'Start sockets for docker container'
|
56
|
-
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
57
|
-
Start sockets for docker container
|
58
|
-
LONGDESC
|
59
|
-
# Start sockets for docker container.
|
60
|
-
def start
|
61
|
-
exit docker_socket_start
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# docker socket stop
|
66
|
-
#
|
67
|
-
desc 'stop', 'Stop sockets for docker container'
|
68
|
-
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
69
|
-
Stop sockets for docker container
|
70
|
-
LONGDESC
|
71
|
-
# Stop sockets for docker container.
|
72
|
-
def stop
|
73
|
-
exit docker_socket_stop
|
74
|
-
end
|
75
|
-
end
|
76
|
-
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 docker_check_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 docker_check_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
|