kuby-core 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42f6ba3c11212d10aeb9d878af3f91e4712f88498ddf1f6d94a29d26dfbd27d4
4
- data.tar.gz: 624f45761eed5d05d45e115697a6f43e4fa4516fed17f1158a05af01266ef0e4
3
+ metadata.gz: b8199a0db99884940e43a0711cb6ec706d0828a6e553bb327f04d3370ee4c724
4
+ data.tar.gz: 4a07cf9105716b0d230a3935b33205321818e414d458e99058dcd23b9abbbf99
5
5
  SHA512:
6
- metadata.gz: 46fda51d238e517907361f4da89ef9615383e55d3daad4c58eb8a0d947ccae27398ca340b9d2590274ff02ef312e9f8384fa7965a5470b4b3b0d8b0eb63527bb
7
- data.tar.gz: b7589f6ad84cbd44276893466a15350ba24db01dc5183db3554dc8f5cff77b6834ec964c0591de4c3ad1293713e62f6f28766775b6c88074d3f36d6749afe522
6
+ metadata.gz: 5e4a38749d22b3dc559296aeaa15cff01d4b51a2bcfd754ec1f780a8a62a849dc85723bb8ee7e2a92f24eaa16c19b5e27e2c238682da2805077507441b87bae6
7
+ data.tar.gz: 6070a9a67c1aab75c1e7d1f0b7684bb6fbd899312df57aed642c5c7012d98e886a2880dfca21fec00d38646ba8cbef426fcf56e9a96ba4d4c0dc604b2aa61aa9
@@ -1,3 +1,7 @@
1
+ ## 0.4.0
2
+ * Introduce simple managed package.
3
+ * Refactor deploy task into its own class.
4
+
1
5
  ## 0.3.0
2
6
  * Fix Krane issue causing incorrect constant lookup and therefore deploy failures.
3
7
  - See: https://github.com/Shopify/krane/pull/720
data/README.md CHANGED
@@ -8,170 +8,13 @@ At its core, Kuby is a set of tools and smart defaults that encapsulate and codi
8
8
 
9
9
  Under the hood, Kuby leverages the power of Docker and Kubernetes. It tries to make these technologies accessible to the average Rails dev without requiring a devops black belt.
10
10
 
11
- ## Raison d'etre
12
-
13
- One of Rails' most notorious mantras is "convention over configuration," i.e. sane defaults that limit the cognitive overhead of application development. Rails has survived for as long as it has precisely because it makes so many decisions for you, especially compared to other web application frameworks. It's easy to learn and easy to build with. The development experience is fantastic... right up until the point you want to deploy your app to production. It's at that point that the hand-holding stops. Like the Roadrunner, Rails stops right before the cliff and lets you, Wile E. Coyote, sail over the edge.
14
-
15
- ![Wile E. Coytote](coyote.jpg)
16
-
17
- Perhaps [Stefan Wintermeyer](https://twitter.com/wintermeyer) said it best during his appearance on the Ruby Rogues podcast, [episode 403](https://devchat.tv/ruby-rogues/rr-403-rails-needs-active-deployment-with-stefan-wintermeyer/):
18
-
19
- > "In my experience, deployment is one of the major problems of normal Rails users. It is a big pain to set up a deployment system for a Rails application, and I don't see anything out there that makes it easier. [...] I believe that we lose quite a lot of companies and new developers on this step. Because everything else [is] so much easier with Rails. But that last step - and it's a super important step - is still super complicated."
20
-
21
- ## Docker and Kubernetes
22
-
23
- Why bet the farm on Docker and Kubernetes?
24
-
25
- ### Docker
26
-
27
- When Docker came on the scene in 2013 it was seen as a game-changer. Applications that used to be deployed onto hand-provisioned servers can now be bundled up into neat little packages and transferred between computers in their entirety. Since the whole application - dependencies, operating system components, assets, code, etc - can be passed around as a single artifact, Docker images curtail the need for manually provisioned servers and eliminate a whole class of "works on my machine" problems.
28
-
29
- ### Kubernetes
30
-
31
- Kubernetes has taken the ops world by storm. It's resilient to failure, portable across a variety of cloud providers, and backed by industry-leading organizations like the CNCF. Kubernetes configuration is portable enough to be used, without modification, on just about any Kubernetes cluster, making migrations not only feasible, but easy. Many cloud providers like Google GCP, Amazon AWS, Microsoft Azure, DigitalOcean, and Linode support Kubernetes. Most of these providers will manage the Kubernetes cluster for you, and in some cases will even provide it free of charge (you pay only for the compute resources).
32
-
33
11
  ## Getting Started
34
12
 
35
- NOTE: Kuby is designed to work with Rails 5.1 and up.
36
-
37
- ### Choosing a Provider
38
-
39
- The first step in deploying your app is to choose a hosting provider. At the time of this writing, Kuby supports DigitalOcean and Linode, but support for more providers is coming soon. Use your provider's dashboard to spin up a Kubernetes cluster. In most cases, this shouldn't involve more than a few button clicks.
40
-
41
- ### The Container Registry
42
-
43
- Kuby uses Docker to package up your application into a Docker _image_. Images are then pushed (i.e. uploaded) to something called a "container registry." Container registries host Docker images so they can be pulled (i.e. downloaded) later.
44
-
45
- Although there are a number of container registries available (some free and some paid), consider using the Gitlab registry. Gitlab's registry is free and unlimited. You don't have to host your code on Gitlab to take advantage of the registry, but they're great for that too.
46
-
47
- ### Integrating Kuby
48
-
49
- Kuby configuration is done via a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language). There are two main sections, one for Docker and one for Kubernetes. Put the config into a Rails initializer, eg. config/initializers/kuby.rb.
50
-
51
- Here's what a complete config looks like:
52
-
53
- ```ruby
54
- Kuby.define(:production) do
55
- docker do
56
- credentials do
57
- username ENV['DOCKER_USERNAME']
58
- password ENV['DOCKER_PASSWORD']
59
- email ENV['DOCKER_EMAIL']
60
- end
61
-
62
- image_url 'registry.gitlab.com/username/repo'
63
- end
64
-
65
- kubernetes do
66
- provider :digitalocean do
67
- access_token ENV['DIGITALOCEAN_ACCESS_TOKEN']
68
- cluster_id 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
69
- end
70
-
71
- add_plugin :rails_app do
72
- hostname 'mywebsite.com'
73
- end
74
- end
75
- end
76
- ```
77
-
78
- Let's go over this config in detail.
79
-
80
- ### Deploy Environments
81
-
82
- The first line defines the _deploy environment_:
83
-
84
- ```ruby
85
- Kuby.define(:production)
86
- ```
87
-
88
- Deploy environments usually closely mirror your Rails environments. For example, you might create a new Rails environment called "staging" or "preprod" that's used to test production changes before they go live. You'll want to create a "staging" Kuby deploy environment as well.
89
-
90
- If you're a small shop or hobbyist though, chances are the "production" deploy environment is all you need.
91
-
92
- ### Configuring Docker
93
-
94
- Kuby can automatically "dockerize" your application. You just need to tell it where to push images and provide some credentials:
95
-
96
- ```ruby
97
- docker do
98
- credentials do
99
- username ENV['DOCKER_USERNAME']
100
- password ENV['DOCKER_PASSWORD']
101
- email ENV['DOCKER_EMAIL']
102
- end
103
-
104
- image_url 'registry.gitlab.com/username/repo'
105
- end
106
- ```
107
-
108
- The username, password, and email fields are used to authenticate with the Docker registry that hosts your images. For Gitlab, you'll need to create a [personal access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) instead of your password. The `image_url` field is the full URL to your image, including the registry's domain.
109
-
110
- In the example above, the username, password, and email are all provided as environment variables. **NEVER** hard-code sensitive information like this in your Kuby config or check it into source control (i.e. git). Consider using a tool like [dotenv](https://github.com/bkeepers/dotenv) to automatically load the variables from a file when your app starts (NOTE: don't check the .env file into git either!)
111
-
112
- ### Configuring Kubernetes
113
-
114
- Now that your app can be packaged up into a Docker image, it's time to use Kubernetes to run it. There are two top-level concerns in the Kubernetes section of your Kuby config: providers and plugins.
115
-
116
- #### Providers
117
-
118
- Each Kubernetes definition must have a provider configured. Providers correspond to the hosting provider you chose earlier. For example, you'll need to add the `:digitalocean` provider to deploy to a managed DigitalOcean Kubernetes cluster.
119
-
120
- ```ruby
121
- kubernetes do
122
- provider :digitalocean do
123
- access_token ENV['DIGITALOCEAN_ACCESS_TOKEN']
124
- cluster_id 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
125
- end
126
- end
127
- ```
128
-
129
- Kuby providers are distributed as individual rubygems. Add the one you need to your Gemfile, for example:
130
-
131
- ```ruby
132
- gem 'kuby-digitalocean', '~> 0.1'
133
- ```
134
-
135
- Providers can have different config options, so make sure you consult the gem's README for the provider you've chosen.
136
-
137
- #### Plugins
138
-
139
- Nearly all Kuby's functionality is provided via plugins. For example, simply add the `:rails_app` plugin to get your Rails app ready to deploy:
140
-
141
- ```ruby
142
- add_plugin :rails_app
143
- ```
144
-
145
- To indicate your app exists behind a particular domain name, specify the `hostname` option:
146
-
147
- ```ruby
148
- add_plugin :rails_app do
149
- hostname 'mywebsite.com'
150
- end
151
- ```
152
-
153
- Configuring DNS to point to your Kubernetes cluster is outside the scope of this README, but all the hosting providers should have tutorials. For example, [here's the one](https://www.digitalocean.com/community/tutorials/how-to-point-to-digitalocean-nameservers-from-common-domain-registrars) from DigitalOcean.
154
-
155
- ## Deploying
156
-
157
- Now that Kuby is configured and your Kubernetes cluster is ready, it's time to deploy!
158
-
159
- 1. Build the Docker image
160
-
161
- ```sh
162
- bundle exec rake kuby:build
163
- ```
164
- 1. Push the Docker image to the container registry
13
+ See the [Quick Start Guide](https://github.com/getkuby/kuby-core/wiki/Quick-Start-Guide)
165
14
 
166
- ```sh
167
- bundle exec rake kuby:push
168
- ```
169
- 1. Deploy!
15
+ ## More Info
170
16
 
171
- ```sh
172
- bundle exec rake kuby:deploy
173
- ```
174
- 1. Rejoice
17
+ See the [wiki](https://github.com/getkuby/kuby-core/wiki).
175
18
 
176
19
  ## Running Tests
177
20
 
@@ -1,5 +1,10 @@
1
1
  require 'kuby/railtie'
2
2
 
3
+ begin
4
+ require 'kuby/kubernetes/plugins/rails_app/generators/kuby'
5
+ rescue NameError
6
+ end
7
+
3
8
  module Kuby
4
9
  autoload :BasicLogger, 'kuby/basic_logger'
5
10
  autoload :CLIBase, 'kuby/cli_base'
@@ -56,11 +61,15 @@ module Kuby
56
61
  @plugins ||= {}
57
62
  end
58
63
 
59
- def register_package(package_name, package_def)
64
+ def register_package(package_name, package_def = nil)
60
65
  packages[package_name] = case package_def
66
+ when NilClass
67
+ Kuby::Docker::Packages::SimpleManagedPackage.new(
68
+ package_name
69
+ )
61
70
  when String
62
- Kuby::Docker::Packages::ManagedPackage.new(
63
- package_name, debian: package_def, alpine: package_def
71
+ Kuby::Docker::Packages::SimpleManagedPackage.new(
72
+ package_def
64
73
  )
65
74
  when Hash
66
75
  Kuby::Docker::Packages::ManagedPackage.new(
@@ -1,10 +1,11 @@
1
1
  module Kuby
2
2
  module Docker
3
3
  module Packages
4
- autoload :ManagedPackage, 'kuby/docker/packages/managed_package'
5
- autoload :Nodejs, 'kuby/docker/packages/nodejs'
6
- autoload :Package, 'kuby/docker/packages/package'
7
- autoload :Yarn, 'kuby/docker/packages/yarn'
4
+ autoload :ManagedPackage, 'kuby/docker/packages/managed_package'
5
+ autoload :Nodejs, 'kuby/docker/packages/nodejs'
6
+ autoload :Package, 'kuby/docker/packages/package'
7
+ autoload :SimpleManagedPackage, 'kuby/docker/packages/simple_managed_package'
8
+ autoload :Yarn, 'kuby/docker/packages/yarn'
8
9
  end
9
10
  end
10
11
  end
@@ -0,0 +1,25 @@
1
+ module Kuby
2
+ module Docker
3
+ module Packages
4
+ class SimpleManagedPackage
5
+ attr_reader :name
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ end
10
+
11
+ def package_name_for(distro)
12
+ name
13
+ end
14
+
15
+ def with_version(*)
16
+ self
17
+ end
18
+
19
+ def managed?
20
+ true
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -4,6 +4,7 @@ module Kuby
4
4
  module Kubernetes
5
5
  autoload :MinikubeProvider, 'kuby/kubernetes/minikube_provider'
6
6
  autoload :Deployer, 'kuby/kubernetes/deployer'
7
+ autoload :DeployTask, 'kuby/kubernetes/deploy_task'
7
8
  autoload :DockerConfig, 'kuby/kubernetes/docker_config'
8
9
  autoload :Manifest, 'kuby/kubernetes/manifest'
9
10
  autoload :Monitors, 'kuby/kubernetes/monitors'
@@ -0,0 +1,33 @@
1
+ require 'krane'
2
+ require 'ext/krane/kubernetes_resource'
3
+ require 'kubectl-rb'
4
+
5
+ module Kuby
6
+ module Kubernetes
7
+ class DeployTask
8
+ attr_reader :deploy_task
9
+
10
+ def initialize(**kwargs)
11
+ @deploy_task ||= ::Krane::DeployTask.new(**kwargs)
12
+ end
13
+
14
+ def run!(**kwargs)
15
+ new_path = "#{File.dirname(KubectlRb.executable)}:#{ENV['PATH']}"
16
+
17
+ with_env('PATH' => new_path) do
18
+ deploy_task.run!(**kwargs)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def with_env(new_env)
25
+ old_env = ENV.to_h
26
+ ENV.replace(old_env.merge(new_env))
27
+ yield
28
+ ensure
29
+ ENV.replace(old_env)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,4 @@
1
1
  require 'fileutils'
2
- require 'krane'
3
- require 'ext/krane/kubernetes_resource'
4
2
  require 'securerandom'
5
3
  require 'yaml'
6
4
 
@@ -63,7 +61,7 @@ module Kuby
63
61
  File.write(resource_path, resource.to_resource.to_yaml)
64
62
  end
65
63
 
66
- task = ::Krane::DeployTask.new(
64
+ task = ::Kuby::Kubernetes::DeployTask.new(
67
65
  namespace: namespace.metadata.name,
68
66
  context: cli.current_context,
69
67
  filenames: [tmpdir]
@@ -0,0 +1,43 @@
1
+ require 'rails/generators/base'
2
+
3
+ class KubyGenerator < Rails::Generators::Base
4
+ def create_initializer_file
5
+ initializer(
6
+ 'kuby.rb',
7
+ <<~END
8
+ # Define a production Kuby deploy environment
9
+ Kuby.define(:production) do
10
+ docker do
11
+ # Configure your Docker registry credentials here. Add them to your
12
+ # Rails credentials file by running `bundle exec rake credentials:edit`.
13
+ credentials do
14
+ username Rails.application.credentials[:KUBY_DOCKER_USERNAME]
15
+ password Rails.application.credentials[:KUBY_DOCKER_PASSWORD]
16
+ email Rails.application.credentials[:KUBY_DOCKER_EMAIL]
17
+ end
18
+
19
+ # Configure the URL to your Docker image here, eg:
20
+ # image_url 'foo.bar.com/me/myproject'
21
+ #
22
+ # If you're using Gitlab's Docker registry, try something like this:
23
+ # image_url 'registry.gitlab.com/<username>/<repo>'
24
+ end
25
+
26
+ kubernetes do
27
+ # Add a plugin that facilitates deploying a Rails app.
28
+ add_plugin :rails_app
29
+
30
+ # Use minikube as the default provider.
31
+ # See: https://github.com/kubernetes/minikube
32
+ #
33
+ # Note: you will likely want to use a different provider when deploying
34
+ # your application into a production environment. To configure a different
35
+ # provider, add the corresponding gem to your gemfile and update the
36
+ # following line according to the provider gem's README.
37
+ provider :minikube
38
+ end
39
+ end
40
+ END
41
+ )
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Kuby
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.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.3.0
4
+ version: 0.4.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-06-18 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -173,6 +173,7 @@ files:
173
173
  - lib/kuby/docker/packages/managed_package.rb
174
174
  - lib/kuby/docker/packages/nodejs.rb
175
175
  - lib/kuby/docker/packages/package.rb
176
+ - lib/kuby/docker/packages/simple_managed_package.rb
176
177
  - lib/kuby/docker/packages/yarn.rb
177
178
  - lib/kuby/docker/phase.rb
178
179
  - lib/kuby/docker/remote_tags.rb
@@ -183,6 +184,7 @@ files:
183
184
  - lib/kuby/docker/webserver_phase.rb
184
185
  - lib/kuby/docker/yarn_phase.rb
185
186
  - lib/kuby/kubernetes.rb
187
+ - lib/kuby/kubernetes/deploy_task.rb
186
188
  - lib/kuby/kubernetes/deployer.rb
187
189
  - lib/kuby/kubernetes/docker_config.rb
188
190
  - lib/kuby/kubernetes/errors.rb
@@ -193,6 +195,7 @@ files:
193
195
  - lib/kuby/kubernetes/plugins/nginx_ingress.rb
194
196
  - lib/kuby/kubernetes/plugins/rails_app.rb
195
197
  - lib/kuby/kubernetes/plugins/rails_app/database.rb
198
+ - lib/kuby/kubernetes/plugins/rails_app/generators/kuby.rb
196
199
  - lib/kuby/kubernetes/plugins/rails_app/mysql.rb
197
200
  - lib/kuby/kubernetes/plugins/rails_app/plugin.rb
198
201
  - lib/kuby/kubernetes/plugins/rails_app/postgres.rb