activek8s 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d018b9854d53c3391a1c0bb9cee5bbf70ff8ec047dccac68bb3cd0ca8c547b96
4
+ data.tar.gz: eb994d76135e672904ba0d415ef7c7fd31bdddadd14179d201a1929546de9865
5
+ SHA512:
6
+ metadata.gz: aa70aa6b07c53d06abd5decb2057388fec005d89a62edfa067023c4ed9a618e4e9b557378b6c35296a459f3f181447013c64ca9a7abc3575666a82abf224534d
7
+ data.tar.gz: 9252a490f7f013cb73928958d475d501e69bcf9b9e7dc28e3cae5f5d226701db5c29291a52834782a9cf45a0e1e3f7c51480f4b91045258f9efd1d068700d327
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ coverage
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ ModuleLength:
2
+ Exclude:
3
+ - 'lib/ewallet_core/cores/quenti/*.rb'
4
+ Metrics/MethodLength:
5
+ Max: 20
6
+ Exclude:
7
+ - 'lib/ewallet_core/cores/quenti/*.rb'
8
+ Metrics/AbcSize:
9
+ Max: 20
10
+ Exclude:
11
+ - 'lib/ewallet_core/cores/quenti/*.rb'
12
+ Metrics/ClassLength:
13
+ Max: 150
14
+ Metrics/BlockLength:
15
+ Exclude:
16
+ - 'Rakefile'
17
+ - '**/*.rake'
18
+ - 'spec/**/*.rb'
19
+ - 'core_validations/**/*.rb'
20
+ - 'lib/ewallet_core/models/null_object.rb'
21
+ Style/ExpandPathArguments:
22
+ Enabled: false
23
+ Style/WordArray:
24
+ Enabled: false
25
+ Style/PercentLiteralDelimiters:
26
+ Enabled: false
27
+ Style/RescueStandardError:
28
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in activek8s.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activek8s (0.1.0)
5
+ childprocess (~> 0.9.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ byebug (10.0.2)
12
+ childprocess (0.9.0)
13
+ ffi (~> 1.0, >= 1.0.11)
14
+ coderay (1.1.2)
15
+ diff-lcs (1.3)
16
+ docile (1.3.1)
17
+ ffi (1.9.25)
18
+ jaro_winkler (1.5.1)
19
+ json (2.1.0)
20
+ method_source (0.9.2)
21
+ parallel (1.12.1)
22
+ parser (2.5.3.0)
23
+ ast (~> 2.4.0)
24
+ powerpack (0.1.2)
25
+ pry (0.12.2)
26
+ coderay (~> 1.1.0)
27
+ method_source (~> 0.9.0)
28
+ pry-byebug (3.6.0)
29
+ byebug (~> 10.0)
30
+ pry (~> 0.10)
31
+ rainbow (3.0.0)
32
+ rake (10.5.0)
33
+ rspec (3.8.0)
34
+ rspec-core (~> 3.8.0)
35
+ rspec-expectations (~> 3.8.0)
36
+ rspec-mocks (~> 3.8.0)
37
+ rspec-core (3.8.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-expectations (3.8.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-mocks (3.8.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-support (3.8.0)
46
+ rubocop (0.59.2)
47
+ jaro_winkler (~> 1.5.1)
48
+ parallel (~> 1.10)
49
+ parser (>= 2.5, != 2.5.1.1)
50
+ powerpack (~> 0.1)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (~> 1.0, >= 1.0.1)
54
+ ruby-progressbar (1.10.0)
55
+ simplecov (0.16.1)
56
+ docile (~> 1.1)
57
+ json (>= 1.8, < 3)
58
+ simplecov-html (~> 0.10.0)
59
+ simplecov-html (0.10.2)
60
+ unicode-display_width (1.4.1)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ activek8s!
67
+ bundler (~> 1.17)
68
+ pry-byebug (~> 3.6)
69
+ rake (~> 10.0)
70
+ rspec (~> 3.0)
71
+ rubocop (~> 0.59.0)
72
+ simplecov (~> 0.16.1)
73
+
74
+ BUNDLED WITH
75
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Fernando Valverde Arredondo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Activek8s
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activek8s`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'activek8s'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install activek8s
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activek8s.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/activek8s.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'activek8s/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'activek8s'
7
+ spec.version = Activek8s::VERSION
8
+ spec.authors = ['Fernando Valverde Arredondo']
9
+ spec.email = ['fdov88@gmail.com']
10
+
11
+ spec.summary = 'Kubernetes integration to Rails apps via Rake tasks'
12
+ spec.description = 'Kubernetes integration to Rails apps via Rake tasks'
13
+ spec.homepage = 'https://github.com/fdoxyz/activek8s'
14
+ spec.license = 'MIT'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been
18
+ # added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'childprocess', '~> 0.9.0'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.17'
31
+ spec.add_development_dependency 'pry-byebug', '~> 3.6'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.59.0'
35
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
36
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'activek8s'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,13 @@
1
+ module Activek8s
2
+ # Railtie for Rails integration
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ load 'tasks/build_deployment.rake'
6
+ load 'tasks/deploy.rake'
7
+ load 'tasks/delete.rake'
8
+ load 'tasks/port_forward.rake'
9
+ load 'tasks/port_forward_many.rake'
10
+ load 'tasks/kibana.rake'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Activek8s
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/activek8s.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'activek8s/version'
2
+ require 'activek8s/railtie' if defined?(Rails)
3
+
4
+ # Main module definition
5
+ module Activek8s
6
+ end
@@ -0,0 +1,14 @@
1
+ namespace 'k8s' do
2
+ desc 'Builds the deployment.yml file for execution on a cluster'
3
+ task :build_deployment, [:namespace, :tag] do |_t, args|
4
+ args.with_defaults(namespace: 'dev', tag: 'latest')
5
+
6
+ deployment = File.read('kube/deployment.yml')
7
+
8
+ deployment.gsub!('{{NAMESPACE}}', args.namespace)
9
+ deployment.gsub!('{{IMAGE_TAG}}', args.tag)
10
+
11
+ deployment_path = ENV['K8S_DEPLOYMENT_FILE'] || 'kube/last_deployment.yml'
12
+ File.write(deployment_path, deployment)
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ namespace 'k8s' do
2
+ desc 'Deletes the current microservice TAG version on a specific NAMESPACE'
3
+ task :delete, [:namespace, :tag, :cleanup] do |_t, args|
4
+ deployment_path = ENV['K8S_DEPLOYMENT_FILE'] || 'kube/last_deployment.yml'
5
+ Rake::Task['k8s:build_deployment'].invoke(args.namespace, args.tag)
6
+
7
+ sh %{kubectl delete -f #{deployment_path}} do |ok, res|
8
+ cleanup = args.cleanup && File.exist?(deployment_path)
9
+ File.delete(deployment_path) if cleanup
10
+
11
+ raise "Error deleting deployment! (status = #{res.exitstatus})" unless ok
12
+
13
+ puts 'Deployment successfully deleted!'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ namespace 'k8s' do
2
+ desc 'Deploys the current microservice TAG version on a specific NAMESPACE'
3
+ task :deploy, [:namespace, :tag, :cleanup] do |_t, args|
4
+ deployment_path = ENV['K8S_DEPLOYMENT_FILE'] || 'kube/last_deployment.yml'
5
+ Rake::Task['k8s:build_deployment'].invoke(args.namespace, args.tag)
6
+
7
+ sh %{kubectl apply -f #{deployment_path}} do |ok, res|
8
+ cleanup = args.cleanup && File.exist?(deployment_path)
9
+ File.delete(deployment_path) if cleanup
10
+
11
+ raise "Error deploying! (status = #{res.exitstatus})" unless ok
12
+
13
+ puts 'Deployment successfully applied!'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ namespace 'k8s' do
2
+ desc 'Port forwards kibana to access logs'
3
+ task :kibana, [:namespace, :port] do |_t, args|
4
+ args.with_defaults(namespace: 'logging', port: '5601')
5
+ Rake::Task['k8s:port_forward'].invoke(args.namespace,
6
+ 'kibana',
7
+ args.port,
8
+ args.port)
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ namespace 'k8s' do
2
+ desc 'Port forwards a microservice from a specific NAMESPACE to a PORT'
3
+ task :port_forward,
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
+ puts 'WARNING: Unable to load default metadata from "kube/deployment.yml"'
11
+ own_name = 'CHECK DOCS AT -> https://github.com/fdoxyz/activek8s'
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,40 @@
1
+ namespace 'k8s' do
2
+ desc 'Port forwards many services from a specific NAMESPACE'
3
+ task :port_forward_many, [:namespace, :first_port, :services] do |_t, args|
4
+ # default "empty char" separated services to be port-forwarded from ENV
5
+ args.with_defaults(namespace: 'dev',
6
+ first_port: '3001',
7
+ services: ENV['K8S_SERVICES'].to_s)
8
+
9
+ # Build 'dynamic' values
10
+ services = args.services.split(' ').each_with_index.map do |name, index|
11
+ port = args.first_port.to_i + index
12
+ export_env = "#{name.upcase}_SERVICE_URL"
13
+ {
14
+ port: port,
15
+ rake_task: "k8s:port_forward[#{args.namespace},#{name},#{port},3000]",
16
+ env: "#{export_env}=http://localhost:#{port}/"
17
+ }
18
+ end
19
+
20
+ # Export ENV variables
21
+ env_file = services.map { |service| service[:env] }.join("\n")
22
+ File.write('services.env', env_file)
23
+
24
+ # Execute each 'rake_task' in a child process until CTRL+C is received
25
+ begin
26
+ processes = services.map do |service|
27
+ ChildProcess.build('bin/rake', service[:rake_task])
28
+ end
29
+ processes.each(&:start)
30
+
31
+ puts 'Services should be port forwarded to localhost in a few seconds.'
32
+ puts 'Execute ". services.env" to source each service URL.'
33
+ loop { sleep 3 }
34
+ rescue Interrupt
35
+ puts "\nExiting child processes..."
36
+ processes.each(&:stop)
37
+ puts 'Done!'
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activek8s
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fernando Valverde Arredondo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: childprocess
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.59.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.59.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.16.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.16.1
111
+ description: Kubernetes integration to Rails apps via Rake tasks
112
+ email:
113
+ - fdov88@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - activek8s.gemspec
128
+ - bin/console
129
+ - bin/setup
130
+ - lib/activek8s.rb
131
+ - lib/activek8s/railtie.rb
132
+ - lib/activek8s/version.rb
133
+ - lib/tasks/build_deployment.rake
134
+ - lib/tasks/delete.rake
135
+ - lib/tasks/deploy.rake
136
+ - lib/tasks/kibana.rake
137
+ - lib/tasks/port_forward.rake
138
+ - lib/tasks/port_forward_many.rake
139
+ homepage: https://github.com/fdoxyz/activek8s
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.7.8
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Kubernetes integration to Rails apps via Rake tasks
163
+ test_files: []