takelage 0.13.3 → 0.14.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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/takelage.rb +37 -14
  3. data/lib/takelage/bit/check/cli.rb +1 -1
  4. data/lib/takelage/bit/check/{module.rb → workspace.rb} +2 -2
  5. data/lib/takelage/bit/clipboard/cli.rb +9 -3
  6. data/lib/takelage/bit/clipboard/copy.rb +140 -0
  7. data/lib/takelage/bit/clipboard/lib.rb +153 -0
  8. data/lib/takelage/bit/clipboard/paste.rb +58 -0
  9. data/lib/takelage/bit/clipboard/pull.rb +38 -0
  10. data/lib/takelage/bit/clipboard/push.rb +37 -0
  11. data/lib/takelage/bit/scope/add.rb +55 -0
  12. data/lib/takelage/bit/scope/cli.rb +7 -3
  13. data/lib/takelage/bit/scope/inbit.rb +13 -0
  14. data/lib/takelage/bit/scope/list.rb +41 -0
  15. data/lib/takelage/bit/scope/new.rb +44 -0
  16. data/lib/takelage/default.yml +4 -3
  17. data/lib/takelage/docker/check/cli.rb +1 -1
  18. data/lib/takelage/docker/check/{module.rb → running.rb} +2 -2
  19. data/lib/takelage/docker/container/check/cli.rb +4 -2
  20. data/lib/takelage/docker/container/check/existing.rb +31 -0
  21. data/lib/takelage/docker/container/check/network.rb +31 -0
  22. data/lib/takelage/docker/container/check/orphaned.rb +31 -0
  23. data/lib/takelage/docker/container/cli.rb +35 -34
  24. data/lib/takelage/docker/container/command.rb +33 -0
  25. data/lib/takelage/docker/container/daemon.rb +13 -0
  26. data/lib/takelage/docker/container/lib.rb +149 -0
  27. data/lib/takelage/docker/container/login.rb +46 -0
  28. data/lib/takelage/docker/container/nuke.rb +39 -0
  29. data/lib/takelage/docker/container/purge.rb +30 -0
  30. data/lib/takelage/docker/image/check/cli.rb +4 -4
  31. data/lib/takelage/docker/image/check/{module.rb → outdated.rb} +4 -5
  32. data/lib/takelage/docker/image/cli.rb +4 -4
  33. data/lib/takelage/docker/image/tag/check/cli.rb +4 -3
  34. data/lib/takelage/docker/image/tag/check/{module.rb → local.rb} +2 -34
  35. data/lib/takelage/docker/image/tag/check/remote.rb +38 -0
  36. data/lib/takelage/docker/image/tag/latest/cli.rb +5 -3
  37. data/lib/takelage/docker/image/tag/latest/local.rb +20 -0
  38. data/lib/takelage/docker/image/tag/latest/{module.rb → remote.rb} +2 -18
  39. data/lib/takelage/docker/image/tag/list/cli.rb +3 -2
  40. data/lib/takelage/docker/image/tag/list/local.rb +19 -0
  41. data/lib/takelage/docker/image/tag/list/{module.rb → remote.rb} +2 -17
  42. data/lib/takelage/docker/image/{module.rb → update.rb} +2 -2
  43. data/lib/takelage/docker/socket/cli.rb +6 -2
  44. data/lib/takelage/docker/socket/host.rb +25 -0
  45. data/lib/takelage/docker/socket/lib.rb +88 -0
  46. data/lib/takelage/docker/socket/scheme.rb +46 -0
  47. data/lib/takelage/docker/socket/start.rb +34 -0
  48. data/lib/takelage/docker/socket/stop.rb +55 -0
  49. data/lib/takelage/git/check/clean.rb +46 -0
  50. data/lib/takelage/git/check/cli.rb +3 -1
  51. data/lib/takelage/git/check/master.rb +26 -0
  52. data/lib/takelage/git/check/workspace.rb +33 -0
  53. data/lib/takelage/self/cli.rb +1 -1
  54. data/lib/takelage/self/{module.rb → list.rb} +2 -2
  55. data/lib/takelage/version +1 -1
  56. metadata +38 -15
  57. data/lib/takelage/bit/clipboard/module.rb +0 -401
  58. data/lib/takelage/bit/scope/module.rb +0 -122
  59. data/lib/takelage/docker/container/check/module.rb +0 -81
  60. data/lib/takelage/docker/container/module.rb +0 -295
  61. data/lib/takelage/docker/socket/module.rb +0 -227
  62. data/lib/takelage/git/check/module.rb +0 -93
