kplay 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5180ff7f8cd05626876ebf6c9354137a8b3fa5cd
4
+ data.tar.gz: d258a93821772f38a7e3bb2813a7735acde81fca
5
+ SHA512:
6
+ metadata.gz: ef83b0c6c793d7b2fc0dc22589ccca59b7cd8edbf12ea031cc74f1724eb254ab6b28e64309972abdb8b7746fd0298e8dbb17259e4f3d1bc63ff17f868ee15029
7
+ data.tar.gz: bb4c2ee638f81e59b3e9fc4d4c38a245085744a67269d3a956c84054b4d6f473d22c9fa48c909019782cf655b2e76a33db8e601f65ca04e4051f0996ef12b0a8
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /.kplay
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
@@ -0,0 +1,22 @@
1
+ stages:
2
+ - setup
3
+ - test
4
+
5
+ prepare:
6
+ stage: setup
7
+ cache:
8
+ key: gems
9
+ paths:
10
+ - vendor/bundle
11
+ script:
12
+ - bundle install --deployment
13
+
14
+ rspec:
15
+ stage: test
16
+ cache:
17
+ key: gems
18
+ paths:
19
+ - vendor/bundle
20
+ policy: pull
21
+ script:
22
+ - bundle exec rspec
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alex.kukushkin@cubits.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kplay.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Alex Kukushkin
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.
@@ -0,0 +1,41 @@
1
+ # Kplay
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/kplay`. 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 'kplay'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kplay
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]/kplay. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -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
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'kplay'
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
+ require 'pry'
10
+ Pry.start
@@ -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,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'kplay'
5
+
6
+ using Rainbow
7
+
8
+ begin
9
+ Kplay::CLI.start(ARGV)
10
+ rescue => e
11
+ if ENV['debug']
12
+ puts e
13
+ puts e.backtrace.join("\n")
14
+ end
15
+ abort 'ERROR: '.red + e.to_s
16
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kplay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kplay'
8
+ spec.version = Kplay::VERSION
9
+ spec.authors = ['Alex Kukushkin']
10
+ spec.email = ['alex.kukushkin@strongkeep.com']
11
+
12
+ spec.summary = 'Starts your project within a container in minikube'
13
+ spec.description = 'A tool to start a container in minikube and mount your project folder into it'
14
+ spec.homepage = ''
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ 'public gem pushes.'
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'thor', '~> 0.20'
34
+ spec.add_dependency 'rainbow', '~> 3.0'
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.14'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_development_dependency 'pry', '~> 0.11'
40
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ require 'rainbow/refinement'
3
+
4
+ require 'kplay/version'
5
+ require_relative 'kplay/system'
6
+ require_relative 'kplay/cli'
7
+ require_relative 'kplay/minikube'
8
+ require_relative 'kplay/config'
9
+ require_relative 'kplay/pod'
10
+ require_relative 'kplay/registry'
11
+
12
+ module Kplay
13
+ include System
14
+
15
+ DEFAULT_DATA_FOLDER = '~/.kplay'
16
+
17
+ #
18
+ # Checks if requirements are satisfied
19
+ #
20
+ def self.assert_requirements!
21
+ assert_program_presence!('minikube')
22
+ assert_program_presence!('kubectl')
23
+ end
24
+
25
+ # Returns path to data folder or its subfolders/files
26
+ #
27
+ def self.data_path(*paths)
28
+ Pathname.new(DEFAULT_DATA_FOLDER).join(*paths).expand_path
29
+ end
30
+
31
+ # Install data folder
32
+ #
33
+ def self.install_paths
34
+ sh ['install', '-p', data_path]
35
+ end
36
+ end # module Kplay
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal
2
+ require 'thor'
3
+
4
+ module Kplay
5
+ class CLI < Thor
6
+ using Rainbow
7
+
8
+ class_option :verbose, type: :boolean, aliases: :v, default: false
9
+
10
+ desc 'info', 'Displays environment info'
11
+ def info
12
+ print 'Checking requirements... '
13
+ Kplay.assert_requirements!
14
+ puts 'OK'.green
15
+
16
+ path = Dir.pwd
17
+ pod = Kplay::Pod.new(path)
18
+ puts " name: #{pod.name}"
19
+ puts "host path: #{pod.path_host}"
20
+ puts " vm path: #{pod.path_vm}"
21
+ puts
22
+ end
23
+
24
+ desc 'config', 'Displays local configuration'
25
+ def config
26
+ print 'Global config file: '
27
+ puts Kplay::Config.global.path.to_s.yellow
28
+ puts
29
+ config = Kplay::Config.local
30
+ puts config.to_h.to_yaml
31
+ end
32
+
33
+ desc 'status', 'Displays the cluster and container (pod) status'
34
+ def status
35
+ Kplay.assert_requirements!
36
+ Kplay.sh ['minikube', 'status']
37
+ pod = Kplay::Pod.new(Dir.pwd)
38
+ Kplay.sh ['kubectl', 'get', 'pods', pod.name] rescue nil
39
+ end
40
+
41
+ desc 'start', 'Starts a container (pod) with the local folder mounted inside'
42
+ option :image, aliases: :i, desc: 'Image to use'
43
+ def start
44
+ Kplay.assert_requirements!
45
+ pod = Kplay::Pod.new(Dir.pwd, Kplay::Config.local, options)
46
+ pod.start!
47
+ end
48
+
49
+ desc 'stop', 'Stops the container (pod) associated with the local folder'
50
+ def stop
51
+ Kplay.assert_requirements!
52
+ pod = Kplay::Pod.new(Dir.pwd, Kplay::Config.local, options)
53
+ pod.stop!
54
+ end
55
+
56
+ desc 'open', 'Opens a shell session into the container'
57
+ def open
58
+ Kplay.assert_requirements!
59
+ pod = Kplay::Pod.new(Dir.pwd, Kplay::Config.local, options)
60
+ pod.shell
61
+ end
62
+
63
+ desc 'play', '(default) Starts the container and opens a shell session into it'
64
+ option :image, aliases: :i, desc: 'Image to use'
65
+ def play
66
+ start
67
+ open
68
+ stop
69
+ end
70
+ default_task :play
71
+ end # class CLI
72
+ end # module Kplay
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+
4
+ module Kplay
5
+ #
6
+ # Represents the global or local configuration
7
+ #
8
+ class Config
9
+ GLOBAL_CONFIG_FILENAME = 'config'
10
+ GLOBAL_DEFAULTS = {
11
+ 'image' => 'dev',
12
+ 'mount_path' => '/${name}',
13
+ 'shell' => '/bin/bash',
14
+ 'shell_args' => ['-c', 'cd /${name}; exec "${SHELL:-sh}"'],
15
+ 'stop_grace_period' => 5
16
+ }.freeze
17
+
18
+ attr_reader :path, :data
19
+
20
+ def initialize(data = {}, path = nil)
21
+ @path = path ? Pathname.new(path).expand_path : nil
22
+ @data = data.dup
23
+ @extra_data = YAML.load(File.read(path)) if path && File.exist?(path)
24
+ @data = @data.merge(@extra_data) if @extra_data
25
+ end
26
+
27
+ def [](key)
28
+ value = data[key.to_s]
29
+ value = self.class.new(value) if value.is_a?(Hash)
30
+ value
31
+ end
32
+
33
+ def to_h
34
+ data.dup
35
+ end
36
+
37
+ # Expands templates in the values of the current config.
38
+ #
39
+ def expand_templates!(vars)
40
+ self.class.expand_templates!(@data, vars)
41
+ end
42
+
43
+ # In-place expansion of templates.
44
+ # Templates found in values are substituted with given vars
45
+ #
46
+ def self.expand_templates!(hash, vars)
47
+ hash.keys.each do |key|
48
+ case hash[key]
49
+ when String
50
+ hash[key] = expand_template(hash[key], vars)
51
+ when Array
52
+ hash[key] = hash[key].map { |t| expand_template(t, vars) }
53
+ when Hash
54
+ expand_templates!(hash[key], vars)
55
+ end
56
+ end
57
+ end
58
+
59
+ # Expand templates in given string value.
60
+ #
61
+ # Example:
62
+ # "${name}" -> "my-pod"
63
+ #
64
+ # @param text [String]
65
+ # @param vars [Hash]
66
+ #
67
+ def self.expand_template(text, vars)
68
+ vars.keys.reduce(text) do |t, var_name|
69
+ t.gsub("${#{var_name}}", vars[var_name].to_s)
70
+ end
71
+ end
72
+
73
+ def self.global
74
+ new(GLOBAL_DEFAULTS.dup, Kplay.data_path(GLOBAL_CONFIG_FILENAME))
75
+ end
76
+
77
+ def self.local
78
+ new(global.data, Pathname.pwd.join('.kplay'))
79
+ end
80
+ end # class Config
81
+ end # module Kplay
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kplay
4
+ module Minikube
5
+ # Returns the host folder, path on host.
6
+ #
7
+ # Host folder is the single folder Minikube mounts by default into the VM.
8
+ # Usually it's /home or /Users.
9
+ #
10
+ def self.hostfolder_host
11
+ case Kplay.host_os
12
+ when :linux
13
+ '/home/'
14
+ when :macosx
15
+ '/Users/'
16
+ else
17
+ raise 'Cannot identify mounted host folder, unknown OS'
18
+ end
19
+ end
20
+
21
+ # Returns the host folder mount point, path on minikube VM
22
+ #
23
+ def self.hostfolder_vm
24
+ case Kplay.host_os
25
+ when :linux
26
+ '/hosthome/'
27
+ when :macosx
28
+ '/Users/'
29
+ else
30
+ raise 'Cannot identify mounted host folder, unknown OS'
31
+ end
32
+ end
33
+
34
+ # Given the path on host returns the corresponding path in VM.
35
+ # Raises an error if the folder on host is not mounted.
36
+ #
37
+ # @param path_host [String] path to a folder on a host machine
38
+ # @return [String] corresponding path in VM
39
+ #
40
+ def self.host_path_in_vm(path_host)
41
+ unless path_host.to_s.start_with?(hostfolder_host.to_s)
42
+ raise ArgumentError, "Failed to find mount point for: '#{path_host}', parent is not mounted"
43
+ end
44
+ Pathname.new(path_host.to_s.sub(hostfolder_host.to_s, hostfolder_vm.to_s))
45
+ end
46
+ end # module Minikube
47
+ end # module Kplay
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'tempfile'
4
+
5
+ module Kplay
6
+ #
7
+ # Pod represents a pod associated with a folder on a host machine
8
+ #
9
+ class Pod
10
+ attr_reader :name, :config, :volume_name, :path_host, :path_vm, :mount_path, :options
11
+
12
+ # Creates a Pod from a path on host
13
+ #
14
+ # @param path_host [String]
15
+ # @param config [Config] local pod configuration options
16
+ # @param options [Hash] command execution options
17
+ #
18
+ def initialize(path_host, config = nil, options = {})
19
+ @path_host = path_host
20
+ @path_vm = Kplay::Minikube.host_path_in_vm(path_host)
21
+ @name = File.basename(path_host)
22
+ @config = config ? config : Kplay::Config.global
23
+ @config.expand_templates!(
24
+ name: name,
25
+ path_host: path_host,
26
+ path_vm: path_vm
27
+ )
28
+ @options = options
29
+ @volume_name = name + '-volume'
30
+ end
31
+
32
+ # Kubernetes configuration to run this pod
33
+ #
34
+ # @return [Hash]
35
+ #
36
+ def configuration
37
+ {
38
+ 'apiVersion' => 'v1',
39
+ 'kind' => 'Pod',
40
+ 'metadata' => { 'name' => name },
41
+ 'spec' => {
42
+ 'containers' => [
43
+ {
44
+ 'name' => name,
45
+ 'image' => options[:image] || config[:image],
46
+ 'imagePullPolicy' => 'IfNotPresent',
47
+ 'volumeMounts' => [
48
+ { 'mountPath' => config[:mount_path], 'name' => volume_name }
49
+ ]
50
+ }
51
+ ],
52
+ 'volumes' => [
53
+ {
54
+ 'name' => volume_name,
55
+ 'hostPath' => { 'path' => path_host }
56
+ }
57
+ ]
58
+ }
59
+ }
60
+ end
61
+
62
+ # Returns Kubernetes pod configuration in YAML
63
+ #
64
+ def configuration_yaml
65
+ configuration.to_yaml
66
+ end
67
+
68
+ # Runs the pod in Kubernetes cluster
69
+ #
70
+ def start!
71
+ with_configuration_file do |conf_file|
72
+ Kplay.sh ['kubectl', 'apply', '-f', conf_file.path], echo: options[:verbose]
73
+ end
74
+ sleep 1
75
+ end
76
+
77
+ # Stops the pod
78
+ #
79
+ def stop!
80
+ Kplay.sh(
81
+ ['kubectl', 'delete', 'pod', name, "--grace-period=#{config[:stop_grace_period]}", '--force'],
82
+ echo: options[:verbose]
83
+ )
84
+ end
85
+
86
+ # Runs a shell session inside the pod
87
+ #
88
+ def shell
89
+ Kplay.sh(
90
+ ['kubectl', 'exec', name, '-ti', config[:shell], '--', *config[:shell_args]],
91
+ tty: true,
92
+ echo: options[:verbose]
93
+ )
94
+ end
95
+
96
+ # Creates a temporary configuration file and returns it
97
+ #
98
+ # @return [Tempfile]
99
+ #
100
+ def temp_configuration_file
101
+ @temp_configuration_file ||= begin
102
+ tempfile = Tempfile.new("kplay-#{name}")
103
+ tempfile.write(configuration_yaml)
104
+ tempfile.close
105
+ tempfile
106
+ end
107
+ end
108
+
109
+ # Creates a temporary configuration file for the pod, yields it to the given block
110
+ # and then deletes it.
111
+ #
112
+ #
113
+ def with_configuration_file(&_block)
114
+ yield temp_configuration_file
115
+ ensure
116
+ temp_configuration_file.unlink
117
+ @temp_configuration_file = nil
118
+ end
119
+ end # class Pod
120
+ end # module Kplay
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kplay
4
+ #
5
+ # Represents the registry of started pods
6
+ #
7
+ module Registry
8
+ # Registers a pod started by given process
9
+ #
10
+ def self.register(pod_name, pid)
11
+ end
12
+
13
+ # Unregisters a pod started by given process
14
+ #
15
+ def self.unregister(pod_name, pid)
16
+ end
17
+
18
+ # Unregisters a pod for all processes
19
+ #
20
+ def self.unregister_all(pod_name)
21
+ end
22
+
23
+ # Returns true if the pod is registered for any process
24
+ #
25
+ def self.registered?(pod_name)
26
+ end
27
+
28
+ private # -ish
29
+
30
+ def self.storage_path
31
+
32
+ end
33
+ end # module Registry
34
+ end # module Kplay
@@ -0,0 +1,79 @@
1
+
2
+ # frozen_string_literal: true
3
+ require 'open3'
4
+
5
+ module Kplay
6
+ #
7
+ # Common system extensions
8
+ #
9
+ module System
10
+ def self.included(base)
11
+ base.send :extend, ClassMethods
12
+ end
13
+
14
+ # Class level methods
15
+ module ClassMethods
16
+ DEFAULT_SH_OPTS = {
17
+ echo: true,
18
+ output: true,
19
+ tty: false
20
+ }.freeze
21
+
22
+ # Executes a shell command on the host
23
+ #
24
+ # @param cmd [String] command to execute
25
+ # @param opts [Hash]
26
+ # @option opts [true,false] :echo echo command to stdout (default: true)
27
+ # @option opts [true,false] :output display (true) or suppress (false) commands output (default: true)
28
+ # @option opts [true,false] :tty attach a TTY (stdin is preserved and output is never suppressed), (default: false)
29
+ #
30
+ def sh(cmd, opts = {})
31
+ opts = DEFAULT_SH_OPTS.merge(opts)
32
+ cmd = [cmd] if cmd.is_a?(String)
33
+ puts cmd.join(' ') if opts[:echo]
34
+ exit_status = nil
35
+ if opts[:tty]
36
+ exit_status = system(*cmd) ? 0 : -1
37
+ else
38
+ out, status = Open3.capture2(*cmd)
39
+ puts out if opts[:output]
40
+ exit_status = status.exitstatus
41
+ end
42
+ raise "Failed to execute '#{cmd.join(' ')}' (#{exit_status})" unless exit_status == 0
43
+ end
44
+
45
+ # Checks if program with given name is present. Raises an error if the program is not found.
46
+ #
47
+ def assert_program_presence!(name)
48
+ sh(['which', name], echo: false, output: false)
49
+ rescue
50
+ raise "Failed to find required program: #{name}"
51
+ end
52
+
53
+ # Outputs a string to STDOUT without adding a line break
54
+ #
55
+ # @param text [String]
56
+ #
57
+ def print(text)
58
+ Kernel.print(text)
59
+ $stdout.flush
60
+ end
61
+
62
+ # Returns the OS identifier
63
+ #
64
+ # @return [Symbol] :linux, :macosx or :unknown
65
+ #
66
+ def host_os
67
+ name = `uname`.split(' ').first.downcase.to_sym
68
+ case name
69
+ when :linux
70
+ :linux
71
+ when :darwin
72
+ :macosx
73
+ else
74
+ :unknown
75
+ end
76
+ end
77
+ end # module ClassMethods
78
+ end # module System
79
+ end # module Kplay
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module Kplay
3
+ VERSION = '0.1.1'
4
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kplay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Kukushkin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.20'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rainbow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
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: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.11'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.11'
97
+ description: A tool to start a container in minikube and mount your project folder
98
+ into it
99
+ email:
100
+ - alex.kukushkin@strongkeep.com
101
+ executables:
102
+ - kplay
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".gitlab-ci.yml"
108
+ - ".rspec"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/setup
117
+ - exe/kplay
118
+ - kplay.gemspec
119
+ - lib/kplay.rb
120
+ - lib/kplay/cli.rb
121
+ - lib/kplay/config.rb
122
+ - lib/kplay/minikube.rb
123
+ - lib/kplay/pod.rb
124
+ - lib/kplay/registry.rb
125
+ - lib/kplay/system.rb
126
+ - lib/kplay/version.rb
127
+ homepage: ''
128
+ licenses:
129
+ - MIT
130
+ metadata:
131
+ allowed_push_host: https://rubygems.org
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.5.1
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Starts your project within a container in minikube
152
+ test_files: []