takeltau 0.44.2 → 0.44.8
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/lib/takeltau/default.yml +1 -2
- data/lib/takeltau/lib/system.rb +7 -0
- data/lib/takeltau/ship/cli.rb +3 -0
- data/lib/takeltau/ship/container/lib.rb +12 -4
- data/lib/takeltau/ship/container/stop.rb +1 -0
- data/lib/takeltau/ship/info/lib.rb +3 -0
- data/lib/takeltau/ship/ports/cli.rb +24 -0
- data/lib/takeltau/ship/ports/lib.rb +124 -0
- data/lib/takeltau/ship/ports/list.rb +16 -0
- data/lib/takeltau/ship/project/cli.rb +3 -1
- data/lib/takeltau/ship/project/start.rb +59 -28
- data/lib/takeltau/version +1 -1
- data/lib/takeltau.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0265577b0c7fe802841470d93b7df218162928a825b3c360e0c7fa5c16d10810
|
4
|
+
data.tar.gz: 39143047fc8490a50a8bef1c967ddf7ee61396e5f8a1f198f7aac0ab803c9ffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d28bb37c89010cbba5c0a0061b6d349bfe3e1c1235c5fc1e3ecab38db85518583c86059f0d457362ef1f0c4fb25fdb6d24593b98579e15df914876f4e04a9b89
|
7
|
+
data.tar.gz: 06c7e2e98e681c7a28cc03ddbfef9cff9c21481db11446c8067ef5e9962c56ee1c55506d436a728dd1949323c51aeb1127ec7cdf32c7c4d561826739d6daa0df
|
data/lib/takeltau/default.yml
CHANGED
@@ -61,10 +61,10 @@ cmd_ship_container_docker: '%{ship_docker} exec --interactive %{tty} %{ship_host
|
|
61
61
|
cmd_ship_container_login: 'bash'
|
62
62
|
cmd_ship_docker: 'docker'
|
63
63
|
cmd_ship_docker_check: 'docker --version'
|
64
|
+
cmd_ship_project_follow_logs: 'pod --workdir /home/podman/takelship/compose/projects/%{project} podman-compose logs --follow'
|
64
65
|
cmd_ship_project_start_docker_run_nonprivileged: '%{ship_docker} run --rm --interactive %{image} %{command}'
|
65
66
|
cmd_ship_project_start_docker_run_privileged: '%{ship_docker} run --privileged --rm --detach --name %{ship_hostname} --hostname %{ship_hostname} %{ship_env} %{ports} --volume ./%{ship_data_dir}:/home/podman/takelship %{image} %{command}'
|
66
67
|
cmd_ship_project_start_docker_stop: '%{ship_docker} stop %{ship_hostname}'
|
67
|
-
cmd_ship_project_follow_logs: 'pod --workdir /home/podman/takelship/compose/projects/%{project} podman-compose logs --follow'
|
68
68
|
docker_container_check_matrjoschka: 'true'
|
69
69
|
docker_debug: 'ansible/roles/takel_takelage/files/takelscripts'
|
70
70
|
docker_entrypoint_extra: ''
|
@@ -96,7 +96,6 @@ ship_env: '--env TAKELSHIP_UPDATE=true'
|
|
96
96
|
ship_hostname: '%{ship_name}_%{unique}'
|
97
97
|
ship_name: 'takelship'
|
98
98
|
ship_podman_localhost: '127.0.0.1'
|
99
|
-
ship_ports: ''
|
100
99
|
ship_port_expose_podman_socket: 'false'
|
101
100
|
ship_repo: 'takelship'
|
102
101
|
ship_tag: 'latest'
|
data/lib/takeltau/lib/system.rb
CHANGED
@@ -49,6 +49,13 @@ module SystemModule
|
|
49
49
|
@content
|
50
50
|
end
|
51
51
|
|
52
|
+
# Write content to file
|
53
|
+
def write_file(file, content)
|
54
|
+
log.debug "Writing content to file \"#{file}\":"
|
55
|
+
log.debug "\"#{content}\""
|
56
|
+
File.write(file, content)
|
57
|
+
end
|
58
|
+
|
52
59
|
# Remove directory tree.
|
53
60
|
def rm_fr(directory)
|
54
61
|
unless File.directory? directory
|
data/lib/takeltau/ship/cli.rb
CHANGED
@@ -25,6 +25,9 @@ module Takeltau
|
|
25
25
|
desc 'info [COMMAND]', 'Get info about takelship containers'
|
26
26
|
subcommand 'info', ShipInfo
|
27
27
|
|
28
|
+
desc 'ports [COMMAND]', 'Manage takelship portss'
|
29
|
+
subcommand 'ports', ShipPorts
|
30
|
+
|
28
31
|
desc 'project [COMMAND]', 'Manage takelship projects'
|
29
32
|
subcommand 'project', ShipProject
|
30
33
|
|
@@ -20,14 +20,18 @@ module ShipContainerLib
|
|
20
20
|
# rubocop:disable Metrics/MethodLength
|
21
21
|
def _ship_container_lib_docker_privileged(ports, command)
|
22
22
|
ship_data_dir = config.active['ship_data_dir']
|
23
|
-
ship_env = config.active['ship_env']
|
23
|
+
ship_env = [config.active['ship_env']]
|
24
|
+
ports.each do |key, port|
|
25
|
+
envvar = "TAKELSHIP_CONFIG_#{key}".upcase
|
26
|
+
envstr = "--env #{envvar}=#{port['localhost']}"
|
27
|
+
ship_env << envstr
|
28
|
+
end
|
24
29
|
ports = _ship_container_lib_publish(ports)
|
25
|
-
ports = config.active['ports'] unless config.active['ship_ports'].empty?
|
26
30
|
cmd_docker_run_command = format(
|
27
31
|
config.active['cmd_ship_project_start_docker_run_privileged'],
|
28
32
|
ship_docker: config.active['cmd_ship_docker'],
|
29
33
|
ship_hostname: _ship_container_lib_ship_hostname,
|
30
|
-
ship_env: ship_env,
|
34
|
+
ship_env: ship_env.join(' '),
|
31
35
|
ports: ports,
|
32
36
|
ship_data_dir: ship_data_dir,
|
33
37
|
image: _ship_container_lib_image,
|
@@ -77,7 +81,11 @@ module ShipContainerLib
|
|
77
81
|
def _ship_container_lib_publish(ports)
|
78
82
|
publish = []
|
79
83
|
ports.each do |port|
|
80
|
-
|
84
|
+
shipport = port[1]['takelship'].to_s
|
85
|
+
localport = port[1]['localhost'].to_s
|
86
|
+
next unless localport.to_i.between? 1, 65_535
|
87
|
+
|
88
|
+
publish << "--publish \"127.0.0.1:#{localport}:#{shipport}\""
|
81
89
|
end
|
82
90
|
publish.join(' ')
|
83
91
|
end
|
@@ -9,6 +9,7 @@ module ShipInfoLib
|
|
9
9
|
log.debug 'Gathering takelship info'
|
10
10
|
takelshipinfo = _ship_info_lib_get_info_from_file
|
11
11
|
takelshipinfo = _ship_info_lib_get_info_from_docker if takelshipinfo.empty?
|
12
|
+
|
12
13
|
return false if takelshipinfo.nil?
|
13
14
|
|
14
15
|
takelshipinfo
|
@@ -44,6 +45,8 @@ module ShipInfoLib
|
|
44
45
|
def _ship_info_lib_valid_project?(takelship, project)
|
45
46
|
valid_project = false
|
46
47
|
takelship_projects = takelship['projects']
|
48
|
+
return false if takelship_projects.nil? || takelship_projects.empty?
|
49
|
+
|
47
50
|
takelship_projects.each do |takelship_project|
|
48
51
|
valid_project = true if project == takelship_project['name']
|
49
52
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Takeltau
|
4
|
+
# tau ship info
|
5
|
+
class ShipPorts < SubCommandBase
|
6
|
+
include LoggingModule
|
7
|
+
include SystemModule
|
8
|
+
include ConfigModule
|
9
|
+
include DockerCheckDaemon
|
10
|
+
include ShipContainerLib
|
11
|
+
include ShipInfoLib
|
12
|
+
include ShipPortsLib
|
13
|
+
include ShipPortsList
|
14
|
+
|
15
|
+
desc 'list [PROJECT]', 'Print takelship ports of a [PROJECT]'
|
16
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
17
|
+
Print the ports that a takelship project exposes.
|
18
|
+
LONGDESC
|
19
|
+
# ship list: {Takeltau::ShipPorts#list}
|
20
|
+
def list(project = 'default')
|
21
|
+
say (ship_ports_list project).to_yaml
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# tau ship ports lib
|
4
|
+
module ShipPortsLib
|
5
|
+
private
|
6
|
+
|
7
|
+
# get the ports of a takelship
|
8
|
+
# rubocop:disable Metrics/MethodLength
|
9
|
+
def _ship_ports_lib_get_ports(takelship, takelproject)
|
10
|
+
ports = _ship_ports_lib_get_ports_docker(takelship)
|
11
|
+
takelship['projects'].each do |project|
|
12
|
+
next unless project['name'] == takelproject
|
13
|
+
|
14
|
+
project['services'].each do |service|
|
15
|
+
next unless service.key? 'ports'
|
16
|
+
|
17
|
+
service['ports'].each do |port|
|
18
|
+
key = _ship_ports_lib_generate_key port, service
|
19
|
+
ports[key] = _ship_ports_lib_get_port key, port, service
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
ports
|
24
|
+
end
|
25
|
+
# rubocop:enable Metrics/MethodLength
|
26
|
+
|
27
|
+
# write ports to project takelage.yml
|
28
|
+
def _ship_ports_lib_write_ports(ports, project)
|
29
|
+
config_project = _ship_ports_lib_get_project_config ports, project
|
30
|
+
project_dir = config.active['project_root_dir']
|
31
|
+
config_file = "#{project_dir}/takelage.yml"
|
32
|
+
write_file config_file, config_project.to_yaml
|
33
|
+
end
|
34
|
+
|
35
|
+
# get current project config
|
36
|
+
# the values are added/updated unconditionally
|
37
|
+
# the merge with the existing values has been done here:
|
38
|
+
# ConfigModule::TakeltauConfig::_config_merge_active
|
39
|
+
# and here: _ship_ports_lib_get_localhost_port
|
40
|
+
def _ship_ports_lib_get_project_config(ports, project)
|
41
|
+
config_project = config.project
|
42
|
+
ports.each do |key, port|
|
43
|
+
config_project[key] = port['localhost']
|
44
|
+
end
|
45
|
+
config_project['ship_default_project'] = project
|
46
|
+
config_project.sort.to_h
|
47
|
+
end
|
48
|
+
|
49
|
+
# map the podman socket port (aka "DOCKER_HOST")
|
50
|
+
# returns a hash unlike the get_port method
|
51
|
+
# rubocop:disable Metrics/MethodLength
|
52
|
+
def _ship_ports_lib_get_ports_docker(takelship)
|
53
|
+
takel_docker = takelship['docker_host']
|
54
|
+
docker_key = "ship_ports_dind_docker_#{takel_docker}"
|
55
|
+
local_docker = _ship_ports_lib_get_localhost_port docker_key, takel_docker
|
56
|
+
{
|
57
|
+
docker_key => {
|
58
|
+
'service' => 'dind',
|
59
|
+
'protocol' => 'docker',
|
60
|
+
'takelship' => takel_docker.to_i,
|
61
|
+
'localhost' => local_docker
|
62
|
+
}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
# rubocop:enable Metrics/MethodLength
|
66
|
+
|
67
|
+
# map a takelship port
|
68
|
+
def _ship_ports_lib_get_port(key, port, service)
|
69
|
+
localhost = _ship_ports_lib_get_localhost_port key, port['port']
|
70
|
+
{
|
71
|
+
'service' => service['name'],
|
72
|
+
'protocol' => port['protocol'],
|
73
|
+
'takelship' => port['port'],
|
74
|
+
'localhost' => localhost
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
# get new port on localhost for takelport
|
79
|
+
def _ship_ports_lib_get_localhost_port(key, port)
|
80
|
+
env_var = "TAKELAGE_TAU_CONFIG_#{key}".upcase
|
81
|
+
return ENV[env_var].to_i if ENV.key? env_var
|
82
|
+
|
83
|
+
return config.active[key] if config.active.key? key
|
84
|
+
|
85
|
+
_ship_ports_lib_get_free_port port
|
86
|
+
end
|
87
|
+
|
88
|
+
# derive a random free port from a port
|
89
|
+
def _ship_ports_lib_get_free_port(port)
|
90
|
+
localport = 0
|
91
|
+
loop do
|
92
|
+
offset = _ship_ports_lib_get_offset
|
93
|
+
localport = port.to_i + offset
|
94
|
+
break unless _ship_ports_lib_port_open? localport
|
95
|
+
end
|
96
|
+
localport
|
97
|
+
end
|
98
|
+
|
99
|
+
# generate dynamic takelconfig key
|
100
|
+
def _ship_ports_lib_generate_key(port, service)
|
101
|
+
key = "ship_ports_#{service['name']}_#{port['protocol']}_#{port['port']}"
|
102
|
+
key.gsub('-', '_')
|
103
|
+
end
|
104
|
+
|
105
|
+
# generate random offset
|
106
|
+
def _ship_ports_lib_get_offset
|
107
|
+
# this results in ports
|
108
|
+
# from 30000 + 15000 = 45000
|
109
|
+
# to 40000 + 25000 = 65000
|
110
|
+
# max port number: 65535
|
111
|
+
rand(15_000..25_000)
|
112
|
+
end
|
113
|
+
|
114
|
+
# check if a port on the host is open
|
115
|
+
def _ship_ports_lib_port_open?(port)
|
116
|
+
log.debug "Checking if port #{port} is open"
|
117
|
+
begin
|
118
|
+
Socket.tcp('127.0.0.1', port, connect_timeout: 5)
|
119
|
+
true
|
120
|
+
rescue Errno::ECONNREFUSED
|
121
|
+
false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# tau ship ports list
|
4
|
+
module ShipPortsList
|
5
|
+
# List takelship portss.
|
6
|
+
def ship_ports_list(project)
|
7
|
+
log.debug 'List takelship ports'
|
8
|
+
|
9
|
+
takelship = _ship_info_lib_get_takelshipinfo
|
10
|
+
project = _ship_info_lib_get_project(project, takelship)
|
11
|
+
|
12
|
+
return false unless _ship_info_lib_valid_project? takelship, project
|
13
|
+
|
14
|
+
_ship_ports_lib_get_ports takelship, project
|
15
|
+
end
|
16
|
+
end
|
@@ -12,6 +12,7 @@ module Takeltau
|
|
12
12
|
include ShipContainerLib
|
13
13
|
include ShipContainerStop
|
14
14
|
include ShipInfoLib
|
15
|
+
include ShipPortsLib
|
15
16
|
include ShipProjectList
|
16
17
|
include ShipProjectLogs
|
17
18
|
include ShipProjectStart
|
@@ -46,7 +47,8 @@ module Takeltau
|
|
46
47
|
Start a takelship and run project [PROJECT] in it.
|
47
48
|
LONGDESC
|
48
49
|
def start(project = 'default')
|
49
|
-
ship_project_start project
|
50
|
+
project_start = ship_project_start project
|
51
|
+
say project_start if project_start
|
50
52
|
end
|
51
53
|
|
52
54
|
#
|
@@ -4,44 +4,75 @@
|
|
4
4
|
module ShipProjectStart
|
5
5
|
# Start a takelship
|
6
6
|
def ship_project_start(project)
|
7
|
-
return false
|
8
|
-
|
9
|
-
return false if ship_container_check_existing
|
7
|
+
return false unless _ship_project_start_prerequisites_fulfilled?
|
10
8
|
|
11
9
|
takelship = _ship_info_lib_get_takelshipinfo
|
12
|
-
project = _ship_info_lib_get_project
|
10
|
+
project = _ship_info_lib_get_project project, takelship
|
11
|
+
|
12
|
+
return false unless _ship_project_start_valid_project? takelship, project
|
13
|
+
|
14
|
+
ports = _ship_ports_lib_get_ports(takelship, project)
|
13
15
|
|
14
|
-
|
16
|
+
log.debug 'Writing port configuration to takelage.yml'
|
17
|
+
_ship_ports_lib_write_ports(ports, project)
|
15
18
|
|
16
19
|
log.debug "Starting takelship project \"#{project}\""
|
17
|
-
ports
|
18
|
-
|
20
|
+
_ship_container_lib_docker_privileged ports, project
|
21
|
+
|
22
|
+
_ship_project_start_print_ports project, ports
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
22
26
|
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
# check prerequisistes
|
28
|
+
def _ship_project_start_prerequisites_fulfilled?
|
29
|
+
if _docker_container_lib_check_matrjoschka
|
30
|
+
say 'Cannot start a takelship from within a takelage container!'
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
|
34
|
+
if ship_container_check_existing
|
35
|
+
say "Container \"#{_ship_container_lib_ship_hostname}\" is already started!"
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
# check if the project is a valid takelship project
|
43
|
+
def _ship_project_start_valid_project?(takelship, project)
|
44
|
+
return true if _ship_info_lib_valid_project? takelship, project
|
45
|
+
|
46
|
+
say 'No valid project found!'
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
# print ports after starting a takelship
|
51
|
+
def _ship_project_start_print_ports(project, ports)
|
52
|
+
output = []
|
53
|
+
output << "Started takelship project \"#{project}\"\n"
|
54
|
+
max_length = _ship_project_start_get_maxlength ports
|
55
|
+
|
56
|
+
ports.each_value do |port|
|
57
|
+
next unless port['localhost'].to_i.between? 1, 65_535
|
58
|
+
|
59
|
+
left = "localhost:#{port['localhost']}"
|
60
|
+
right = "(#{port['service']} #{port['protocol']})"
|
61
|
+
output << "#{left.ljust(max_length)} #{right}"
|
38
62
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
63
|
+
output.join("\n")
|
64
|
+
end
|
65
|
+
|
66
|
+
# get max length of left column
|
67
|
+
def _ship_project_start_get_maxlength(ports)
|
68
|
+
max_length = 0
|
69
|
+
ports.each_value do |port|
|
70
|
+
localport = port['localhost']
|
71
|
+
next unless localport.to_i.between? 1, 65_535
|
72
|
+
|
73
|
+
left_string = "localhost:#{localport}"
|
74
|
+
max_length = left_string.length if max_length < left_string.length
|
42
75
|
end
|
43
|
-
|
76
|
+
max_length
|
44
77
|
end
|
45
78
|
end
|
46
|
-
# rubocop:enable Metrics/AbcSize
|
47
|
-
# rubocop:enable Metrics/MethodLength
|
data/lib/takeltau/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.44.
|
1
|
+
0.44.8
|
data/lib/takeltau.rb
CHANGED
@@ -98,6 +98,9 @@ require_relative 'takeltau/ship/container/stop'
|
|
98
98
|
require_relative 'takeltau/ship/container/update'
|
99
99
|
require_relative 'takeltau/ship/container/cli'
|
100
100
|
require_relative 'takeltau/ship/info/cli'
|
101
|
+
require_relative 'takeltau/ship/ports/lib'
|
102
|
+
require_relative 'takeltau/ship/ports/list'
|
103
|
+
require_relative 'takeltau/ship/ports/cli'
|
101
104
|
require_relative 'takeltau/ship/project/list'
|
102
105
|
require_relative 'takeltau/ship/project/logs'
|
103
106
|
require_relative 'takeltau/ship/project/start'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: takeltau
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.44.
|
4
|
+
version: 0.44.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takelwerk
|
@@ -300,6 +300,9 @@ files:
|
|
300
300
|
- lib/takeltau/ship/container/update.rb
|
301
301
|
- lib/takeltau/ship/info/cli.rb
|
302
302
|
- lib/takeltau/ship/info/lib.rb
|
303
|
+
- lib/takeltau/ship/ports/cli.rb
|
304
|
+
- lib/takeltau/ship/ports/lib.rb
|
305
|
+
- lib/takeltau/ship/ports/list.rb
|
303
306
|
- lib/takeltau/ship/project/cli.rb
|
304
307
|
- lib/takeltau/ship/project/list.rb
|
305
308
|
- lib/takeltau/ship/project/logs.rb
|