@@ -1,227 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # takelage docker socket module
4
- module DockerSocketModule
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
- # Backend method for docker socket host.
22
- def docker_socket_host
23
- log.debug 'Getting docker socket host ip address'
24
-
25
- socket_host = '127.0.0.1'
26
-
27
- addr_infos = Socket.getifaddrs
28
-
29
- # if interface docker0 exists (== linux host)
30
- # then return the ip address
31
- addr_infos.each do |addr_info|
32
- if addr_info.name == 'docker0'
33
- socket_host = addr_info.addr.ip_address if addr_info.addr.ipv4?
34
- end
35
- end
36
-
37
- log.debug "Docker socket host ip address is \"#{socket_host}\""
38
-
39
- socket_host
40
- end
41
-
42
- # Backend method for docker socket start.
43
- def docker_socket_start
44
- log.debug 'Starting sockets for docker container'
45
-
46
- return false unless docker_check_running
47
-
48
- cmds_start_socket = _get_socket_start_commands 'start'
49
-
50
- return true if cmds_start_socket.empty?
51
-
52
- _socket_get_sudo
53
-
54
- cmds_start_socket.each do |cmd_start_socket|
55
- run_and_fork cmd_start_socket
56
- end
57
-
58
- true
59
- end
60
-
61
- # Backend method for docker socket stop.
62
- def docker_socket_stop
63
- log.debug 'Stopping sockets for docker container'
64
-
65
- return false unless docker_check_running
66
-
67
- # get process list
68
- # assuming format: "pid command"
69
- cmd_ps =
70
- config.active['cmd_docker_socket_stop_docker_socket_ps']
71
-
72
- stdout_str = run cmd_ps
73
-
74
- cmds_start_socket = _get_socket_start_commands 'stop'
75
-
76
- # loop over process list
77
- stdout_str.split(/\n+/).each do |process|
78
- _socket_stop_process process, cmds_start_socket
79
- end
80
-
81
- true
82
- end
83
-
84
- private
85
-
86
- # Get gpg agent socket path.
87
- def _socket_get_agent_socket_path
88
- cmd_agent_socket_path =
89
- config.active['cmd_docker_socket_config_agent_socket_path']
90
- (run cmd_agent_socket_path).chomp
91
- end
92
-
93
- # Get gpg ssh agent socket path.
94
- def _socket_get_agent_ssh_socket_path
95
- cmd_agent_ssh_socket_path =
96
- config.active['cmd_docker_socket_config_agent_ssh_socket_path']
97
- (run cmd_agent_ssh_socket_path).chomp
98
- end
99
-
100
- # Create socket scheme.
101
- def _socket_get_scheme(gpg_path, gpg_port, ssh_path, ssh_port)
102
- { 'agent-socket' => { 'path' => gpg_path,
103
- 'host' => @socket_host,
104
- 'port' => gpg_port },
105
- 'agent-ssh-socket' => { 'path' => ssh_path,
106
- 'host' => @socket_host,
107
- 'port' => ssh_port } }
108
- end
109
-
110
- # Get socket start commands.
111
- # sockets_up is a boolean which defines if the sockets need to be up
112
- # to be included in the resulting array of socket start commands
113
- def _get_socket_start_commands(mode)
114
- cmds_start_socket = []
115
-
116
- # loop over sockets
117
- @sockets.each do |socket, socket_config|
118
- host = socket_config['host']
119
- port = socket_config['port']
120
- path = socket_config['path']
121
-
122
- cmd = _get_socket_start_command mode, socket, host, port, path
123
- cmds_start_socket.push cmd if cmd
124
- end
125
-
126
- cmds_start_socket
127
- end
128
-
129
- # Get socket start command
130
- def _get_socket_start_command(mode, socket, host, port, path)
131
- if mode == 'start'
132
- unless _socket_up? socket, host, port, path
133
- return _socket_get_cmd_start_socket(host, port, path)
134
- end
135
- elsif _socket_up? socket, host, port, path
136
- return _socket_get_cmd_start_socket(host, port, path)
137
- end
138
- nil
139
- end
140
-
141
- # Get socket start command.
142
- def _socket_get_cmd_start_socket(host, port, path)
143
- format(
144
- config.active['cmd_docker_socket_get_start'],
145
- host: host,
146
- port: port,
147
- path: path
148
- )
149
- end
150
-
151
- # Check if a socket is available by trying to connect to it via TCP
152
- def _socket_up?(socket, host, port, path)
153
- error_message = _socket_get_error_message socket, host, port, path
154
- begin
155
- Timeout.timeout(1) do
156
- _socket_reachable? socket, host, port, error_message
157
- end
158
- rescue Timeout::Error
159
- log.debug "Timeout: #{error_message}"
160
- false
161
- end
162
- end
163
-
164
- # Create error message.
165
- def _socket_get_error_message(socket, host, port, path)
166
- 'failed to connect to ' \
167
- "socket \"#{socket}\" " \
168
- "using host \"#{host}\", " \
169
- "port \"#{port}\", " \
170
- "path \"#{path}\""
171
- end
172
-
173
- # Test socket.
174
- # rubocop:disable Metrics/MethodLength
175
- def _socket_reachable?(socket, host, port, error_message)
176
- begin
177
- s = TCPSocket.new host, port
178
- s.close
179
- log.debug "Socket \"#{socket}\" up"
180
- return true
181
- rescue Errno::ECONNREFUSED
182
- log.debug "Connection refused: #{error_message}"
183
- rescue Errno::EHOSTUNREACH
184
- log.debug "Host unreachable: #{error_message}"
185
- rescue SocketError
186
- log.debug "Socket error: #{error_message}"
187
- end
188
- false
189
- end
190
-
191
- # rubocop:enable Metrics/MethodLength
192
-
193
- # Kill process.
194
- def _socket_kill_pid(pid)
195
- log.debug "Killing PID #{pid}"
196
- cmd_kill =
197
- format(
198
- config.active['cmd_docker_socket_stop_docker_socket_kill'],
199
- pid: pid
200
- )
201
- run cmd_kill
202
- end
203
-
204
- # Get sudo.
205
- def _socket_get_sudo
206
- log.debug 'Request sudo so that ' \
207
- 'subsequent background tasks run without delay'
208
- cmd_sudo_true =
209
- config.active['cmd_docker_socket_start_sudo_true']
210
- run cmd_sudo_true
211
- end
212
-
213
- # Stop process.
214
- def _socket_stop_process(process, cmds_start_socket)
215
- # split processes in process id and process command
216
- pid_command = process.strip.split(/ /, 2)
217
- pid = pid_command[0]
218
- command = pid_command[1]
219
-
220
- # loop over socket start commands
221
- cmds_start_socket.each do |cmd_start_socket|
222
- next unless command == cmd_start_socket
223
-
224
- _socket_kill_pid pid
225
- end
226
- end
227
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # takelage git check module
4
- module GitCheckModule
5
- # Backend method for git check clean.
6
- # @return [Boolean] is git workspace clean?
7
- def git_check_clean
8
- log.debug 'Checking if git workspace is clean'
9
-
10
- return false unless git_check_workspace
11
-
12
- status_unstaged = _git_get_status_unstaged
13
- status_uncommitted = _git_get_status_uncommitted
14
- stdout_str_status = _git_get_str_status
15
-
16
- # only return true if neither unstaged nor uncommitted nor empty files
17
- sum = status_unstaged.exitstatus +
18
- status_uncommitted.exitstatus +
19
- stdout_str_status.length
20
-
21
- sum.zero?
22
- end
23
-
24
- # Backend method for git check master.
25
- # @return [Boolean] are we on the git master branch?
26
- def git_check_master
27
- log.debug 'Check if we are on the git master branch'
28
-
29
- return false unless git_check_workspace
30
-
31
- branch = _git_get_branch
32
- log.debug "We are on git branch \"#{branch}\""
33
-
34
- branch == 'master'
35
- end
36
-
37
- # Backend method for git check workspace.
38
- # @return [Boolean] is this a git workspace?
39
- def git_check_workspace
40
- log.debug 'Check if this is a git workspace'
41
- status_repo = _git_get_status_repo
42
- dir = _git_get_dir
43
- unless status_repo.exitstatus.zero?
44
- log.debug "No git workspace found in \"#{dir}\""
45
- return false
46
- end
47
- true
48
- end
49
-
50
- private
51
-
52
- # Get git status of unstaged changes.
53
- def _git_get_status_unstaged
54
- cmd_git_unstaged =
55
- config.active['cmd_git_check_clean_git_unstaged']
56
- try cmd_git_unstaged
57
- end
58
-
59
- # Get git status of uncommitted changes.
60
- def _git_get_status_uncommitted
61
- cmd_git_uncommitted =
62
- config.active['cmd_git_check_clean_git_uncommitted']
63
- try cmd_git_uncommitted
64
- end
65
-
66
- # Get git status result.
67
- def _git_get_str_status
68
- cmd_git_status =
69
- config.active['cmd_git_check_clean_git_status']
70
- run cmd_git_status
71
- end
72
-
73
- # Get git branch.
74
- def _git_get_branch
75
- cmd_get_branch =
76
- config.active['cmd_git_check_master_git_branch']
77
- (run cmd_get_branch).strip.split('/')[-1]
78
- end
79
-
80
- # Get git repository status.
81
- def _git_get_status_repo
82
- cmd_git_repo =
83
- config.active['cmd_git_check_workspace_git_repo']
84
- try cmd_git_repo
85
- end
86
-
87
- # Get current working directory.
88
- def _git_get_dir
89
- cmd_pwd =
90
- config.active['cmd_git_check_workspace_pwd']
91
- (run cmd_pwd).strip
92
- end
93
- end