kuby-core 0.5.0 → 0.7.2

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -0
  3. data/kuby-core.gemspec +4 -1
  4. data/lib/kuby.rb +23 -17
  5. data/lib/kuby/definition.rb +20 -14
  6. data/lib/kuby/docker.rb +2 -1
  7. data/lib/kuby/docker/alpine.rb +0 -1
  8. data/lib/kuby/docker/assets_phase.rb +1 -1
  9. data/lib/kuby/docker/bundler_phase.rb +4 -2
  10. data/lib/kuby/docker/cli.rb +32 -0
  11. data/lib/kuby/docker/copy_phase.rb +1 -1
  12. data/lib/kuby/docker/errors.rb +1 -0
  13. data/lib/kuby/docker/inline_layer.rb +15 -0
  14. data/lib/kuby/docker/{phase.rb → layer.rb} +6 -5
  15. data/lib/kuby/docker/layer_stack.rb +30 -4
  16. data/lib/kuby/docker/metadata.rb +10 -2
  17. data/lib/kuby/docker/package_phase.rb +1 -1
  18. data/lib/kuby/docker/setup_phase.rb +1 -1
  19. data/lib/kuby/docker/spec.rb +4 -4
  20. data/lib/kuby/docker/timestamp_tag.rb +6 -3
  21. data/lib/kuby/docker/webserver_phase.rb +1 -1
  22. data/lib/kuby/docker/yarn_phase.rb +1 -1
  23. data/lib/kuby/environment.rb +22 -0
  24. data/lib/kuby/kubernetes/minikube_provider.rb +5 -5
  25. data/lib/kuby/kubernetes/plugins/nginx_ingress.rb +12 -0
  26. data/lib/kuby/kubernetes/plugins/rails_app/database.rb +30 -9
  27. data/lib/kuby/kubernetes/plugins/rails_app/generators/kuby.rb +43 -4
  28. data/lib/kuby/kubernetes/plugins/rails_app/mysql.rb +14 -4
  29. data/lib/kuby/kubernetes/plugins/rails_app/plugin.rb +15 -14
  30. data/lib/kuby/kubernetes/plugins/rails_app/postgres.rb +132 -0
  31. data/lib/kuby/kubernetes/plugins/rails_app/sqlite.rb +20 -0
  32. data/lib/kuby/kubernetes/plugins/rails_app/tasks.rake +9 -4
  33. data/lib/kuby/kubernetes/spec.rb +1 -1
  34. data/lib/kuby/railtie.rb +0 -4
  35. data/lib/kuby/tasks.rb +31 -0
  36. data/lib/kuby/tasks/kuby.rake +19 -18
  37. data/lib/kuby/version.rb +1 -1
  38. data/spec/docker/timestamp_tag_spec.rb +11 -0
  39. data/spec/spec_helper.rb +102 -0
  40. metadata +23 -5
@@ -3,8 +3,28 @@ module Kuby
3
3
  module Plugins
4
4
  module RailsApp
5
5
  class Sqlite < Kuby::Kubernetes::Plugin
6
+ attr_reader :definition
7
+
8
+ def initialize(definition, *)
9
+ @definition = definition
10
+ end
11
+
12
+ def after_configuration
13
+ definition.docker.package_phase.add(:sqlite_dev)
14
+ definition.docker.package_phase.add(:sqlite_client)
15
+ end
6
16
  end
7
17
  end
8
18
  end
9
19
  end
10
20
  end
21
+
22
+ Kuby.register_package(:sqlite_dev,
23
+ debian: 'libsqlite3-dev',
24
+ alpine: 'sqlite-dev'
25
+ )
26
+
27
+ Kuby.register_package(:sqlite_client,
28
+ debian: 'sqlite3',
29
+ alpine: 'sqlite'
30
+ )
@@ -3,11 +3,16 @@ require 'rake'
3
3
  namespace :kuby do
4
4
  namespace :rails_app do
5
5
  namespace :db do
6
- task rewrite_config: :environment do
7
- config_file = Kuby.definition.app.root.join('config', 'database.yml')
6
+ task :rewrite_config do
7
+ Kuby.load!
8
+
9
+ config_file = File.join(Kuby.definition.kubernetes.plugin(:rails_app).root, 'config', 'database.yml')
8
10
  database = Kuby.definition.kubernetes.plugin(:rails_app).database
9
- File.write(config_file, YAML.dump(database.rewritten_configs))
10
- Kuby.logger.info("Wrote #{config_file}")
11
+
12
+ if database.respond_to?(:rewritten_configs)
13
+ File.write(config_file, YAML.dump(database.rewritten_configs))
14
+ Kuby.logger.info("Wrote #{config_file}")
15
+ end
11
16
  end
12
17
 
13
18
  task :create_unless_exists do
@@ -118,7 +118,7 @@ module Kuby
118
118
 
119
119
  @namespace ||= KubeDSL.namespace do
120
120
  metadata do
121
- name "#{spec.selector_app}-#{spec.definition.environment}"
121
+ name "#{spec.selector_app}-#{spec.definition.environment.name}"
122
122
  end
123
123
  end
124
124
 
@@ -7,10 +7,6 @@ module Kuby
7
7
  load File.expand_path(File.join('tasks', 'kuby.rake'), __dir__)
8
8
  end
9
9
 
10
- initializer 'kuby.startup' do |_app|
11
- Kuby.logger = Kuby::BasicLogger.new(STDERR)
12
- end
13
-
14
10
  initializer 'kuby.health_check_middleware' do |app|
15
11
  app.middleware.use Kuby::Middleware::HealthCheck
16
12
  end
@@ -16,6 +16,10 @@ module Kuby
16
16
  puts formatter.format(tokens)
17
17
  end
18
18
 
19
+ def setup
20
+ definition.kubernetes.setup
21
+ end
22
+
19
23
  def build
20
24
  docker.cli.build(
21
25
  dockerfile: docker.to_dockerfile,
@@ -35,6 +39,24 @@ module Kuby
35
39
  end
36
40
 
37
41
  def push
42
+ hostname = docker.metadata.image_hostname
43
+
44
+ unless docker.cli.auths.include?(hostname)
45
+ Kuby.logger.info("Attempting to log in to registry at #{hostname}")
46
+
47
+ begin
48
+ docker.cli.login(
49
+ url: docker.metadata.image_host,
50
+ username: docker.credentials.username,
51
+ password: docker.credentials.password
52
+ )
53
+ rescue Kuby::Docker::LoginError => e
54
+ Kuby.logger.fatal("Couldn't log in to the registry at #{hostname}")
55
+ Kuby.logger.fatal(e.message)
56
+ return
57
+ end
58
+ end
59
+
38
60
  image_url = docker.metadata.image_url
39
61
 
40
62
  begin
@@ -46,9 +68,18 @@ module Kuby
46
68
  'Docker image before running this task.'
47
69
 
48
70
  Kuby.logger.fatal(msg)
71
+ Kuby.logger.fatal(e.message)
49
72
  end
50
73
  end
51
74
 
75
+ def deploy
76
+ definition.kubernetes.deploy
77
+ end
78
+
79
+ def rollback
80
+ definition.kubernetes.rollback
81
+ end
82
+
52
83
  def print_resources
53
84
  kubernetes.before_deploy
54
85
 
@@ -2,67 +2,68 @@ require 'shellwords'
2
2
 
3
3
  namespace :kuby do
4
4
  def tasks
5
+ Kuby.load!
5
6
  @tasks ||= Kuby::Tasks.new(Kuby.definition)
6
7
  end
7
8
 
8
- task dockerfile: :environment do
9
+ task :dockerfile do
9
10
  tasks.print_dockerfile
10
11
  end
11
12
 
12
- task build: :environment do
13
+ task :build do
13
14
  tasks.build
14
15
  end
15
16
 
16
- task run: :environment do
17
+ task :run do
17
18
  tasks.run
18
19
  end
19
20
 
20
- task push: :environment do
21
+ task :push do
21
22
  tasks.push
22
23
  end
23
24
 
24
- task resources: :environment do
25
+ task :resources do
25
26
  tasks.print_resources
26
27
  end
27
28
 
28
- task :kubectl, [:cmd] => [:environment] do |_, args|
29
+ task :kubectl, [:cmd] do |_, args|
29
30
  tasks.kubectl(Shellwords.shellsplit(args[:cmd]))
30
31
  end
31
32
 
32
- task deploy: :environment do
33
- Kuby.definition.kubernetes.deploy
33
+ task :deploy do
34
+ tasks.deploy
34
35
  end
35
36
 
36
- task rollback: :environment do
37
- Kuby.definition.kubernetes.rollback
37
+ task :rollback do
38
+ tasks.rollback
38
39
  end
39
40
 
40
- task kubeconfig: :environment do
41
+ task :kubeconfig do
41
42
  tasks.print_kubeconfig
42
43
  end
43
44
 
44
- task setup: :environment do
45
- Kuby.definition.kubernetes.setup
45
+ task :setup do
46
+ tasks.setup
46
47
  end
47
48
 
48
49
  namespace :remote do
49
- task logs: :environment do
50
+ task :logs do
50
51
  tasks.remote_logs
51
52
  end
52
53
 
53
- task status: :environment do
54
+ task :status do
54
55
  tasks.remote_status
55
56
  end
56
57
 
57
- task shell: :environment do
58
+ task :shell do
58
59
  tasks.remote_shell
59
60
  end
60
61
 
61
- task console: :environment do
62
+ task :console do
62
63
  tasks.remote_console
63
64
  end
64
65
 
65
- task dbconsole: :environment do
66
+ task :dbconsole do
66
67
  tasks.remote_dbconsole
67
68
  end
68
69
  end
@@ -1,3 +1,3 @@
1
1
  module Kuby
2
- VERSION = '0.5.0'
2
+ VERSION = '0.7.2'
3
3
  end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe Kuby::Docker::TimestampTag do
4
+ context ".try_parse" do
5
+ it "returns a new timestamp tag" do
6
+ tag = described_class.try_parse("20200810165134")
7
+
8
+ expect(tag).to be_kind_of(described_class)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,102 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
101
+
102
+ require "kuby"
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.5.0
4
+ version: 0.7.2
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-07-31 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.1'
61
+ version: '0.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.1'
68
+ version: '0.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: kube-dsl
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: Deploy your Rails app onto Kubernetes the easy way.
140
154
  email:
141
155
  - camertron@gmail.com
@@ -164,6 +178,8 @@ files:
164
178
  - lib/kuby/docker/debian.rb
165
179
  - lib/kuby/docker/dockerfile.rb
166
180
  - lib/kuby/docker/errors.rb
181
+ - lib/kuby/docker/inline_layer.rb
182
+ - lib/kuby/docker/layer.rb
167
183
  - lib/kuby/docker/layer_stack.rb
168
184
  - lib/kuby/docker/local_tags.rb
169
185
  - lib/kuby/docker/metadata.rb
@@ -175,7 +191,6 @@ files:
175
191
  - lib/kuby/docker/packages/package.rb
176
192
  - lib/kuby/docker/packages/simple_managed_package.rb
177
193
  - lib/kuby/docker/packages/yarn.rb
178
- - lib/kuby/docker/phase.rb
179
194
  - lib/kuby/docker/remote_tags.rb
180
195
  - lib/kuby/docker/setup_phase.rb
181
196
  - lib/kuby/docker/spec.rb
@@ -183,6 +198,7 @@ files:
183
198
  - lib/kuby/docker/timestamp_tag.rb
184
199
  - lib/kuby/docker/webserver_phase.rb
185
200
  - lib/kuby/docker/yarn_phase.rb
201
+ - lib/kuby/environment.rb
186
202
  - lib/kuby/kubernetes.rb
187
203
  - lib/kuby/kubernetes/deploy_task.rb
188
204
  - lib/kuby/kubernetes/deployer.rb
@@ -212,6 +228,8 @@ files:
212
228
  - lib/kuby/tasks/kuby.rake
213
229
  - lib/kuby/trailing_hash.rb
214
230
  - lib/kuby/version.rb
231
+ - spec/docker/timestamp_tag_spec.rb
232
+ - spec/spec_helper.rb
215
233
  homepage: http://github.com/getkuby/kuby-core
216
234
  licenses: []
217
235
  metadata: {}