mina-kubernetes 1.0.1 → 2.0.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/CHANGELOG.md +10 -0
- data/README.md +9 -11
- data/lib/mina/kubernetes.rb +10 -22
- data/lib/mina/kubernetes/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f69cc691a91d27b5cefa7d4a79056184cfad126ffd833ce2c11c8c85438516ef
|
4
|
+
data.tar.gz: 15e3ee21f521d47f1cc4d22ab70edeb7ace125244b301a571fcb88a3ea01537d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e3d514d8ee7e171f28d646f2142dc1fad2acca1416ecb30baa77742c1f046e19cd92990d88e34016d196f62fbaf7492f99778158a69504365af7c3844096a70
|
7
|
+
data.tar.gz: '01066097331bdac2aeba3b2228fc4d78f68511accef2ea59d111478d379bf37551b55673842dbf77b9cc1d0012222d6378328bb7538dde1c9ea46335c3121be9'
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## 2.0.0
|
2
|
+
|
3
|
+
*Breaking*
|
4
|
+
|
5
|
+
- Using `namespace` config variable instead of `app_name`
|
6
|
+
- Using `kubernetes_context` config variable linking directly to a context set in $KUBE_CONFIG instead of creating a new context from separate `kubernetes_cluster` and `kubernetes_user` config variables
|
7
|
+
|
8
|
+
*Fixes*
|
9
|
+
|
10
|
+
- Not overriding $KUBE_CONFIG environment variable anymore
|
data/README.md
CHANGED
@@ -3,6 +3,9 @@ Plugin for the [mina](https://github.com/mina-deploy/mina) deployment tool to st
|
|
3
3
|
|
4
4
|
Requires local Docker and [kubectl](https://cloud.google.com/kubernetes-engine/docs/quickstart) with authentication set up to connect to the destination Kubernetes cluster.
|
5
5
|
|
6
|
+
NB: `docker manifest inspect` is used to check the image is available. This requires experimental features to be enabled in your local Docker config by adding `"experimental": "enabled"` to `~/.docker/config.json`.
|
7
|
+
If the image repository is not public authentication will need to be set up for your local Docker, for instance see https://cloud.google.com/container-registry/docs/advanced-authentication#gcloud_as_a_docker_credential_helper for images hosted on the Google Cloud Registry
|
8
|
+
|
6
9
|
## Usage
|
7
10
|
|
8
11
|
Add `mina-kubernetes` to your local Gemfile.
|
@@ -10,6 +13,7 @@ Add `mina-kubernetes` to your local Gemfile.
|
|
10
13
|
Create a configuration file for mina in `config/deploy.rb` like the one below:
|
11
14
|
```ruby
|
12
15
|
require "mina/default"
|
16
|
+
require "mina/multistage"
|
13
17
|
require "mina/kubernetes"
|
14
18
|
|
15
19
|
task :deploy do
|
@@ -19,20 +23,14 @@ end
|
|
19
23
|
|
20
24
|
Add the following variables to your stage configuration i.e. `config/deploy/production.rb`:
|
21
25
|
```ruby
|
22
|
-
set :
|
23
|
-
set :
|
24
|
-
set :
|
25
|
-
set :kubernetes_user, "kubernetes_user_name"
|
26
|
+
set :namespace, "my_app"
|
27
|
+
set :image_repo, "gcr.io/project-id/myapp"
|
28
|
+
set :kubernetes_context, "kubernetes_context_name"
|
26
29
|
```
|
27
30
|
|
28
31
|
If `set :image_tag, "my_image_tag"` is also defined, it'll be used to deploy the image tagged with this tag on the repository. Otherwise you'll be prompted to pick a branch from current working Git repository and the image to deploy will be assumed to be tagged with the Git commit hash, i.e. `gcr.io/project-123456/my_app:abcd1234`.
|
29
32
|
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
set :kube_config, "~/.kube/config"
|
33
|
-
```
|
34
|
-
|
35
|
-
Then create `*.yml.erb` Kubernetes resource definition files in the stage folder, i.e. `config/deploy/production/app.yml.erb`. Occurences of `<%= image_repo %>` and `<%= current_sha %>` in these files will be dynamically replaced on deploy by the image repository URL and the latest commit hash of the selected branch on its git origin.
|
33
|
+
Then add `*.yml.erb` Kubernetes resource definition files in the stage folder, i.e. `config/deploy/production/app.yml.erb`. Occurences of `<%= image_repo %>` and `<%= current_sha %>` in these files will be dynamically replaced on deploy by the image repository URL and the latest commit hash of the selected branch on its git origin.
|
36
34
|
|
37
35
|
When you run `mina production deploy`, a namespace labelled `my_app-production` will be created on the Kubernetes cluster and set as a local kubectl context. Then the resources are applied to the cluster after checking/waiting for the image to be available on the repository.
|
38
36
|
|
@@ -52,4 +50,4 @@ Prompts for branch unless image tag is set, then spins up a temporary pod with t
|
|
52
50
|
|
53
51
|
#### `kubernetes:delete`
|
54
52
|
|
55
|
-
Confirms and delete all resources on cluster under namespace
|
53
|
+
Confirms and delete all resources on cluster under namespace.
|
data/lib/mina/kubernetes.rb
CHANGED
@@ -7,20 +7,13 @@ require "base64"
|
|
7
7
|
# required by mina
|
8
8
|
set :execution_mode, :pretty
|
9
9
|
|
10
|
-
# default for kubernetes-deploy
|
11
|
-
set :kube_config, "~/.kube/config"
|
12
|
-
|
13
10
|
namespace :kubernetes do
|
14
11
|
|
15
|
-
set :namespace, fetch(:app_name)
|
16
|
-
set :context, "#{fetch(:namespace)}-#{fetch(:stage)}"
|
17
|
-
|
18
12
|
task :deploy do
|
19
13
|
desc "Set image tag to be latest commit of prompted branch (unless provided) then applies resources to cluster"
|
20
14
|
set_tag_from_branch_commit unless fetch(:image_tag)
|
21
15
|
wait_until_image_ready(fetch(:image_tag))
|
22
16
|
create_namespace_on_cluster
|
23
|
-
set_local_config_context
|
24
17
|
apply_kubernetes_resources
|
25
18
|
end
|
26
19
|
|
@@ -35,17 +28,15 @@ namespace :kubernetes do
|
|
35
28
|
desc "Spins up temporary pod with image and runs given command in interactive shell, passing given environment variable"
|
36
29
|
set_tag_from_branch_commit unless fetch(:image_tag)
|
37
30
|
wait_until_image_ready(fetch(:image_tag))
|
38
|
-
run_terminal_command(fetch(:command),
|
31
|
+
run_terminal_command(fetch(:command), env_hash_arg)
|
39
32
|
end
|
40
33
|
|
41
34
|
task :delete do
|
42
35
|
desc "Delete all resources in namespace on cluster"
|
43
|
-
if TTY::Prompt.new.yes?("This will delete all resources in namespace #{fetch(:namespace)} on
|
36
|
+
if TTY::Prompt.new.yes?("This will delete all resources in namespace #{fetch(:namespace)} on context #{fetch(:kubernetes_context)}, are you sure?")
|
44
37
|
run :local do
|
45
38
|
comment "Deleting all resources in #{fetch(:namespace)}..."
|
46
|
-
command "kubectl delete namespace #{fetch(:namespace)} --
|
47
|
-
comment "Removing local config context..."
|
48
|
-
command "kubectl config unset contexts.#{fetch(:context)}"
|
39
|
+
command "kubectl delete namespace #{fetch(:namespace)} --context=#{fetch(:kubernetes_context)}"
|
49
40
|
end
|
50
41
|
end
|
51
42
|
end
|
@@ -54,6 +45,10 @@ end
|
|
54
45
|
|
55
46
|
private
|
56
47
|
|
48
|
+
def env_hash_arg
|
49
|
+
@env_hash_arg ||= (fetch(:env_hash).is_a?(String) ? JSON.parse(fetch(:env_hash)) : fetch(:env_hash)) || {}
|
50
|
+
end
|
51
|
+
|
57
52
|
def set_tag_from_branch_commit
|
58
53
|
run :local do
|
59
54
|
comment "Updating Git branches..."
|
@@ -66,14 +61,7 @@ end
|
|
66
61
|
def create_namespace_on_cluster
|
67
62
|
run :local do
|
68
63
|
comment "Create/update namespace on Kubernetes cluster..."
|
69
|
-
command "kubectl create namespace #{fetch(:namespace)} --dry-run -o yaml | kubectl apply -f - --
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def set_local_config_context
|
74
|
-
run :local do
|
75
|
-
comment "Set up local Kubernetes config context..."
|
76
|
-
command "kubectl config set-context #{fetch(:context)} --namespace=#{fetch(:namespace)} --cluster=#{fetch(:kubernetes_cluster)} --user=#{fetch(:kubernetes_user)}"
|
64
|
+
command "kubectl create namespace #{fetch(:namespace)} --dry-run -o yaml | kubectl apply -f - --context=#{fetch(:kubernetes_context)}"
|
77
65
|
end
|
78
66
|
end
|
79
67
|
|
@@ -97,12 +85,12 @@ def run_terminal_command(command, env_hash = {})
|
|
97
85
|
env = env_hash.collect{|k,v| "--env #{k}=#{v}" }.join(" ")
|
98
86
|
label = command.downcase.gsub(" ", "-").gsub(":", "-")
|
99
87
|
# using system instead of mina's command so tty opens successfully
|
100
|
-
system "kubectl run #{label}-#{SecureRandom.hex(4)} --rm -i --tty --restart=Never --context=#{fetch(:
|
88
|
+
system "kubectl run #{label}-#{SecureRandom.hex(4)} --rm -i --tty --restart=Never --context=#{fetch(:kubernetes_context)} --image #{fetch(:image_repo)}:#{fetch(:image_tag)} #{env} -- #{command}"
|
101
89
|
end
|
102
90
|
|
103
91
|
def apply_kubernetes_resources
|
104
92
|
run :local do
|
105
93
|
comment "Apply all Kubernetes resources..."
|
106
|
-
command "REVISION=#{fetch(:image_tag)}
|
94
|
+
command "REVISION=#{fetch(:image_tag)} kubernetes-deploy --template-dir=config/deploy/#{fetch(:stage)} --bindings=image_repo=#{fetch(:image_repo)},image_tag=#{fetch(:image_tag)},namespace=#{fetch(:namespace)} #{fetch(:namespace)} #{fetch(:kubernetes_context)}"
|
107
95
|
end
|
108
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-kubernetes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antoine Sabourin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- ".gitignore"
|
119
|
+
- CHANGELOG.md
|
119
120
|
- README.md
|
120
121
|
- Rakefile
|
121
122
|
- lib/mina/kubernetes.rb
|