takeltau 0.44.2 → 0.44.11
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 +3 -0
- data/lib/takeltau/default.yml +1 -2
- data/lib/takeltau/lib/system.rb +7 -0
- data/lib/takeltau/ship/cli.rb +35 -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 +138 -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 +77 -26
- 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: 6ddae907069e4203d6fd9ab233e4e39573a2c9db4a4921868fa53e3375172d18
|
4
|
+
data.tar.gz: 0bae02ff5ccaa0885c4c08c9ea2dd4e48dec96b8b6164532a86b5fd3add3fc8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a263b2321750b5547d6234c35a85a75a06fbe8b9e357f5aa18af74f0aa1300c28fab6b830d662fb239f03a6188e730a39659c1fc8e8db2b89b6ff4ef6349b0a
|
7
|
+
data.tar.gz: b0024cf566206e62ffd3e5d1f407d04217ca66b0738d77ee8c2c31e5f897af951ad312cf7c799761ee3ea3abd1f2afba6fbfc9aaf2dd86442fcc3d54115fccc7
|
data/README.md
CHANGED
@@ -131,15 +131,18 @@ tau [ship project list](features/cucumber/features/ship/project/ship.project.lis
|
|
131
131
|
tau [ship project logs](features/cucumber/features/ship/project/ship.project.logs.feature) [PROJECT] | Follow logs of a takelship [PROJECT]
|
132
132
|
tau [ship project start](features/cucumber/features/ship/project/ship.project.start.feature) [PROJECT] | Start a takelship [PROJECT]
|
133
133
|
tau [ship project stop](features/cucumber/features/ship/project/ship.project.stop.feature) | Stop a takelship project
|
134
|
+
tau ship board | Alias for tau [ship container login](features/cucumber/features/ship/container/ship.container.login.feature)
|
134
135
|
tau ship command [COMMAND] | Alias for tau [ship container command](features/cucumber/features/ship/container/ship.container.command.feature)
|
135
136
|
tau ship list | Alias for tau [ship container list](features/cucumber/features/ship/container/ship.container.list.feature)
|
136
137
|
tau ship login | Alias for tau [ship container login](features/cucumber/features/ship/container/ship.container.login.feature)
|
137
138
|
tau ship logs [PROJECT] | Alias for tau [ship project logs](features/cucumber/features/ship/project/ship.project.logs.feature)
|
138
139
|
tau ship ls | Alias for tau [ship container list](features/cucumber/features/ship/container/ship.container.list.feature)
|
139
140
|
tau ship podman [COMMAND] | Alias for tau [ship container podman](features/cucumber/features/ship/container/ship.container.podman.feature)
|
141
|
+
tau ship sail [PROJECT] | Alias for tau [ship project start](features/cucumber/features/ship/project/ship.project.start.feature)
|
140
142
|
tau ship start [PROJECT] | Alias for tau [ship project start](features/cucumber/features/ship/project/ship.project.start.feature)
|
141
143
|
tau ship stop | Alias for tau [ship project stop](features/cucumber/features/ship/project/ship.project.stop.feature)
|
142
144
|
tau ship sudo [COMMAND] | Alias for tau [ship container sudo](features/cucumber/features/ship/container/ship.container.sudo.feature)
|
145
|
+
tau ship wreck | Alias for tau [ship project stop](features/cucumber/features/ship/project/ship.project.stop.feature)
|
143
146
|
tau ship update | Alias for tau [ship container update](features/cucumber/features/ship/container/ship.container.update.feature)
|
144
147
|
tau clean | Alias for tau [docker container clean](features/cucumber/features/docker/docker.container.clean.feature)
|
145
148
|
tau commands | Alias for tau [self commands](features/cucumber/features/self/self.commands.feature)
|
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
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module Takeltau
|
4
4
|
# tau ship
|
5
|
+
# rubocop:disable Metrics/ClassLength
|
5
6
|
class Ship < SubCommandBase
|
6
7
|
include LoggingModule
|
7
8
|
include SystemModule
|
@@ -25,6 +26,9 @@ module Takeltau
|
|
25
26
|
desc 'info [COMMAND]', 'Get info about takelship containers'
|
26
27
|
subcommand 'info', ShipInfo
|
27
28
|
|
29
|
+
desc 'ports [COMMAND]', 'Manage takelship portss'
|
30
|
+
subcommand 'ports', ShipPorts
|
31
|
+
|
28
32
|
desc 'project [COMMAND]', 'Manage takelship projects'
|
29
33
|
subcommand 'project', ShipProject
|
30
34
|
|
@@ -32,6 +36,16 @@ module Takeltau
|
|
32
36
|
# Top-level ship commands
|
33
37
|
#
|
34
38
|
|
39
|
+
desc 'board', 'Log in to a takelship'
|
40
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
41
|
+
Log in to a takelship as root.
|
42
|
+
Alias for ship container login.
|
43
|
+
LONGDESC
|
44
|
+
# ship board: {Takeltau::ShipContainer#login}
|
45
|
+
def board
|
46
|
+
Takeltau::ShipContainer.new.login
|
47
|
+
end
|
48
|
+
|
35
49
|
desc 'command [COMMAND]', 'Run a [COMMAND] in a takelship'
|
36
50
|
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
37
51
|
Run a command in a takelship container as user podman.
|
@@ -112,6 +126,16 @@ module Takeltau
|
|
112
126
|
Takeltau::ShipProject.new.start project
|
113
127
|
end
|
114
128
|
|
129
|
+
desc 'sail [PROJECT]', 'Start takelship [PROJECT]'
|
130
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
131
|
+
Start a takelship and run project [PROJECT] in it.
|
132
|
+
Alias for ship project start.
|
133
|
+
LONGDESC
|
134
|
+
# ship sail: {Takeltau::ShipProject#start}
|
135
|
+
def sail(project = 'default')
|
136
|
+
Takeltau::ShipProject.new.start project
|
137
|
+
end
|
138
|
+
|
115
139
|
desc 'stop', 'Stop a takelship'
|
116
140
|
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
117
141
|
Stop a takelship container.
|
@@ -122,6 +146,16 @@ module Takeltau
|
|
122
146
|
Takeltau::ShipProject.new.stop
|
123
147
|
end
|
124
148
|
|
149
|
+
desc 'wreck', 'Stop a takelship'
|
150
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
151
|
+
Stop a takelship container.
|
152
|
+
Alias for ship container stop.
|
153
|
+
LONGDESC
|
154
|
+
# ship wreck: {Takeltau::ShipProject#stop}
|
155
|
+
def wreck
|
156
|
+
Takeltau::ShipProject.new.stop
|
157
|
+
end
|
158
|
+
|
125
159
|
desc 'update', 'Update takelship image'
|
126
160
|
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
127
161
|
Update the takelship docker image.
|
@@ -132,4 +166,5 @@ module Takeltau
|
|
132
166
|
Takeltau::ShipContainer.new.update
|
133
167
|
end
|
134
168
|
end
|
169
|
+
# rubocop:enable Metrics/ClassLength
|
135
170
|
end
|
@@ -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_#{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,138 @@
|
|
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
|
+
docker_host = "DOCKER_HOST=tcp://localhost:#{local_docker}"
|
57
|
+
{
|
58
|
+
docker_key => {
|
59
|
+
'service' => 'dind',
|
60
|
+
'protocol' => 'docker',
|
61
|
+
'takelship' => takel_docker.to_i,
|
62
|
+
'localhost' => local_docker,
|
63
|
+
'description' => docker_host
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
# rubocop:enable Metrics/MethodLength
|
68
|
+
|
69
|
+
# map a takelship port
|
70
|
+
# rubocop:disable Metrics/MethodLength
|
71
|
+
def _ship_ports_lib_get_port(key, port, service)
|
72
|
+
localhost = _ship_ports_lib_get_localhost_port key, port['port']
|
73
|
+
unless port.key?('description')
|
74
|
+
return {
|
75
|
+
'service' => service['name'],
|
76
|
+
'protocol' => port['protocol'],
|
77
|
+
'takelship' => port['port'],
|
78
|
+
'localhost' => localhost
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
{
|
83
|
+
'service' => service['name'],
|
84
|
+
'protocol' => port['protocol'],
|
85
|
+
'takelship' => port['port'],
|
86
|
+
'localhost' => localhost,
|
87
|
+
'description' => port['description']
|
88
|
+
}
|
89
|
+
end
|
90
|
+
# rubocop:enable Metrics/MethodLength
|
91
|
+
|
92
|
+
# get new port on localhost for takelport
|
93
|
+
def _ship_ports_lib_get_localhost_port(key, port)
|
94
|
+
env_var = "TAKELAGE_TAU_CONFIG_#{key}".upcase
|
95
|
+
return ENV[env_var].to_i if ENV.key? env_var
|
96
|
+
|
97
|
+
return config.active[key] if config.active.key? key
|
98
|
+
|
99
|
+
_ship_ports_lib_get_free_port port
|
100
|
+
end
|
101
|
+
|
102
|
+
# derive a random free port from a port
|
103
|
+
def _ship_ports_lib_get_free_port(port)
|
104
|
+
localport = 0
|
105
|
+
loop do
|
106
|
+
offset = _ship_ports_lib_get_offset
|
107
|
+
localport = port.to_i + offset
|
108
|
+
break unless _ship_ports_lib_port_open? localport
|
109
|
+
end
|
110
|
+
localport
|
111
|
+
end
|
112
|
+
|
113
|
+
# generate dynamic takelconfig key
|
114
|
+
def _ship_ports_lib_generate_key(port, service)
|
115
|
+
key = "ship_ports_#{service['name']}_#{port['protocol']}_#{port['port']}"
|
116
|
+
key.gsub('-', '_')
|
117
|
+
end
|
118
|
+
|
119
|
+
# generate random offset
|
120
|
+
def _ship_ports_lib_get_offset
|
121
|
+
# this results in ports
|
122
|
+
# from 30000 + 15000 = 45000
|
123
|
+
# to 40000 + 25000 = 65000
|
124
|
+
# max port number: 65535
|
125
|
+
rand(15_000..25_000)
|
126
|
+
end
|
127
|
+
|
128
|
+
# check if a port on the host is open
|
129
|
+
def _ship_ports_lib_port_open?(port)
|
130
|
+
log.debug "Checking if port #{port} is open"
|
131
|
+
begin
|
132
|
+
Socket.tcp('127.0.0.1', port, connect_timeout: 5)
|
133
|
+
true
|
134
|
+
rescue Errno::ECONNREFUSED
|
135
|
+
false
|
136
|
+
end
|
137
|
+
end
|
138
|
+
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
|
#
|
@@ -3,45 +3,96 @@
|
|
3
3
|
# tau ship project start
|
4
4
|
module ShipProjectStart
|
5
5
|
# Start a takelship
|
6
|
+
# rubocop:disable Metrics/MethodLength
|
6
7
|
def ship_project_start(project)
|
7
|
-
return false
|
8
|
-
|
9
|
-
return false if ship_container_check_existing
|
8
|
+
return false unless _ship_project_start_matrjoschka?
|
10
9
|
|
11
10
|
takelship = _ship_info_lib_get_takelshipinfo
|
12
|
-
project = _ship_info_lib_get_project
|
11
|
+
project = _ship_info_lib_get_project project, takelship
|
12
|
+
|
13
|
+
return false unless _ship_project_start_valid_project? takelship, project
|
13
14
|
|
14
|
-
|
15
|
+
ports = _ship_ports_lib_get_ports(takelship, project)
|
16
|
+
|
17
|
+
return false unless _ship_project_start_sailing? project, ports
|
18
|
+
|
19
|
+
log.debug 'Writing port configuration to takelage.yml'
|
20
|
+
_ship_ports_lib_write_ports(ports, project)
|
15
21
|
|
16
22
|
log.debug "Starting takelship project \"#{project}\""
|
17
|
-
ports
|
18
|
-
say
|
23
|
+
_ship_container_lib_docker_privileged ports, project
|
24
|
+
say "Started project \"#{project}\" on takelship \"#{_ship_container_lib_ship_hostname}\".\n\n"
|
25
|
+
_ship_project_start_print_ports ports
|
19
26
|
end
|
27
|
+
# rubocop:enable Metrics/MethodLength
|
20
28
|
|
21
29
|
private
|
22
30
|
|
23
|
-
#
|
31
|
+
# check if we are inside a takelage container
|
32
|
+
def _ship_project_start_matrjoschka?
|
33
|
+
return true unless _docker_container_lib_check_matrjoschka
|
34
|
+
|
35
|
+
say 'Cannot start a takelship from within a takelage container!'
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
# check if the takelship is already existng
|
40
|
+
def _ship_project_start_sailing?(project, ports)
|
41
|
+
return true unless ship_container_check_existing
|
42
|
+
|
43
|
+
say "The takelship \"#{_ship_container_lib_ship_hostname}\" is sailing with project \"#{project}\".\n\n"
|
44
|
+
say _ship_project_start_print_ports ports
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
48
|
+
# check if the project is a valid takelship project
|
49
|
+
def _ship_project_start_valid_project?(takelship, project)
|
50
|
+
return true if _ship_info_lib_valid_project? takelship, project
|
51
|
+
|
52
|
+
say 'No valid project found!'
|
53
|
+
say 'Hint: ship project list'
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
# print ports after starting a takelship
|
24
58
|
# rubocop:disable Metrics/MethodLength
|
25
59
|
# rubocop:disable Metrics/AbcSize
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
60
|
+
def _ship_project_start_print_ports(ports)
|
61
|
+
output = []
|
62
|
+
max_length = _ship_project_start_get_maxlength ports
|
63
|
+
ports.each_value do |port|
|
64
|
+
next unless port['localhost'].to_i.between? 1, 65_535
|
65
|
+
|
66
|
+
url = "localhost:#{port['localhost']}"
|
67
|
+
service = "[#{port['service']} #{port['protocol']}]"
|
68
|
+
description = port['description']
|
69
|
+
description = " (#{description})" if port.key? 'description'
|
70
|
+
output << "#{url.ljust(max_length['url'])} #{service.ljust(max_length['service'])}#{description}"
|
38
71
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
72
|
+
output.join("\n")
|
73
|
+
end
|
74
|
+
# rubocop:enable Metrics/AbcSize
|
75
|
+
# rubocop:enable Metrics/MethodLength
|
76
|
+
|
77
|
+
# get max length of left column
|
78
|
+
# rubocop:disable Metrics/MethodLength
|
79
|
+
# rubocop:disable Metrics/AbcSize
|
80
|
+
def _ship_project_start_get_maxlength(ports)
|
81
|
+
max_length = {}
|
82
|
+
max_length['url'] = 0
|
83
|
+
max_length['service'] = 0
|
84
|
+
ports.each_value do |port|
|
85
|
+
localport = port['localhost']
|
86
|
+
next unless localport.to_i.between? 1, 65_535
|
87
|
+
|
88
|
+
url = "localhost:#{localport}"
|
89
|
+
max_length['url'] = url.length if max_length['url'] < url.length
|
90
|
+
|
91
|
+
service = "[#{port['service']} #{port['protocol']}]"
|
92
|
+
max_length['service'] = service.length if max_length['service'] < service.length
|
42
93
|
end
|
43
|
-
|
94
|
+
max_length
|
44
95
|
end
|
96
|
+
# rubocop:enable Metrics/AbcSize
|
97
|
+
# rubocop:enable Metrics/MethodLength
|
45
98
|
end
|
46
|
-
# rubocop:enable Metrics/AbcSize
|
47
|
-
# rubocop:enable Metrics/MethodLength
|
data/lib/takeltau/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.44.
|
1
|
+
0.44.11
|
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.11
|
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
|