kuby-core 0.9.1 → 0.10.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8202396d9daaa1ccba46f2b607f90b64e615b9d44a2f87cbfef1682dadd8a8d1
4
- data.tar.gz: a6ad5b2436b1aacdc097ffd2ff03a2ad993d62747f6e8a54126239c0c42ac628
3
+ metadata.gz: f61bf7246e7fed1b51421252d1fee25da0bf1ad35da792e9f705d306ad5aeeba
4
+ data.tar.gz: fcaed876fd5da816cd1458c41c19fc735a7d3e5de2d23879427c526f2f0f94ea
5
5
  SHA512:
6
- metadata.gz: 2f1c577697475d726c38a74f20ec881613e03be19de90dc4843cee795fe54ec69cdfd23296e60c56db3611707fc397408ca7bbddf257b8a70c84af65d5cf2edd
7
- data.tar.gz: a732245dd7b3a23aa7a0bfeaa8c53b7f057c1a60ac5d4a667b11c966fcc31354df068276624e0c5d8a8c893ef1ea6e779d602087a6ed86ccbdb507664e69abbf
6
+ metadata.gz: 78f6cad56fd00b1265a43ac36169da5d46b15c50ceb5afce6f519ef175ff3949f84204ccf40ad9531b9dbb6b357d38ac0396e6969d848bfb17b42ba1c273ba6d
7
+ data.tar.gz: 056b9a151fd6f11079eb87fd5c0b7c4f92087cd8455a361ac7e668e9b94e4fc99a866b91c4f30d0a3eda582b0c2cafaac2e3ee882daebec0a52f1fd748786871
@@ -1,3 +1,12 @@
1
+ ## 0.10.0
2
+ * Set default database user and password in dev environment.
3
+ * Add ability to run rake tasks in dev environment.
4
+ * Disallow running rails and rake tasks in non-dev environments.
5
+ * Don't run database config through ERB.
6
+ - Rails env often isn't loaded, so ERB rendering can blow up with `NoMethodError`s, etc.
7
+ - All we really need to know is what database engine to stand up.
8
+ * Require database user/password to be added manually to Kuby config.
9
+
1
10
  ## 0.9.1
2
11
  * Run dev setup when asked to.
3
12
  - Bug caused dev setup to be skipped even when requested.
@@ -23,6 +23,8 @@ module Kuby
23
23
  autoload :TrailingHash, 'kuby/trailing_hash'
24
24
 
25
25
  DEFAULT_ENV = 'development'.freeze
26
+ DEFAULT_DB_USER = 'root'.freeze
27
+ DEFAULT_DB_PASSWORD = 'password'.freeze
26
28
 
27
29
  class UndefinedEnvironmentError < StandardError; end
28
30
  class MissingConfigError < StandardError; end
@@ -52,6 +54,11 @@ module Kuby
52
54
  kubernetes do
53
55
  add_plugin(:rails_app) do
54
56
  tls_enabled false
57
+
58
+ database do
59
+ user(DEFAULT_DB_USER) if respond_to?(:user)
60
+ password(DEFAULT_DB_PASSWORD) if respond_to?(:password)
61
+ end
55
62
  end
56
63
 
57
64
  provider :docker_desktop
@@ -17,9 +17,9 @@ module Kuby
17
17
  # is no singleton class version of #prepend in the Ruby language).
18
18
  singleton_class.send(:prepend, Module.new do
19
19
  def run(args)
20
- if idx = args.index('rails')
21
- @rails_options = args[(idx + 1)..-1]
22
- super(args[0..(idx + 1)])
20
+ if idx = args.index('rails') || idx = args.index('rake')
21
+ @rails_options = args[idx..-1]
22
+ super(args[0..idx])
23
23
  else
24
24
  super
25
25
  end
@@ -27,7 +27,13 @@ module Kuby
27
27
  end)
28
28
 
29
29
  def self.tasks
30
- Kuby::Tasks.new(Kuby.definition.environment)
30
+ Kuby::Tasks.new(Kuby.environment)
31
+ end
32
+
33
+ def self.must_be_dev_env!
34
+ unless Kuby.environment.development?
35
+ fail "Command not supported in the '#{Kuby.environment.name}' environment"
36
+ end
31
37
  end
32
38
 
33
39
  program_desc 'Kuby command-line interface. Kuby is a convention '\
