Module: Kuby

Defined in:
lib/kuby/plugin.rb,
lib/kuby.rb,
lib/kuby/tasks.rb,
lib/kuby/utils.rb,
lib/kuby/docker.rb,
lib/kuby/plugins.rb,
lib/kuby/railtie.rb,
lib/kuby/version.rb,
lib/kuby/cli_base.rb,
lib/kuby/commands.rb,
lib/kuby/definition.rb,
lib/kuby/dependable.rb,
lib/kuby/dependency.rb,
lib/kuby/docker/cli.rb,
lib/kuby/kubernetes.rb,
lib/kuby/middleware.rb,
lib/kuby/docker/spec.rb,
lib/kuby/environment.rb,
lib/kuby/utils/table.rb,
lib/kuby/utils/which.rb,
lib/kuby/basic_logger.rb,
lib/kuby/docker/image.rb,
lib/kuby/docker/layer.rb,
lib/kuby/docker/alpine.rb,
lib/kuby/docker/debian.rb,
lib/kuby/docker/distro.rb,
lib/kuby/docker/errors.rb,
lib/kuby/trailing_hash.rb,
lib/kuby/utils/sem_ver.rb,
lib/kuby/plugins/system.rb,
lib/kuby/docker/packages.rb,
lib/kuby/kubernetes/spec.rb,
lib/kuby/plugin_registry.rb,
lib/kuby/docker/app_image.rb,
lib/kuby/docker/app_phase.rb,
lib/kuby/docker/copy_phase.rb,
lib/kuby/docker/docker_uri.rb,
lib/kuby/docker/dockerfile.rb,
lib/kuby/docker/local_tags.rb,
lib/kuby/docker/yarn_phase.rb,
lib/kuby/kubernetes/errors.rb,
lib/kuby/plugins/rails_app.rb,
lib/kuby/docker/credentials.rb,
lib/kuby/docker/layer_stack.rb,
lib/kuby/docker/remote_tags.rb,
lib/kuby/docker/setup_phase.rb,
lib/kuby/docker/assets_phase.rb,
lib/kuby/docker/inline_layer.rb,
lib/kuby/docker/package_list.rb,
lib/kuby/kubernetes/deployer.rb,
lib/kuby/kubernetes/manifest.rb,
lib/kuby/kubernetes/provider.rb,
lib/kuby/docker/bundler_phase.rb,
lib/kuby/docker/package_phase.rb,
lib/kuby/docker/packages/yarn.rb,
lib/kuby/docker/timestamp_tag.rb,
lib/kuby/plugins/nginx_ingress.rb,
lib/kuby/utils/sem_ver/version.rb,
lib/kuby/docker/packages/nodejs.rb,
lib/kuby/docker/webserver_phase.rb,
lib/kuby/kubernetes/deploy_task.rb,
lib/kuby/plugins/rails_app/crdb.rb,
lib/kuby/docker/packages/package.rb,
lib/kuby/middleware/health_check.rb,
lib/kuby/docker/timestamped_image.rb,
lib/kuby/kubernetes/docker_config.rb,
lib/kuby/plugins/rails_app/assets.rb,
lib/kuby/plugins/rails_app/plugin.rb,
lib/kuby/plugins/rails_app/sqlite.rb,
lib/kuby/utils/sem_ver/constraint.rb,
lib/kuby/kubernetes/registry_secret.rb,
lib/kuby/plugins/rails_app/database.rb,
lib/kuby/utils/sem_ver/constraint_set.rb,
lib/kuby/plugins/rails_app/crdb/plugin.rb,
lib/kuby/kubernetes/bare_metal_provider.rb,
lib/kuby/plugins/rails_app/assets_image.rb,
lib/kuby/docker/packages/managed_package.rb,
lib/kuby/plugins/rails_app/asset_copy_task.rb,
lib/kuby/kubernetes/docker_desktop_provider.rb,
lib/kuby/plugins/rails_app/rewrite_db_config.rb,
lib/kuby/docker/packages/simple_managed_package.rb

Overview

typed: strict

Defined Under Namespace

Modules: CockroachConsoleMonkeypatch, Docker, Kubernetes, Middleware, Plugins, Utils Classes: BasicLogger, CLIBase, Commands, Definition, Dependable, Dependency, Environment, MissingConfigError, Plugin, PluginRegistry, Railtie, Tasks, TrailingHash, UndefinedEnvironmentError

