kubes 0.2.4 → 0.2.5

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: 8d2e75bd0d156b889fcbd5a55389d335e4509e2c27bc667940bfd87155b3d9a0
4
- data.tar.gz: f13237e1d8fa442d2b1a1ed07d7e209b3054cf3cdfee8f68dab20e3358352add
3
+ metadata.gz: 658324c3828bd9f6ee60ad1fd925eb47ff9706fe08256b791e180b0daf3cfba0
4
+ data.tar.gz: 5a2cc328105e6ac7dd7847f4d92697db98827e81b214b7dc3f6b353bf78e224f
5
5
  SHA512:
6
- metadata.gz: '09576784450fc73c4846f7803c375542de5ed1f37bda86cd8cd8e61cf53dfa774192b8648d9b207180b9681a4e787ea0ade6211d02eedcd63a11051c694bb0a1'
7
- data.tar.gz: 13219946a970eb6e476902b09971ae832b47a8cddf0ebc73ab68a079de2d7a67e50a539b8784731d67cf5037c677c811408db6e3cbb8b7eea528bec5588784a4
6
+ metadata.gz: 307badb633d97365c4072a7e089c5a36b2abb81e761aa3a5abb46e4aaa4e3da2878023edb12cf203b817ee6aa4484b4d2d758e6f4a20b1e571fdaec75bf61ddc
7
+ data.tar.gz: e5d6f7434c93a73bc996fc661d026f5c601a4bd7c6680c14f0219af4561f1f7ac362370123efe381fac0538021ccb151adc308658b1f3f70c0dbff58334fed9d
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.2.5]
7
+ - #17 cloudbuild build strategy
8
+
6
9
  ## [0.2.4]
7
10
  - #16 google cloudbuild support & docs: add Dockerfile for kubes as a docker entrypoint
8
11
 
