dctl_rb 0.10.5 → 0.11.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 +4 -4
- data/Gemfile.lock +1 -1
- data/exe/dctl +4 -0
- data/lib/dctl/cli/kubernetes.rb +60 -0
- data/lib/dctl/kubernetes.rb +27 -0
- data/lib/dctl/version.rb +1 -1
- data/lib/dctl.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb2a3ff3297ec27acacc32e5bfc12698e8d9c8d55f76c394ae4640e36d63aa2a
|
4
|
+
data.tar.gz: df5ef66c7a27870689c7e98337d7d983252beab2d4bad49ddc1fbb69cb036766
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 441b6e8f2d1e8507f2bd15a47de9780c5d97e1ed939832609da888b7cb8eb4da1f4d4f665ce000f3f2c615a44a3ca327c7cd9dcca98f33890f016123b9af893c
|
7
|
+
data.tar.gz: 494d65de08a6b505c3fab9f1665e5e01a2ffdf8bcef8c52602fbe596d3a5b892059d7ce6fc351273902ab3c9fe508a9ea1058a136849c83228857738140bb579
|
data/Gemfile.lock
CHANGED
data/exe/dctl
CHANGED
@@ -6,6 +6,7 @@ require "pty"
|
|
6
6
|
require "rainbow"
|
7
7
|
require "config"
|
8
8
|
require "open3"
|
9
|
+
require "dctl/cli/kubernetes"
|
9
10
|
|
10
11
|
module Dctl
|
11
12
|
class Cli < Thor
|
@@ -13,6 +14,9 @@ module Dctl
|
|
13
14
|
SUCCESS_COLOR = :green
|
14
15
|
CMD_COLOR = :dimgray
|
15
16
|
|
17
|
+
desc "k8s", "Manage a kubernetes cluster"
|
18
|
+
subcommand "k8s", Dctl::Kubernetes::Cli
|
19
|
+
|
16
20
|
class_option :env, type: :string
|
17
21
|
class_option :host, type: :string
|
18
22
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "dctl/kubernetes"
|
3
|
+
|
4
|
+
module Dctl::Kubernetes
|
5
|
+
class Cli < Thor
|
6
|
+
|
7
|
+
class_option :namespace, type: :string, aliases: :n
|
8
|
+
class_option :env, type: :string
|
9
|
+
|
10
|
+
desc "live-image", "Returns the active image for the given deployment"
|
11
|
+
def live_image(service)
|
12
|
+
puts Dctl::Kubernetes.live_image(service, k8s_opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "is-outdated", "Exit 1 if deployed image would be updated by a deploy, or 0 otherwise."
|
16
|
+
long_desc <<~LONGDESC
|
17
|
+
Check whether the currently deployed image is outdated and would be
|
18
|
+
updated by a new deployment.
|
19
|
+
|
20
|
+
This is determined by checking the tag specified in the compose file for
|
21
|
+
this environment against a random pod in the corresponding k8s deployment.
|
22
|
+
|
23
|
+
For example, if the tag in the compose file is `jutonz/app:4` and the live
|
24
|
+
image is `jutonz/app:3`, this would exit with 0. If the tags matched this
|
25
|
+
would exit with 1.
|
26
|
+
|
27
|
+
This is useful for determining when it is possible to skip building new
|
28
|
+
images, e.g with a CI/CD setup.
|
29
|
+
|
30
|
+
Example:\x5
|
31
|
+
export DCTL_ENV=prod\x5
|
32
|
+
if dctl is-outdated app; then\x5
|
33
|
+
\tdctl build app\x5
|
34
|
+
\tdctl push app\x5
|
35
|
+
else\x5
|
36
|
+
\techo "app is up to date"\x5
|
37
|
+
fi\x5
|
38
|
+
LONGDESC
|
39
|
+
def is_outdated(service)
|
40
|
+
dctl = Dctl::Main.new dctl_opts
|
41
|
+
compose_tag = dctl.image_tag service
|
42
|
+
live_tag = Dctl::Kubernetes.live_image(service, k8s_opts)
|
43
|
+
exit compose_tag == live_tag ? 1 : 0
|
44
|
+
end
|
45
|
+
|
46
|
+
no_commands do
|
47
|
+
# Transform Thor's HashWithIndifferentAccess to a regular hash so it can
|
48
|
+
# be passed to methods and treated as named arguments.
|
49
|
+
def k8s_opts
|
50
|
+
{ namespace: options["namespace"] }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Transform Thor's HashWithIndifferentAccess to a regular hash so it can
|
54
|
+
# be passed to methods and treated as named arguments.
|
55
|
+
def dctl_opts
|
56
|
+
{ env: options.fetch("env", "dev") }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Dctl::Kubernetes
|
2
|
+
def self.live_image(service, namespace: nil)
|
3
|
+
# Check if namespace exists
|
4
|
+
if namespace && `kubectl get ns #{namespace}`.empty?
|
5
|
+
error = "Could not find namespace #{namespace}"
|
6
|
+
puts Rainbow(error).fg ERROR_COLOR
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
|
10
|
+
# Check if deployment exists
|
11
|
+
deploy_check_command = "kubectl get deploy #{service}"
|
12
|
+
deploy_check_command += " -n #{namespace}" if namespace
|
13
|
+
if `#{deploy_check_command}`.empty?
|
14
|
+
error = "Could not find deployment for #{service}"
|
15
|
+
error += " in namespace #{namespace}" if namespace
|
16
|
+
puts Rainbow(error).fg ERROR_COLOR
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
jsonpath = "{$.spec.template.spec.containers[:1].image}"
|
21
|
+
live_image_command = "kubectl get deploy #{service}"
|
22
|
+
live_image_command += " -ojsonpath='#{jsonpath}'"
|
23
|
+
live_image_command += " -n #{namespace}" if namespace
|
24
|
+
|
25
|
+
`#{live_image_command}`
|
26
|
+
end
|
27
|
+
end
|
data/lib/dctl/version.rb
CHANGED
data/lib/dctl.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dctl_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Toniazzo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -151,6 +151,8 @@ files:
|
|
151
151
|
- hi.txt
|
152
152
|
- lib/dctl.rb
|
153
153
|
- lib/dctl/.version.rb.swp
|
154
|
+
- lib/dctl/cli/kubernetes.rb
|
155
|
+
- lib/dctl/kubernetes.rb
|
154
156
|
- lib/dctl/main.rb
|
155
157
|
- lib/dctl/version.rb
|
156
158
|
homepage: https://github.com/jutonz/dctl_rb
|