@@ -57,9 +63,16 @@ module Kuby
57
63
  # commands are handled by the RailsCommands class.
58
64
  desc 'Runs a Rails command.'
59
65
  command :rails do |rc|
66
+ rc.action do |global_options, options, args|
67
+ must_be_dev_env!
68
+ exit 1 unless tasks.dev_deployment_ok
69
+ Kuby::RailsCommands.run(@rails_options)
70
+ end
71
+
60
72
  rc.desc 'Runs the rails server (run `rails server --help` for options)'
61
73
  rc.command [:server, :s] do |c|
62
74
  c.action do |global_options, options, args|
75
+ must_be_dev_env!
63
76
  exit 1 unless tasks.dev_deployment_ok
64
77
  Kuby::RailsCommands.run(@rails_options)
65
78
  end
@@ -68,6 +81,7 @@ module Kuby
68
81
  rc.desc 'Runs a script in the Rails environment (run `rails runner --help` for options)'
69
82
  rc.command [:runner, :r] do |c|
70
83
  c.action do |global_options, options, args|
84
+ must_be_dev_env!
71
85
  exit 1 unless tasks.dev_deployment_ok
72
86
  Kuby::RailsCommands.run(@rails_options)
73
87
  end
@@ -77,12 +91,22 @@ module Kuby
77
91
  '(run `rails console --help` for options)'
78
92
  rc.command [:console, :c] do |c|
79
93
  c.action do |global_options, options, args|
94
+ must_be_dev_env!
80
95
  exit 1 unless tasks.dev_deployment_ok
81
96
  Kuby::RailsCommands.run(@rails_options)
82
97
  end
83
98
  end
84
99
  end
85
100
 
101
+ desc 'Runs a rake task.'
102
+ command :rake do |rc|
103
+ rc.action do |global_options, options, args|
104
+ must_be_dev_env!
105
+ exit 1 unless tasks.dev_deployment_ok
106
+ Kuby::RailsCommands.run(@rails_options)
107
+ end
108
+ end
109
+
86
110
  desc 'Builds the Docker image.'
87
111
  command :build do |c|
88
112
  c.action do |global_options, options, args|
@@ -1,4 +1,3 @@
1
- require 'erb'
2
1
  require 'yaml'
3
2
 
4
3
  module Kuby
@@ -51,7 +50,7 @@ module Kuby
51
50
  end
52
51
 
53
52
  def db_configs
54
- @db_configs ||= YAML.load(ERB.new(File.read(db_config_path)).result)
53
+ @db_configs ||= YAML.load(File.read(db_config_path))
55
54
  end
56
55
 
57
56
  def db_config_path