@@ -0,0 +1,46 @@
1
+ ---
2
+ title: Build Strategy
3
+ ---
4
+
5
+ Kubes uses the `docker` to build the docker image by default. Kubes can also support an additional build strategy: gcloud.
6
+
7
+ ## Gcloud Build Strategy
8
+
9
+ With the gcloud build strategy, you do not need docker installed locally. Google CloudBuild is used to build and push the image to a GCR registry.
10
+
11
+ You must set up the [gcloud cli](https://cloud.google.com/sdk/gcloud/reference/builds/submit). Please refer to the [gcloud sdk install docs](https://cloud.google.com/sdk/install). Kubes will call out to `gcloud builds submit` to create the Docker image.
12
+
13
+ ## Configure
14
+
15
+ You configure gcloud as the build strategy like so:
16
+
17
+ ```ruby
18
+ Kubes.configure do |config|
19
+ config.repo = "gcr.io/#{ENV['GOOGLE_PROJECT']}/demo"
20
+ config.logger.level = "info"
21
+ config.build_strategy = "gcloud" # <= changed to gcloud
22
+ end
23
+ ```
24
+
25
+ ## Commands
26
+
27
+ The kubes builds command will remain the same.
28
+
29
+ kubes docker build
30
+
31
+ There is no need to run the push command, as the build command with the gcloud strategy will always push.
32
+
33
+ ## Deploy
34
+
35
+ The deploy commands remain the same. Example:
36
+
37
+ kubes deploy web
38
+
39
+ If you want to skip the `docker build` phase of the deploy, you can run:
40
+
41
+ kubes deploy web --no-build
42
+
43
+ Also, kubes apply another way to skip the docker build:
44
+
45
+ kubes apply web
46
+
@@ -56,6 +56,7 @@
56
56
  <li><a href="{% link _docs/config/docker.md %}">Docker</a></li>
57
57
  <li><a href="{% link _docs/config/env.md %}">Env</a></li>
58
58
  <li><a href="{% link _docs/config/kubectl.md %}">Kubectl</a></li>
59
+ <li><a href="{% link _docs/config/build-strategy.md %}">Build Strategy</a></li>
59
60
  </ul>
60
61
  </li>
61
62
  <li><a href="{% link _docs/yaml.md %}">YAML</a></li>
@@ -1,8 +1,8 @@
1
1
  class Kubes::CLI
2
2
  class Build < Base
3
3
  def run
4
- Kubes::Docker::Build.new(@options).run
5
- Kubes::Docker::Push.new(@options).run
4
+ Kubes::Docker.new(@options, "build").run
5
+ Kubes::Docker.new(@options, "push").run
6
6
  end
7
7
  end
8
8
  end
@@ -4,7 +4,7 @@ class Kubes::CLI
4
4
  long_desc Help.text("docker:build")
5
5
  option :push, type: :boolean, default: false
6
6
  def build
7
- builder = Kubes::Docker::Build.new(options)
7
+ builder = Kubes::Docker.new(options, "build")
8
8
  builder.run
9
9
  push if options[:push]
10
10
  end
@@ -13,7 +13,7 @@ class Kubes::CLI
13
13
  long_desc Help.text("docker:push")
14
14
  option :push, type: :boolean, default: false
15
15
  def push
16
- pusher = Kubes::Docker::Push.new(options)
16
+ pusher = Kubes::Docker.new(options, "push")
17
17
  pusher.run
18
18
  end
19
19
  end
@@ -35,6 +35,8 @@ module Kubes
35
35
 
36
36
  config.repo = nil # expected to be set by .kubes/config.rb
37
37
 
38
+ config.build_strategy = "docker" # IE: docker or gcloud
39
+
38
40
  config
39
41
  end
40
42
 
@@ -0,0 +1,19 @@
1
+ module Kubes
2
+ class Docker
3
+ def initialize(options, name)
4
+ @options = options
5
+ @name = name
6
+ end
7
+
8
+ def run
9
+ strategy = strategy_class.new(@options, @name) # @name: docker or push
10
+ strategy.run
11
+ end
12
+
13
+ def strategy_class
14
+ strategy = Kubes.config.build_strategy.to_s.camelize # IE: Docker or Gcloud
15
+ klass_name = "Kubes::Docker::Strategy::#{@name.camelize}::#{strategy}"
16
+ klass_name.constantize
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Kubes::Docker::Strategy::Build
2
+ class Base
3
+ extend Memoist
4
+ include Kubes::Docker::Strategy::Utils
5
+
6
+ def initialize(options, name)
7
+ @options, @name = options, name
8
+ end
9
+
10
+ def run
11
+ reserve_image_name
12
+ check_dockerfile!
13
+ perform
14
+ store_image_name
15
+ end
16
+
17
+ def check_dockerfile!
18
+ # Dockerfile is also used in args/default.rb, will have to combine if Dockerfile is made configurable
19
+ return if File.exist?("Dockerfile")
20
+ logger.error "ERROR: The Dockerfile does not exist. Cannot build the docker image without a Dockerfile".color(:red)
21
+ exit 1
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Kubes::Docker::Strategy::Build
2
+ class Docker < Base
3
+ def perform
4
+ params = args.flatten.join(' ')
5
+ command = "docker build #{params}"
6
+ run_hooks "build" do
7
+ sh(command)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Kubes::Docker::Strategy::Build
2
+ class Gcloud < Base
3
+ def perform
4
+ command = "gcloud builds submit --tag #{@@image_name}"
5
+ run_hooks "build" do
6
+ sh(command)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Kubes::Docker::Strategy
2
+ module Hooks
3
+ def run_hooks(name, &block)
4
+ hooks = Kubes::Hooks::Builder.new(name, "#{Kubes.root}/.kubes/config/docker/hooks.rb")
5
+ hooks.build # build hooks
6
+ hooks.run_hooks(&block)
7
+ end
8
+ end
9
+ end
@@ -1,36 +1,6 @@
1
- module Kubes::Docker
2
- class Base
1
+ module Kubes::Docker::Strategy
2
+ module ImageName
3
3
  extend Memoist
4
- include Kubes::Logging
5
- include Kubes::Util::Sh
6
-
7
- def initialize(options={})
8
- @options = options
9
- @name = self.class.name.split('::').last.underscore
10
- end
11
-
12
- def run_hooks(name, &block)
13
- hooks = Kubes::Hooks::Builder.new(name, "#{Kubes.root}/.kubes/config/docker/hooks.rb")
14
- hooks.build # build hooks
15
- hooks.run_hooks(&block)
16
- end
17
-
18
- def args
19
- # base at end in case of redirection. IE: command > /path
20
- custom.args + default.args
21
- end
22
-
23
- def custom
24
- custom = Kubes::Args::Custom.new(@name, "#{Kubes.root}/.kubes/config/docker/args.rb")
25
- custom.build
26
- custom
27
- end
28
- memoize :custom
29
-
30
- def default
31
- Args::Default.new(@name, image_name, @options)
32
- end
33
- memoize :default
34
4
 
35
5
  @@image_name = nil
36
6
  def reserve_image_name
@@ -84,5 +54,22 @@ module Kubes::Docker
84
54
  @git_sha = `cd #{Kubes.root} && git rev-parse --short HEAD`
85
55
  @git_sha.strip!
86
56
  end
57
+
58
+ def args
59
+ # base at end in case of redirection. IE: command > /path
60
+ custom.args + default.args
61
+ end
62
+
63
+ def custom
64
+ custom = Kubes::Args::Custom.new(@name, "#{Kubes.root}/.kubes/config/docker/args.rb")
65
+ custom.build
66
+ custom
67
+ end
68
+ memoize :custom
69
+
70
+ def default
71
+ Kubes::Docker::Args::Default.new(@name, image_name, @options)
72
+ end
73
+ memoize :default
87
74
  end
88
75
  end
@@ -0,0 +1,9 @@
1
+ module Kubes::Docker::Strategy::Push
2
+ class Base
3
+ include Kubes::Docker::Strategy::Utils
4
+
5
+ def initialize(options, name)
6
+ @options, @name = options, name
7
+ end
8
+ end
9
+ end
@@ -1,8 +1,5 @@
1
- module Kubes::Docker
2
- class Push < Base
3
- include Kubes::Logging
4
- include Kubes::Util::Time
5
-
1
+ module Kubes::Docker::Strategy::Push
2
+ class Docker < Base
6
3
  def run
7
4
  update_auth_token
8
5
  start_time = Time.now
@@ -0,0 +1,9 @@
1
+ module Kubes::Docker::Strategy::Push
2
+ class Gcloud < Base
3
+ def run
4
+ run_hooks "push" do
5
+ # noop, gcloud builds submit already pushes the image
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Kubes::Docker::Strategy
2
+ module Utils
3
+ include Kubes::Logging
4
+ include Kubes::Util::Sh
5
+ include Kubes::Util::Time
6
+ include Kubes::Docker::Strategy::ImageName
7
+ include Kubes::Docker::Strategy::Hooks
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-26 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -235,6 +235,7 @@ files:
235
235
  - docs/_docs/auto-context.md
236
236
  - docs/_docs/ci/cloudbuild.md
237
237
  - docs/_docs/config.md
238
+ - docs/_docs/config/build-strategy.md
238
239
  - docs/_docs/config/docker.md
239
240
  - docs/_docs/config/env.md
240
241
  - docs/_docs/config/kubectl.md
@@ -513,10 +514,17 @@ files:
513
514
  - lib/kubes/completer/script.sh
514
515
  - lib/kubes/config.rb
515
516
  - lib/kubes/core.rb
517
+ - lib/kubes/docker.rb
516
518
  - lib/kubes/docker/args/default.rb
517
- - lib/kubes/docker/base.rb
518
- - lib/kubes/docker/build.rb
519
- - lib/kubes/docker/push.rb
519
+ - lib/kubes/docker/strategy/build/base.rb
520
+ - lib/kubes/docker/strategy/build/docker.rb
521
+ - lib/kubes/docker/strategy/build/gcloud.rb
522
+ - lib/kubes/docker/strategy/hooks.rb
523
+ - lib/kubes/docker/strategy/image_name.rb
524
+ - lib/kubes/docker/strategy/push/base.rb
525
+ - lib/kubes/docker/strategy/push/docker.rb
526
+ - lib/kubes/docker/strategy/push/gcloud.rb
527
+ - lib/kubes/docker/strategy/utils.rb
520
528
  - lib/kubes/hooks/builder.rb
521
529
  - lib/kubes/hooks/dsl.rb
522
530
  - lib/kubes/kubectl.rb
@@ -1,22 +0,0 @@
1
- module Kubes::Docker
2
- class Build < Base
3
- def run
4
- reserve_image_name
5
- build
6
- store_image_name
7
- end
8
-
9
- def build
10
- # Dockerfile is also used in args/default.rb, will have to combine if Dockerfile is made configurable
11
- unless File.exist?("Dockerfile")
12
- logger.error "ERROR: The Dockerfile does not exist. Cannot build the docker image without a Dockerfile".color(:red)
13
- exit 1
14
- end
15
- params = args.flatten.join(' ')
16
- command = "docker build #{params}"
17
- run_hooks "build" do
18
- sh(command)
19
- end
20
- end
21
- end
22
- end