activek8s 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/activek8s/railtie.rb +2 -1
- data/lib/activek8s/version.rb +1 -1
- data/lib/tasks/build_deployment.rake +1 -1
- data/lib/tasks/delete.rake +1 -1
- data/lib/tasks/deploy.rake +1 -1
- data/lib/tasks/kibana.rake +1 -1
- data/lib/tasks/port_forward.rake +53 -19
- data/lib/tasks/port_forward_current.rake +24 -0
- data/lib/tasks/port_forward_service.rake +18 -0
- metadata +5 -5
- data/lib/tasks/port_forward_many.rake +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cced9ad51fc24f2435e9b38833bbc5c991b63523db450701d7c80dd548669e7e
|
4
|
+
data.tar.gz: 11f4f7296e0826865e57c5a86d61157d707b7662f63c8399583606460e8b74e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd1a7680bc20702faf6334bdd50c85d0ae3c3cf23e4f0c89730e19c232ea114d3271fa7070932f87e184e326f4fa9f3c5f55bb2c760556205ba9703743c3ddb1
|
7
|
+
data.tar.gz: 29696b79bc8487f13336cebfc73417e8aeff99a5f6c45b221de5fb2bf137a4359c6ff6cae9c25996e2657a7bc4eb2135d10e253816f37ef4f6ac4aecea69f409
|
data/Gemfile.lock
CHANGED
data/lib/activek8s/railtie.rb
CHANGED
@@ -6,7 +6,8 @@ module Activek8s
|
|
6
6
|
load 'tasks/deploy.rake'
|
7
7
|
load 'tasks/delete.rake'
|
8
8
|
load 'tasks/port_forward.rake'
|
9
|
-
load 'tasks/
|
9
|
+
load 'tasks/port_forward_current.rake'
|
10
|
+
load 'tasks/port_forward_service.rake'
|
10
11
|
load 'tasks/kibana.rake'
|
11
12
|
end
|
12
13
|
end
|
data/lib/activek8s/version.rb
CHANGED
data/lib/tasks/delete.rake
CHANGED
data/lib/tasks/deploy.rake
CHANGED
data/lib/tasks/kibana.rake
CHANGED
data/lib/tasks/port_forward.rake
CHANGED
@@ -1,24 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
require 'childprocess'
|
2
|
+
|
3
|
+
namespace 'ak8s' do
|
4
|
+
desc 'Port forwards many services from a specific NAMESPACE'
|
5
|
+
task :port_forward, [:namespace] do |_t, args|
|
6
|
+
# Config with defaults setup
|
7
|
+
config = YAML.load_file(ENV['AK8S_CONFIG'] || '.ak8s.yml')
|
8
|
+
config_namespaces = config.keys.reject { |n| n == 'ak8s' }
|
9
|
+
args.with_defaults(namespace: config_namespaces.first)
|
10
|
+
raise 'Bad config file format' if args.namespace.nil?
|
11
|
+
|
12
|
+
# Helper variables setup
|
13
|
+
first_port = config.dig('ak8s', 'first_port') || 4200
|
14
|
+
namespaced_services = config[args.namespace]['services']
|
15
|
+
raise 'No services listed in .ak8s.yml' if namespaced_services.empty?
|
16
|
+
|
17
|
+
# All services to port forward (an array of hashes)
|
18
|
+
services = namespaced_services.each_with_index.map do |service, index|
|
19
|
+
port = first_port.to_i + index
|
20
|
+
export_env = "#{service['name'].upcase}_ENDPOINT"
|
21
|
+
target_port = service['target_port'] || 3000
|
22
|
+
service_namespace = service['namespace'] || args.namespace
|
23
|
+
|
24
|
+
rake_task_params = [
|
25
|
+
service_namespace,
|
26
|
+
service['name'],
|
27
|
+
port,
|
28
|
+
target_port
|
29
|
+
].map(&:to_s).join(',')
|
30
|
+
|
31
|
+
{
|
32
|
+
port: port,
|
33
|
+
rake_task: "ak8s:port_forward_service[#{rake_task_params}]",
|
34
|
+
env: "export #{export_env}=\"http://localhost:#{port}/\""
|
35
|
+
}
|
12
36
|
end
|
13
37
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
38
|
+
# Export ENV variables to `services.env`
|
39
|
+
env_file = services.map { |service| service[:env] }.join("\n")
|
40
|
+
File.write('services.env', env_file)
|
41
|
+
|
42
|
+
# Execute each 'rake_task' in a child process until CTRL+C is received
|
43
|
+
begin
|
44
|
+
processes = services.map do |service|
|
45
|
+
ChildProcess.build('bin/rake', service[:rake_task])
|
46
|
+
end
|
47
|
+
processes.each(&:start)
|
18
48
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
49
|
+
puts 'Services should be port forwarded to localhost in a few seconds.'
|
50
|
+
puts 'Execute ". services.env" to source each service URL.'
|
51
|
+
loop { sleep 3 }
|
52
|
+
rescue Interrupt
|
53
|
+
puts "\nExiting child processes..."
|
54
|
+
processes.each(&:stop)
|
55
|
+
puts 'Done!'
|
56
|
+
end
|
23
57
|
end
|
24
58
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
namespace 'ak8s' do
|
2
|
+
desc 'Port forwards the current project using the `kube/deployment.yml` file'
|
3
|
+
task :port_forward_current,
|
4
|
+
[:namespace, :service, :local_port, :target_port] do |_t, args|
|
5
|
+
begin
|
6
|
+
service_yaml = File.read('kube/deployment.yml').split('---')[1]
|
7
|
+
deployment_hash = Psych.load(service_yaml)
|
8
|
+
own_name = deployment_hash['metadata']['name']
|
9
|
+
rescue
|
10
|
+
docs_location = 'CHECK DOCS AT -> https://github.com/fdoxyz/activek8s'
|
11
|
+
raise "WARNING: Unable to load `kube/deployment.yml`. #{docs_location}"
|
12
|
+
end
|
13
|
+
|
14
|
+
args.with_defaults(namespace: 'dev',
|
15
|
+
service: own_name,
|
16
|
+
local_port: '3000',
|
17
|
+
target_port: '3000')
|
18
|
+
|
19
|
+
service = "svc/#{args.service}"
|
20
|
+
port_mapping = "#{args.local_port}:#{args.target_port}"
|
21
|
+
namespace = "-n #{args.namespace}"
|
22
|
+
sh %{kubectl port-forward #{service} #{port_mapping} #{namespace}}
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace 'ak8s' do
|
2
|
+
desc 'Port forwards a microservice from a specific NAMESPACE to a PORT'
|
3
|
+
task :port_forward_service,
|
4
|
+
[:namespace, :service, :local_port, :target_port] do |_t, args|
|
5
|
+
|
6
|
+
args.with_defaults(namespace: 'dev',
|
7
|
+
service: nil,
|
8
|
+
local_port: '3000',
|
9
|
+
target_port: '3000')
|
10
|
+
|
11
|
+
raise 'Invalid service name' if args.service.nil?
|
12
|
+
|
13
|
+
service = "svc/#{args.service}"
|
14
|
+
port_mapping = "#{args.local_port}:#{args.target_port}"
|
15
|
+
namespace = "-n #{args.namespace}"
|
16
|
+
sh %{kubectl port-forward #{service} #{port_mapping} #{namespace}}
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activek8s
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Valverde Arredondo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: childprocess
|
@@ -135,7 +135,8 @@ files:
|
|
135
135
|
- lib/tasks/deploy.rake
|
136
136
|
- lib/tasks/kibana.rake
|
137
137
|
- lib/tasks/port_forward.rake
|
138
|
-
- lib/tasks/
|
138
|
+
- lib/tasks/port_forward_current.rake
|
139
|
+
- lib/tasks/port_forward_service.rake
|
139
140
|
homepage: https://github.com/fdoxyz/activek8s
|
140
141
|
licenses:
|
141
142
|
- MIT
|
@@ -155,8 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
156
|
- !ruby/object:Gem::Version
|
156
157
|
version: '0'
|
157
158
|
requirements: []
|
158
|
-
|
159
|
-
rubygems_version: 2.7.8
|
159
|
+
rubygems_version: 3.0.3
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: Kubernetes integration to Rails apps via Rake tasks
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'childprocess'
|
2
|
-
|
3
|
-
namespace 'k8s' do
|
4
|
-
desc 'Port forwards many services from a specific NAMESPACE'
|
5
|
-
task :port_forward_many, [:namespace, :first_port, :services] do |_t, args|
|
6
|
-
# default "empty char" separated services to be port-forwarded from ENV
|
7
|
-
args.with_defaults(namespace: 'dev',
|
8
|
-
first_port: '3001',
|
9
|
-
services: ENV['K8S_SERVICES'].to_s)
|
10
|
-
|
11
|
-
# Build 'dynamic' values
|
12
|
-
services = args.services.split(' ').each_with_index.map do |name, index|
|
13
|
-
port = args.first_port.to_i + index
|
14
|
-
export_env = "#{name.upcase}_ENDPOINT"
|
15
|
-
{
|
16
|
-
port: port,
|
17
|
-
rake_task: "k8s:port_forward[#{args.namespace},#{name},#{port},3000]",
|
18
|
-
env: "export #{export_env}=\"http://localhost:#{port}/\""
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
# Export ENV variables
|
23
|
-
env_file = services.map { |service| service[:env] }.join("\n")
|
24
|
-
File.write('services.env', env_file)
|
25
|
-
|
26
|
-
# Execute each 'rake_task' in a child process until CTRL+C is received
|
27
|
-
begin
|
28
|
-
processes = services.map do |service|
|
29
|
-
ChildProcess.build('bin/rake', service[:rake_task])
|
30
|
-
end
|
31
|
-
processes.each(&:start)
|
32
|
-
|
33
|
-
puts 'Services should be port forwarded to localhost in a few seconds.'
|
34
|
-
puts 'Execute ". services.env" to source each service URL.'
|
35
|
-
loop { sleep 3 }
|
36
|
-
rescue Interrupt
|
37
|
-
puts "\nExiting child processes..."
|
38
|
-
processes.each(&:stop)
|
39
|
-
puts 'Done!'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|