Constant Summary collapse

DEFAULT_ENV =
'development'.freeze
DEFAULT_DB_USER =
'root'.freeze
DEFAULT_DB_PASSWORD =
'password'.freeze
VERSION =
'0.20.2'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.definitionObject (readonly)

Returns the value of attribute definition.



39
40
41
# File 'lib/kuby.rb', line 39

def definition
  @definition
end

.loggerObject



100
101
102
# File 'lib/kuby.rb', line 100

def logger
  @logger ||= BasicLogger.new(STDERR)
end

Class Method Details

.define(name, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kuby.rb', line 52

def define(name, &block)
  raise 'Kuby is already configured' if @definition

  @definition = Definition.new(name.to_s)
  @definition.instance_eval(&block)

  @definition.environments.each do |_, env|
    env.kubernetes.after_configuration
  end

  @definition.environments.each do |_, env|
    env.configured = true
  end

  @definition
end

.dependablesObject



131
132
133
# File 'lib/kuby.rb', line 131

def dependables
  @dependables ||= {}
end

.distrosObject



92
93
94
# File 'lib/kuby.rb', line 92

def distros
  @distros ||= {}
end

.envObject



139
140
141
142
143
# File 'lib/kuby.rb', line 139

def env
  ENV.fetch('KUBY_ENV') do
    (@env || Rails.env rescue nil || DEFAULT_ENV).to_s
  end
end

.env=(env_name) ⇒ Object



135
136
137
# File 'lib/kuby.rb', line 135

def env=(env_name)
  @env = env_name.to_s
end

.environment(name = env) ⇒ Object



69
70
71
72
73
74
# File 'lib/kuby.rb', line 69

def environment(name = env)
  definition.environment(name.to_s) || raise(
    UndefinedEnvironmentError, "couldn't find a Kuby environment named "\
    "'#{name}'"
  )
end

.load!(config_file = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/kuby.rb', line 42

def load!(config_file = nil)
  config_file ||= ENV['KUBY_CONFIG'] || File.join('.', 'kuby.rb')

  unless File.exist?(config_file)
    raise MissingConfigError, "couldn't find Kuby config file at #{config_file}"
  end

  require config_file
end

.load_rake_tasks!Object



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/kuby.rb', line 145

def load_rake_tasks!
  Rake::TaskManager. = true

  Kuby.plugins.each do |_, plugin_klass|
    plugin_klass.task_dirs.each do |task_dir|
      Dir.glob(File.join(task_dir, '*.rake')).each do |path|
        Rake.load_rakefile(path)
      end
    end
  end
end

.packagesObject



123
124
125
# File 'lib/kuby.rb', line 123

def packages
  @packages ||= {}
end

.pluginsObject



96
97
98
# File 'lib/kuby.rb', line 96

def plugins
  @plugins ||= PluginRegistry.new
end

.providersObject



80
81
82
# File 'lib/kuby.rb', line 80

def providers
  @providers ||= {}
end

.register_dependable(name, version_or_callable) ⇒ Object



127
128
129
# File 'lib/kuby.rb', line 127

def register_dependable(name, version_or_callable)
  dependables[name] = Dependable.new(name, version_or_callable)
end

.register_distro(distro_name, distro_klass) ⇒ Object



88
89
90
# File 'lib/kuby.rb', line 88

def register_distro(distro_name, distro_klass)
  distros[distro_name] = distro_klass
end

.register_package(package_name, package_def = nil) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/kuby.rb', line 104

def register_package(package_name, package_def = nil)
  packages[package_name] = case package_def
    when NilClass
      Kuby::Docker::Packages::SimpleManagedPackage.new(
        package_name
      )
    when String
      Kuby::Docker::Packages::SimpleManagedPackage.new(
        package_def
      )
    when Hash
      Kuby::Docker::Packages::ManagedPackage.new(
        package_name, package_def
      )
    else
      package_def.new(package_name)
  end
end

.register_plugin(*args, **kwargs) ⇒ Object



84
85
86
# File 'lib/kuby.rb', line 84

def register_plugin(*args, **kwargs)
  plugins.register(*args, **kwargs)
end

.register_provider(provider_name, provider_klass) ⇒ Object



76
77
78
# File 'lib/kuby.rb', line 76

def register_provider(provider_name, provider_klass)
  providers[provider_name] = provider_klass
end