@@ -6,10 +6,14 @@ class KubyGenerator < Rails::Generators::Base
6
6
  create_file(
7
7
  'kuby.rb',
8
8
  <<~END
9
+ require 'active_support/core_ext'
9
10
  require 'active_support/encrypted_configuration'
10
11
 
11
12
  # Define a production Kuby deploy environment
12
13
  Kuby.define(:production) do
14
+ # Because the Rails environment isn't always loaded when
15
+ # your Kuby config is loaded, provide access to Rails
16
+ # credentials manually.
13
17
  app_creds = ActiveSupport::EncryptedConfiguration.new(
14
18
  config_path: File.join('config', 'credentials.yml.enc'),
15
19
  key_path: File.join('config', 'master.key'),
@@ -35,7 +39,13 @@ class KubyGenerator < Rails::Generators::Base
35
39
 
36
40
  kubernetes do
37
41
  # Add a plugin that facilitates deploying a Rails app.
38
- add_plugin :rails_app
42
+ add_plugin :rails_app do
43
+ # configure database credentials
44
+ database do
45
+ user app_creds[:KUBY_DB_USER]
46
+ password app_creds[:KUBY_DB_PASSWORD]
47
+ end
48
+ end
39
49
 
40
50
  # Use Docker Desktop as the provider.
41
51
  # See: https://www.docker.com/products/docker-desktop
@@ -12,9 +12,6 @@ module Kuby
12
12
  def initialize(environment, configs)
13
13
  @environment = environment
14
14
  @configs = configs
15
-
16
- user(config['username'])
17
- password(config['password'])
18
15
  end
19
16
 
20
17
  def name
@@ -32,6 +32,7 @@ module Kuby
32
32
  @asset_url = DEFAULT_ASSET_URL
33
33
  @packs_url = DEFAULT_PACKS_URL
34
34
  @asset_path = DEFAULT_ASSET_PATH
35
+ @database = Database.get(self)
35
36
  end
36
37
 
37
38
  def configure(&block)
@@ -41,7 +42,7 @@ module Kuby
41
42
  def after_configuration
42
43
  context = self
43
44
 
44
- if @database = Database.get(self)
45
+ if database
45
46
  environment.kubernetes.plugins[database.plugin_name] = @database.plugin
46
47
  environment.kubernetes.add_plugin(:kube_db)
47
48
 
@@ -70,6 +71,10 @@ module Kuby
70
71
  end
71
72
  end
72
73
 
74
+ def database_host
75
+ database.plugin.host
76
+ end
77
+
73
78
  def before_deploy(manifest)
74
79
  # Make sure plugin has been configured. If not, do nothing.
75
80
  if cert_manager = environment.kubernetes.plugin(:cert_manager)
@@ -109,7 +114,7 @@ module Kuby
109
114
  end
110
115
 
111
116
  def database(&block)
112
- @database.instance_eval(&block) if block
117
+ @database.plugin.instance_eval(&block) if block
113
118
  @database
114
119
  end
115
120
 
@@ -34,23 +34,29 @@ module Kuby
34
34
  end
35
35
 
36
36
  class RailsCommands
37
- PREFIX = %w(bundle exec rails).freeze
37
+ PREFIX = %w(bundle exec).freeze
38
38
  SERVER_ARG_ALIASES = [['--binding', '-b'], ['-p', '--port']].freeze
39
39
 
40
40
  class << self
41
41
  def run(args = ARGV)
42
- subcommand = args[0]
43
- arglist = nil
44
-
45
- case subcommand
46
- when 'server', 's'
47
- arglist = Args.new([*PREFIX, *args], SERVER_ARG_ALIASES)
48
- arglist['-b'] ||= '0.0.0.0'
49
- arglist['-p'] ||= '3000'
50
- when 'runner', 'r'
51
- when 'console', 'c'
52
- else
53
- return
42
+ command = args[0]
43
+
44
+ if command == 'rails'
45
+ subcommand = args[1]
46
+ arglist = nil
47
+
48
+ case subcommand
49
+ when 'server', 's'
50
+ arglist = Args.new([*PREFIX, *args], SERVER_ARG_ALIASES)
51
+ arglist['-b'] ||= '0.0.0.0'
52
+ arglist['-p'] ||= '3000'
53
+ when 'runner', 'r'
54
+ when 'console', 'c'
55
+ else
56
+ return
57
+ end
58
+ elsif command == 'rake'
59
+ arglist = Args.new([*PREFIX, *args])
54
60
  end
55
61
 
56
62
  setup
@@ -63,13 +69,7 @@ module Kuby
63
69
  private
64
70
 
65
71
  def setup
66
- require 'rubygems'
67
- require 'bundler'
68
-
69
- Bundler.setup
70
-
71
72
  require 'kuby'
72
-
73
73
  Kuby.load!
74
74
  end
75
75
 
@@ -146,7 +146,7 @@ module Kuby
146
146
  STDOUT.write('Set up development environment? (y/n): ')
147
147
  answer = STDIN.gets.strip.downcase
148
148
  return false unless answer =~ /ye?s?/
149
- DevSetup.new(environment).run
149
+ return DevSetup.new(environment).run
150
150
  else
151
151
  depl = deployments.first
152
152
  deployed_checksum = depl.dig('metadata', 'annotations', 'getkuby.io/dockerfile-checksum')
@@ -161,7 +161,7 @@ module Kuby
161
161
  # return true here to prevent letting an out-of-date deployment
162
162
  # stop us from running commands
163
163
  return true unless answer =~ /ye?s?/
164
- DevSetup.new(environment).run
164
+ return DevSetup.new(environment).run
165
165
  end
166
166
  end
167
167
 
@@ -1,3 +1,3 @@
1
1
  module Kuby
2
- VERSION = '0.9.1'
2
+ VERSION = '0.10.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-11 00:00:00.000000000 Z
11
+ date: 2020-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize