kuby-core 0.7.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/Gemfile +1 -0
  4. data/README.md +11 -1
  5. data/bin/kuby +4 -0
  6. data/kuby-core.gemspec +9 -4
  7. data/lib/kuby.rb +58 -19
  8. data/lib/kuby/basic_logger.rb +13 -0
  9. data/lib/kuby/cli_base.rb +81 -8
  10. data/lib/kuby/commands.rb +244 -0
  11. data/lib/kuby/definition.rb +1 -11
  12. data/lib/kuby/dev_setup.rb +255 -0
  13. data/lib/kuby/docker.rb +1 -0
  14. data/lib/kuby/docker/bundler_phase.rb +3 -3
  15. data/lib/kuby/docker/cli.rb +13 -1
  16. data/lib/kuby/docker/dev_spec.rb +131 -0
  17. data/lib/kuby/docker/dockerfile.rb +16 -1
  18. data/lib/kuby/docker/layer.rb +4 -4
  19. data/lib/kuby/docker/layer_stack.rb +4 -0
  20. data/lib/kuby/docker/local_tags.rb +4 -0
  21. data/lib/kuby/docker/metadata.rb +18 -38
  22. data/lib/kuby/docker/package_phase.rb +2 -2
  23. data/lib/kuby/docker/setup_phase.rb +3 -2
  24. data/lib/kuby/docker/spec.rb +42 -16
  25. data/lib/kuby/docker/timestamp_tag.rb +6 -0
  26. data/lib/kuby/environment.rb +15 -2
  27. data/lib/kuby/kubernetes.rb +9 -11
  28. data/lib/kuby/kubernetes/deploy_task.rb +4 -1
  29. data/lib/kuby/kubernetes/deployer.rb +70 -15
  30. data/lib/kuby/kubernetes/{minikube_provider.rb → docker_desktop_provider.rb} +8 -4
  31. data/lib/kuby/kubernetes/provider.rb +12 -8
  32. data/lib/kuby/kubernetes/spec.rb +30 -29
  33. data/lib/kuby/plugin.rb +59 -0
  34. data/lib/kuby/plugin_registry.rb +27 -0
  35. data/lib/kuby/plugins.rb +6 -0
  36. data/lib/kuby/plugins/nginx_ingress.rb +71 -0
  37. data/lib/kuby/plugins/rails_app.rb +18 -0
  38. data/lib/kuby/plugins/rails_app/asset_copy_task.rb +117 -0
  39. data/lib/kuby/plugins/rails_app/assets.rb +347 -0
  40. data/lib/kuby/plugins/rails_app/database.rb +74 -0
  41. data/lib/kuby/{kubernetes/plugins → plugins}/rails_app/generators/kuby.rb +14 -16
  42. data/lib/kuby/plugins/rails_app/mysql.rb +152 -0
  43. data/lib/kuby/plugins/rails_app/plugin.rb +593 -0
  44. data/lib/kuby/plugins/rails_app/postgres.rb +143 -0
  45. data/lib/kuby/plugins/rails_app/rewrite_db_config.rb +11 -0
  46. data/lib/kuby/plugins/rails_app/sqlite.rb +32 -0
  47. data/lib/kuby/plugins/rails_app/tasks.rake +36 -0
  48. data/lib/kuby/rails_commands.rb +89 -0
  49. data/lib/kuby/railtie.rb +0 -4
  50. data/lib/kuby/tasks.rb +85 -31
  51. data/lib/kuby/version.rb +1 -1
  52. data/spec/docker/metadata_spec.rb +84 -0
  53. data/spec/docker/spec_spec.rb +266 -0
  54. data/spec/docker/timestamp_tag_spec.rb +54 -4
  55. data/spec/dummy/Gemfile +54 -0
  56. data/spec/dummy/Gemfile.lock +223 -0
  57. data/spec/dummy/README.md +24 -0
  58. data/spec/dummy/Rakefile +6 -0
  59. data/spec/dummy/app/assets/config/manifest.js +2 -0
  60. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  61. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  62. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  63. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  64. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  65. data/spec/dummy/app/javascript/channels/consumer.js +6 -0
  66. data/spec/dummy/app/javascript/channels/index.js +5 -0
  67. data/spec/dummy/app/javascript/packs/application.js +17 -0
  68. data/spec/dummy/app/jobs/application_job.rb +7 -0
  69. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  70. data/spec/dummy/app/models/application_record.rb +3 -0
  71. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  72. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  73. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  74. data/spec/dummy/bin/bundle +114 -0
  75. data/spec/dummy/bin/rails +9 -0
  76. data/spec/dummy/bin/rake +9 -0
  77. data/spec/dummy/bin/setup +36 -0
  78. data/spec/dummy/bin/spring +17 -0
  79. data/spec/dummy/bin/yarn +11 -0
  80. data/spec/dummy/config.ru +5 -0
  81. data/spec/dummy/config/application.rb +19 -0
  82. data/spec/dummy/config/boot.rb +4 -0
  83. data/spec/dummy/config/cable.yml +10 -0
  84. data/spec/dummy/config/credentials.yml.enc +1 -0
  85. data/spec/dummy/config/database.yml +25 -0
  86. data/spec/dummy/config/environment.rb +5 -0
  87. data/spec/dummy/config/environments/development.rb +62 -0
  88. data/spec/dummy/config/environments/production.rb +112 -0
  89. data/spec/dummy/config/environments/test.rb +49 -0
  90. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  91. data/spec/dummy/config/initializers/assets.rb +14 -0
  92. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  93. data/spec/dummy/config/initializers/content_security_policy.rb +30 -0
  94. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  95. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  96. data/spec/dummy/config/initializers/inflections.rb +16 -0
  97. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  98. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/spec/dummy/config/locales/en.yml +33 -0
  100. data/spec/dummy/config/master.key +1 -0
  101. data/spec/dummy/config/puma.rb +38 -0
  102. data/spec/dummy/config/routes.rb +3 -0
  103. data/spec/dummy/config/spring.rb +6 -0
  104. data/spec/dummy/config/storage.yml +34 -0
  105. data/spec/dummy/db/seeds.rb +7 -0
  106. data/spec/dummy/package.json +11 -0
  107. data/spec/dummy/public/404.html +67 -0
  108. data/spec/dummy/public/422.html +67 -0
  109. data/spec/dummy/public/500.html +66 -0
  110. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  111. data/spec/dummy/public/apple-touch-icon.png +0 -0
  112. data/spec/dummy/public/favicon.ico +0 -0
  113. data/spec/dummy/public/robots.txt +1 -0
  114. data/spec/dummy/test/application_system_test_case.rb +5 -0
  115. data/spec/dummy/test/channels/application_cable/connection_test.rb +11 -0
  116. data/spec/dummy/test/test_helper.rb +13 -0
  117. data/spec/dummy/tmp/cache/bootsnap-load-path-cache +0 -0
  118. data/spec/spec_helper.rb +77 -2
  119. data/spec/support/docker/fake_cli.rb +54 -0
  120. data/spec/support/docker/remote/fake_client.rb +16 -0
  121. data/spec/trailing_hash_spec.rb +23 -0
  122. metadata +139 -30
  123. data/lib/ext/krane/kubernetes_resource.rb +0 -16
  124. data/lib/kuby/kubernetes/plugin.rb +0 -55
  125. data/lib/kuby/kubernetes/plugins.rb +0 -8
  126. data/lib/kuby/kubernetes/plugins/nginx_ingress.rb +0 -73
  127. data/lib/kuby/kubernetes/plugins/rails_app.rb +0 -16
  128. data/lib/kuby/kubernetes/plugins/rails_app/database.rb +0 -79
  129. data/lib/kuby/kubernetes/plugins/rails_app/mysql.rb +0 -154
  130. data/lib/kuby/kubernetes/plugins/rails_app/plugin.rb +0 -379
  131. data/lib/kuby/kubernetes/plugins/rails_app/postgres.rb +0 -142
  132. data/lib/kuby/kubernetes/plugins/rails_app/rewrite_db_config.rb +0 -13
  133. data/lib/kuby/kubernetes/plugins/rails_app/sqlite.rb +0 -30
  134. data/lib/kuby/kubernetes/plugins/rails_app/tasks.rake +0 -28
  135. data/lib/kuby/tasks/kuby.rake +0 -70
@@ -1,142 +0,0 @@
1
- require 'kube-dsl'
2
- require 'kuby/kube-db'
3
-
4
- module Kuby
5
- module Kubernetes
6
- module Plugins
7
- module RailsApp
8
- class Postgres < Kuby::Kubernetes::Plugin
9
- ROLE = 'web'.freeze
10
-
11
- attr_reader :definition, :environment, :configs
12
-
13
- def initialize(definition, environment, configs)
14
- @definition = definition
15
- @environment = environment
16
- @configs = configs
17
-
18
- user(config['username'])
19
- password(config['password'])
20
- end
21
-
22
- def resources
23
- @resources ||= [secret, database]
24
- end
25
-
26
- def after_configuration
27
- definition.docker.package_phase.add(:postgres_dev)
28
- definition.docker.package_phase.add(:postgres_client)
29
- end
30
-
31
- def host
32
- # host is the same as the name thanks to k8s DNS
33
- @host ||= database.metadata.name
34
- end
35
-
36
- def rewritten_configs
37
- # deep dup
38
- @rewritten_configs ||= Marshal.load(Marshal.dump(configs)).tap do |new_configs|
39
- new_configs[environment]['host'] = host
40
- end
41
- end
42
-
43
- def user(user)
44
- secret do
45
- data do
46
- set :POSTGRES_USER, user
47
- end
48
- end
49
- end
50
-
51
- def password(password)
52
- secret do
53
- data do
54
- set :POSTGRES_PASSWORD, password
55
- end
56
- end
57
- end
58
-
59
- def secret(&block)
60
- context = self
61
-
62
- @secret ||= KubeDSL.secret do
63
- metadata do
64
- name "#{context.base_name}-postgres-secret"
65
- namespace context.kubernetes.namespace.metadata.name
66
- end
67
-
68
- type 'Opaque'
69
- end
70
-
71
- @secret.instance_eval(&block) if block
72
- @secret
73
- end
74
-
75
- def database(&block)
76
- context = self
77
-
78
- @database ||= Kuby::KubeDB.postgres do
79
- api_version 'kubedb.com/v1alpha1'
80
-
81
- metadata do
82
- name "#{context.base_name}-postgres"
83
- namespace context.kubernetes.namespace.metadata.name
84
- end
85
-
86
- spec do
87
- database_secret do
88
- secret_name context.secret.metadata.name
89
- end
90
-
91
- version '11.2'
92
- standby_mode 'Hot'
93
- streaming_mode 'asynchronous'
94
- storage_type 'Durable'
95
-
96
- storage do
97
- storage_class_name context.kubernetes.provider.storage_class_name
98
- access_modes ['ReadWriteOnce']
99
-
100
- resources do
101
- requests do
102
- add :storage, '10Gi'
103
- end
104
- end
105
- end
106
-
107
- termination_policy 'DoNotTerminate'
108
- end
109
- end
110
-
111
- @database.instance_eval(&block) if block
112
- @database
113
- end
114
-
115
- def base_name
116
- @base_name ||= "#{kubernetes.selector_app}-#{ROLE}"
117
- end
118
-
119
- def kubernetes
120
- definition.kubernetes
121
- end
122
-
123
- private
124
-
125
- def config
126
- configs[environment]
127
- end
128
- end
129
- end
130
- end
131
- end
132
- end
133
-
134
- Kuby.register_package(:postgres_dev,
135
- debian: 'postgresql-client',
136
- alpine: 'postgresql-dev'
137
- )
138
-
139
- Kuby.register_package(:postgres_client,
140
- debian: 'postgresql-client',
141
- alpine: 'postgresql-client'
142
- )
@@ -1,13 +0,0 @@
1
- module Kuby
2
- module Kubernetes
3
- module Plugins
4
- module RailsApp
5
- class RewriteDbConfig
6
- def apply_to(dockerfile)
7
- dockerfile.run('bundle exec rake kuby:rails_app:db:rewrite_config')
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,30 +0,0 @@
1
- module Kuby
2
- module Kubernetes
3
- module Plugins
4
- module RailsApp
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
16
- end
17
- end
18
- end
19
- end
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
- )
@@ -1,28 +0,0 @@
1
- require 'rake'
2
-
3
- namespace :kuby do
4
- namespace :rails_app do
5
- namespace :db do
6
- task :rewrite_config do
7
- Kuby.load!
8
-
9
- config_file = File.join(Kuby.definition.kubernetes.plugin(:rails_app).root, 'config', 'database.yml')
10
- database = Kuby.definition.kubernetes.plugin(:rails_app).database
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
16
- end
17
-
18
- task :create_unless_exists do
19
- begin
20
- Rake::Task['environment'].invoke
21
- ActiveRecord::Base.connection
22
- rescue ActiveRecord::NoDatabaseError => e
23
- Rake::Task['db:create'].invoke
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,70 +0,0 @@
1
- require 'shellwords'
2
-
3
- namespace :kuby do
4
- def tasks
5
- Kuby.load!
6
- @tasks ||= Kuby::Tasks.new(Kuby.definition)
7
- end
8
-
9
- task :dockerfile do
10
- tasks.print_dockerfile
11
- end
12
-
13
- task :build do
14
- tasks.build
15
- end
16
-
17
- task :run do
18
- tasks.run
19
- end
20
-
21
- task :push do
22
- tasks.push
23
- end
24
-
25
- task :resources do
26
- tasks.print_resources
27
- end
28
-
29
- task :kubectl, [:cmd] do |_, args|
30
- tasks.kubectl(Shellwords.shellsplit(args[:cmd]))
31
- end
32
-
33
- task :deploy do
34
- tasks.deploy
35
- end
36
-
37
- task :rollback do
38
- tasks.rollback
39
- end
40
-
41
- task :kubeconfig do
42
- tasks.print_kubeconfig
43
- end
44
-
45
- task :setup do
46
- tasks.setup
47
- end
48
-
49
- namespace :remote do
50
- task :logs do
51
- tasks.remote_logs
52
- end
53
-
54
- task :status do
55
- tasks.remote_status
56
- end
57
-
58
- task :shell do
59
- tasks.remote_shell
60
- end
61
-
62
- task :console do
63
- tasks.remote_console
64
- end
65
-
66
- task :dbconsole do
67
- tasks.remote_dbconsole
68
- end
69
- end
70
- end