dapp 0.13.8 → 0.13.9
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/config/en/net_status.yml +4 -0
- data/lib/dapp.rb +16 -3
- data/lib/dapp/cli/command/update.rb +2 -0
- data/lib/dapp/dapp/dapp_config.rb +1 -1
- data/lib/dapp/deployment/kubernetes.rb +1 -1
- data/lib/dapp/dimg/build/stage/base.rb +1 -1
- data/lib/dapp/dimg/config/directive/docker/artifact.rb +5 -0
- data/lib/dapp/helper/yaml.rb +23 -0
- data/lib/dapp/kube/cli/command/kube.rb +3 -1
- data/lib/dapp/kube/cli/command/kube/chart_create.rb +19 -0
- data/lib/dapp/kube/cli/command/kube/secret_edit.rb +24 -0
- data/lib/dapp/kube/dapp/command/chart_create.rb +104 -0
- data/lib/dapp/kube/dapp/command/common.rb +21 -2
- data/lib/dapp/kube/dapp/command/deploy.rb +50 -25
- data/lib/dapp/kube/dapp/command/secret_edit.rb +45 -0
- data/lib/dapp/kube/dapp/command/secret_extract.rb +1 -2
- data/lib/dapp/kube/dapp/command/secret_generate.rb +1 -2
- data/lib/dapp/kube/dapp/command/secret_regenerate.rb +2 -3
- data/lib/dapp/kube/dapp/dapp.rb +4 -0
- data/lib/dapp/kube/kubernetes.rb +6 -0
- data/lib/dapp/kube/kubernetes/client.rb +255 -0
- data/lib/dapp/kube/{client → kubernetes/client}/error.rb +8 -4
- data/lib/dapp/kube/kubernetes/client/resource/base.rb +21 -0
- data/lib/dapp/kube/kubernetes/client/resource/job.rb +27 -0
- data/lib/dapp/kube/kubernetes/client/resource/pod.rb +49 -0
- data/lib/dapp/kube/kubernetes/manager/base.rb +15 -0
- data/lib/dapp/kube/kubernetes/manager/container.rb +88 -0
- data/lib/dapp/kube/kubernetes/manager/job.rb +65 -0
- data/lib/dapp/kube/kubernetes/manager/pod.rb +35 -0
- data/lib/dapp/version.rb +1 -1
- metadata +17 -4
- data/lib/dapp/kube/client.rb +0 -241
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b002b0baef639d31484f8a6dc71dfacaa786683
|
4
|
+
data.tar.gz: a19fc91d6667e26f4a64b4b232583553c5c16e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b776834a1dbef3450b0d61d7bbefdb0afac5ee4cf80df121520e3fb540b9fcc0d3dc5567ac66ba2161df5880083ac687468c157200da64e6807f208bd401bdf
|
7
|
+
data.tar.gz: bed8a4f7b6fd98cb8b0dcbd7f3dfb357d61a05cb32a0c9b6173e6e5f013839ce0e3a3172d7653945c5339edb2168b2078c3594140c191a50a5887d0532196190
|
data/config/en/net_status.yml
CHANGED
@@ -39,6 +39,7 @@ en:
|
|
39
39
|
secret_values_file_not_found: "Secret values file `%{path}` not found!"
|
40
40
|
user_containers_detected: "User containers have been using images!\n%{ids}"
|
41
41
|
incorrect_yaml_structure: "Incorrect YAML structure in `%{path}`!"
|
42
|
+
editor_not_found: "Editor Not found!"
|
42
43
|
dapp:
|
43
44
|
no_such_dimg: "No such dimg: `%{dimgs_patterns}`!"
|
44
45
|
no_such_app: "No such app: `%{apps_patterns}`!"
|
@@ -48,6 +49,8 @@ en:
|
|
48
49
|
docker_not_found: "Docker not found!"
|
49
50
|
docker_version: "Required docker version: >= %{version}!"
|
50
51
|
dapp_config_file_incorrect: "%{message}"
|
52
|
+
yaml_file_incorrect: "Yaml file `%{file}`: `%{message}`"
|
53
|
+
yaml_incorrect: "`%{message}`"
|
51
54
|
incorrect_dapp_config_option: ".dapp_config includes option `%{option}` with incorrect value `%{value}`: expected one of the following types [%{expected}]"
|
52
55
|
incorrect_dapp_config_option_color: ".dapp_config includes option `color` with incorrect value `%{value}`: expected one of the following values [%{expected}]"
|
53
56
|
config:
|
@@ -66,6 +69,7 @@ en:
|
|
66
69
|
mount_from_type_required: "Mount: `from` directive expect `build_dir` or `tmp_dir` type!"
|
67
70
|
builder_type_conflict: 'Conflict between builder types!'
|
68
71
|
docker_from_incorrect: "`docker.from` has incorrect value `%{name}`!"
|
72
|
+
docker_artifact_unsupported_directive: "`artifact.docker` supports only `from` subdirective!"
|
69
73
|
stage_artifact_not_associated: "Artifact not associated with any stage: expected `before` or `after` attribute!"
|
70
74
|
stage_artifact_double_associate: "Cannot use `%{stage}` stage for artifact, already used in `%{conflict_stage}` stage!"
|
71
75
|
stage_artifact_not_supported_associated_stage: "Bad artifact stage `%{stage}`!"
|
data/lib/dapp.rb
CHANGED
@@ -32,6 +32,7 @@ require 'dapp/helper/trivia'
|
|
32
32
|
require 'dapp/helper/sha256'
|
33
33
|
require 'dapp/helper/net_status'
|
34
34
|
require 'dapp/helper/tar'
|
35
|
+
require 'dapp/helper/yaml'
|
35
36
|
require 'dapp/prctl'
|
36
37
|
require 'dapp/error/base'
|
37
38
|
require 'dapp/error/dapp'
|
@@ -105,8 +106,17 @@ require 'dapp/kube'
|
|
105
106
|
require 'dapp/kube/error/base'
|
106
107
|
require 'dapp/kube/error/command'
|
107
108
|
require 'dapp/kube/error/kubernetes'
|
108
|
-
require 'dapp/kube/
|
109
|
-
require 'dapp/kube/
|
109
|
+
require 'dapp/kube/secret'
|
110
|
+
require 'dapp/kube/kubernetes'
|
111
|
+
require 'dapp/kube/kubernetes/client'
|
112
|
+
require 'dapp/kube/kubernetes/client/error'
|
113
|
+
require 'dapp/kube/kubernetes/client/resource/base'
|
114
|
+
require 'dapp/kube/kubernetes/client/resource/pod'
|
115
|
+
require 'dapp/kube/kubernetes/client/resource/job'
|
116
|
+
require 'dapp/kube/kubernetes/manager/base'
|
117
|
+
require 'dapp/kube/kubernetes/manager/pod'
|
118
|
+
require 'dapp/kube/kubernetes/manager/container'
|
119
|
+
require 'dapp/kube/kubernetes/manager/job'
|
110
120
|
require 'dapp/kube/cli/command/base'
|
111
121
|
require 'dapp/kube/cli/command/kube'
|
112
122
|
require 'dapp/kube/cli/command/kube/deploy'
|
@@ -115,7 +125,9 @@ require 'dapp/kube/cli/command/kube/secret_key_generate'
|
|
115
125
|
require 'dapp/kube/cli/command/kube/secret_generate'
|
116
126
|
require 'dapp/kube/cli/command/kube/secret_extract'
|
117
127
|
require 'dapp/kube/cli/command/kube/secret_regenerate'
|
128
|
+
require 'dapp/kube/cli/command/kube/secret_edit'
|
118
129
|
require 'dapp/kube/cli/command/kube/minikube_setup'
|
130
|
+
require 'dapp/kube/cli/command/kube/chart_create'
|
119
131
|
require 'dapp/kube/cli/cli'
|
120
132
|
require 'dapp/kube/dapp/command/common'
|
121
133
|
require 'dapp/kube/dapp/command/deploy'
|
@@ -124,9 +136,10 @@ require 'dapp/kube/dapp/command/secret_key_generate'
|
|
124
136
|
require 'dapp/kube/dapp/command/secret_generate'
|
125
137
|
require 'dapp/kube/dapp/command/secret_extract'
|
126
138
|
require 'dapp/kube/dapp/command/secret_regenerate'
|
139
|
+
require 'dapp/kube/dapp/command/secret_edit'
|
127
140
|
require 'dapp/kube/dapp/command/minikube_setup'
|
141
|
+
require 'dapp/kube/dapp/command/chart_create'
|
128
142
|
require 'dapp/kube/dapp/dapp'
|
129
|
-
require 'dapp/kube/secret'
|
130
143
|
require 'dapp/dimg'
|
131
144
|
require 'dapp/dimg/builder'
|
132
145
|
require 'dapp/dimg/builder/base'
|
@@ -42,7 +42,7 @@ module Dapp
|
|
42
42
|
config_search_paths.reduce({}) do |options, dir|
|
43
43
|
if (config_options_path = make_path(dir, '.dapp_config')).file?
|
44
44
|
config_options = begin
|
45
|
-
|
45
|
+
yaml_load_file(config_options_path).tap do |c_options|
|
46
46
|
c_options.merge!(c_options.in_depth_merge(c_options['ci'] || {})) if ENV['GITLAB_CI'] || ENV['TRAVIS']
|
47
47
|
c_options.delete('ci')
|
48
48
|
end
|
@@ -163,7 +163,7 @@ module Dapp
|
|
163
163
|
def kube_config
|
164
164
|
@kube_config ||= begin
|
165
165
|
if File.exist?((kube_config_path = File.join(ENV['HOME'], '.kube/config')))
|
166
|
-
|
166
|
+
yaml_load_file(kube_config_path)
|
167
167
|
else
|
168
168
|
raise Error::Base, code: :kube_config_not_found, data: { path: kube_config_path }
|
169
169
|
end
|
@@ -231,7 +231,7 @@ module Dapp
|
|
231
231
|
end
|
232
232
|
|
233
233
|
def image_should_be_prepared?
|
234
|
-
!image.built? && !should_be_not_present? || image_should_be_introspected?
|
234
|
+
(!image.built? && !should_be_not_present? || image_should_be_introspected?) && !dimg.dapp.dry_run?
|
235
235
|
end
|
236
236
|
|
237
237
|
def should_be_not_present?
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Helper
|
3
|
+
module YAML
|
4
|
+
def yaml_load_file(file_path, hash: true)
|
5
|
+
yaml_load(File.read(file_path), hash: hash)
|
6
|
+
rescue ::Dapp::Error::Dapp => e
|
7
|
+
raise ::Dapp::Error::Dapp, code: :yaml_file_incorrect, data: { file: file_path, message: e.net_status[:data][:message] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def yaml_load(string, hash: true)
|
11
|
+
::YAML::load(string).tap do |res|
|
12
|
+
if hash && !res.is_a?(Hash)
|
13
|
+
raise ::Dapp::Error::Dapp,
|
14
|
+
code: :yaml_incorrect,
|
15
|
+
data: { message: "unexpected json data \n>>> START YAML\n#{string.strip}\n>>> END YAML\n" }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
rescue Psych::SyntaxError => e
|
19
|
+
raise ::Dapp::Error::Dapp, code: :yaml_incorrect, data: { message: e.message }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end # Helper
|
23
|
+
end # Dapp
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Dapp::Kube::CLI
|
2
2
|
module Command
|
3
3
|
class Kube < ::Dapp::CLI
|
4
|
-
SUBCOMMANDS = ['secret generate', 'secret key generate', 'secret regenerate', 'deploy', 'dismiss', 'secret extract', 'minikube setup'].freeze
|
4
|
+
SUBCOMMANDS = ['secret generate', 'secret key generate', 'secret regenerate', 'deploy', 'dismiss', 'secret extract', 'secret edit', 'minikube setup', 'chart create'].freeze
|
5
5
|
|
6
6
|
banner <<BANNER.freeze
|
7
7
|
Usage: dapp kube subcommand [subcommand options]
|
@@ -14,7 +14,9 @@ Available subcommands: (for details, dapp kube SUB-COMMAND --help)
|
|
14
14
|
dapp kube secret generate [FILE_PATH] [options]
|
15
15
|
dapp kube secret extract [FILE_PATH] [options]
|
16
16
|
dapp kube secret regenerate [SECRET_VALUES_FILE_PATH ...] [options]
|
17
|
+
dapp kube secret edit [FILE_PATH] [options]
|
17
18
|
dapp kube minikube setup
|
19
|
+
dapp kube chart create [options]
|
18
20
|
|
19
21
|
Options:
|
20
22
|
BANNER
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dapp::Kube::CLI::Command
|
2
|
+
class Kube < ::Dapp::CLI
|
3
|
+
class ChartCreate < Base
|
4
|
+
banner <<BANNER.freeze
|
5
|
+
Usage:
|
6
|
+
|
7
|
+
dapp kube chart create [options]
|
8
|
+
|
9
|
+
Options:
|
10
|
+
BANNER
|
11
|
+
|
12
|
+
option :force,
|
13
|
+
long: '--force',
|
14
|
+
short: '-f',
|
15
|
+
description: 'Delete existing chart',
|
16
|
+
default: false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Dapp::Kube::CLI::Command
|
2
|
+
class Kube < ::Dapp::CLI
|
3
|
+
class SecretEdit < Base
|
4
|
+
banner <<BANNER.freeze
|
5
|
+
Usage:
|
6
|
+
|
7
|
+
dapp kube secret edit [FILE_PATH] [options]
|
8
|
+
|
9
|
+
Options:
|
10
|
+
BANNER
|
11
|
+
|
12
|
+
option :values,
|
13
|
+
long: '--values',
|
14
|
+
description: 'Edit secret values file',
|
15
|
+
default: false
|
16
|
+
|
17
|
+
def run(argv = ARGV)
|
18
|
+
self.class.parse_options(self, argv)
|
19
|
+
file_path = self.class.required_argument(self, 'FILE_PATH')
|
20
|
+
::Dapp::Dapp.new(options: cli_options).public_send(run_method, file_path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Dapp
|
2
|
+
module Kube
|
3
|
+
module Dapp
|
4
|
+
module Command
|
5
|
+
module ChartCreate
|
6
|
+
def kube_chart_create
|
7
|
+
with_kube_tmp_chart_dir do
|
8
|
+
FileUtils.cp_r kube_chart_path, kube_tmp_chart_path(name) if kube_chart_path.directory? && !options[:force]
|
9
|
+
|
10
|
+
shellout!("helm create #{name}", cwd: kube_tmp_chart_path)
|
11
|
+
kube_create_chart_samples
|
12
|
+
|
13
|
+
FileUtils.rm_rf kube_chart_path
|
14
|
+
FileUtils.mv kube_tmp_chart_path(name), kube_chart_path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def kube_create_chart_samples
|
19
|
+
kube_tmp_chart_path(name, 'secret-values.yaml').tap { |f| FileUtils.touch(f) unless f.file? }
|
20
|
+
kube_tmp_chart_path(name, kube_chart_secret_dir_name).tap { |dir| FileUtils.mkdir(dir) unless dir.directory? }
|
21
|
+
kube_tmp_chart_path(name, 'templates', '_envs.tpl').tap do |f|
|
22
|
+
f.write begin
|
23
|
+
<<-EOF
|
24
|
+
{{- define "common_envs" }}
|
25
|
+
- name: A
|
26
|
+
value: value
|
27
|
+
{{- if eq .Values.global.env "production" }}
|
28
|
+
- name: B
|
29
|
+
value: value
|
30
|
+
{{- else }}
|
31
|
+
- name: B
|
32
|
+
value: value2
|
33
|
+
{{- if or (eq .Values.global.env "staging") (eq .Values.global.env "testing") }}
|
34
|
+
- name: C
|
35
|
+
value: value3
|
36
|
+
{{- end }}
|
37
|
+
{{- end }}
|
38
|
+
{{- end }}
|
39
|
+
EOF
|
40
|
+
end unless f.file?
|
41
|
+
end
|
42
|
+
kube_tmp_chart_path(name, 'templates', 'backend.yaml').tap do |f|
|
43
|
+
f.write begin
|
44
|
+
<<-EOF
|
45
|
+
apiVersion: extensions/v1beta1
|
46
|
+
kind: Deployment
|
47
|
+
metadata:
|
48
|
+
name: {{ .Chart.Name }}-backend
|
49
|
+
labels:
|
50
|
+
service: {{ .Chart.Name }}-backend
|
51
|
+
spec:
|
52
|
+
minReadySeconds: 60
|
53
|
+
strategy:
|
54
|
+
type: RollingUpdate
|
55
|
+
replicas: 2
|
56
|
+
template:
|
57
|
+
metadata:
|
58
|
+
labels:
|
59
|
+
service: {{ .Chart.Name }}-backend
|
60
|
+
spec:
|
61
|
+
volumes:
|
62
|
+
- name: {{ .Chart.Name }}-backend
|
63
|
+
secret:
|
64
|
+
secretName: {{ .Chart.Name }}-backend
|
65
|
+
containers:
|
66
|
+
- command: [ '/bin/bash', '-l', '-c', 'bundle exec ctl start' ]
|
67
|
+
image: {{ tuple . 'specific_name' | include "dimg" }} # or nameless dimg {{ tuple . | include "dimg" }}
|
68
|
+
imagePullPolicy: Always
|
69
|
+
name: {{ .Chart.Name }}-backend
|
70
|
+
livenessProbe:
|
71
|
+
httpGet:
|
72
|
+
path: /assets/logo.png
|
73
|
+
port: 8080
|
74
|
+
scheme: HTTP
|
75
|
+
initialDelaySeconds: 10
|
76
|
+
periodSeconds: 3
|
77
|
+
ports:
|
78
|
+
- containerPort: 8080
|
79
|
+
name: http
|
80
|
+
protocol: TCP
|
81
|
+
env:
|
82
|
+
{{- include "common_envs" . | indent 8 }}
|
83
|
+
---
|
84
|
+
apiVersion: v1
|
85
|
+
kind: Service
|
86
|
+
metadata:
|
87
|
+
name: {{ .Chart.Name }}-backend
|
88
|
+
spec:
|
89
|
+
type: ClusterIP
|
90
|
+
selector:
|
91
|
+
service: {{ .Chart.Name }}-backend
|
92
|
+
ports:
|
93
|
+
- name: http
|
94
|
+
port: 8080
|
95
|
+
protocol: TCP
|
96
|
+
EOF
|
97
|
+
end unless f.file?
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -46,13 +46,32 @@ module Dapp
|
|
46
46
|
) if secret.nil?
|
47
47
|
end
|
48
48
|
|
49
|
+
def kube_chart_secret_path(*path)
|
50
|
+
kube_chart_path(kube_chart_secret_dir_name, *path).expand_path
|
51
|
+
end
|
52
|
+
|
53
|
+
def kube_chart_secret_dir_name
|
54
|
+
'secret'
|
55
|
+
end
|
56
|
+
|
49
57
|
def kube_chart_path(*path)
|
50
58
|
self.path('.helm', *path).expand_path
|
51
59
|
end
|
52
60
|
|
61
|
+
def with_kube_tmp_chart_dir
|
62
|
+
yield if block_given?
|
63
|
+
ensure
|
64
|
+
FileUtils.rm_rf(kube_tmp_chart_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
def kube_tmp_chart_path(*path)
|
68
|
+
@kube_tmp_path ||= Dir.mktmpdir('dapp-helm-chart-', tmp_base_dir)
|
69
|
+
make_path(@kube_tmp_path, *path).expand_path.tap { |p| p.parent.mkpath }
|
70
|
+
end
|
71
|
+
|
53
72
|
def secret
|
54
73
|
@secret ||= begin
|
55
|
-
unless secret_key = ENV['DAPP_SECRET_KEY']
|
74
|
+
unless (secret_key = ENV['DAPP_SECRET_KEY'])
|
56
75
|
secret_key_not_found_in << '`DAPP_SECRET_KEY`'
|
57
76
|
|
58
77
|
if dappfile_exists?
|
@@ -76,7 +95,7 @@ module Dapp
|
|
76
95
|
def kubernetes
|
77
96
|
@kubernetes ||= begin
|
78
97
|
namespace = options[:namespace].nil? ? nil : options[:namespace].tr('_', '-')
|
79
|
-
Client.new(namespace: namespace)
|
98
|
+
Kubernetes::Client.new(namespace: namespace)
|
80
99
|
end
|
81
100
|
end
|
82
101
|
end
|
@@ -13,7 +13,7 @@ module Dapp
|
|
13
13
|
validate_repo_name!(repo)
|
14
14
|
validate_tag_name!(image_version)
|
15
15
|
|
16
|
-
|
16
|
+
with_kube_tmp_chart_dir do
|
17
17
|
kube_copy_chart
|
18
18
|
kube_helm_decode_secrets
|
19
19
|
kube_generate_helm_chart_tpl
|
@@ -29,10 +29,11 @@ module Dapp
|
|
29
29
|
options.concat(self.options[:helm_set_options].map { |opt| "--set #{opt}" })
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
hooks_jobs = kube_helm_hooks_jobs(additional_values, set_options)
|
33
|
+
|
34
|
+
kube_flush_hooks_jobs(hooks_jobs)
|
35
|
+
|
36
|
+
kube_run_deploy(additional_values, set_options, hooks_jobs: hooks_jobs)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
@@ -54,7 +55,7 @@ module Dapp
|
|
54
55
|
|
55
56
|
def kube_helm_decode_secret_values
|
56
57
|
kube_secret_values_paths.each_with_index do |secret_values_file, index|
|
57
|
-
decoded_data = kube_helm_decode_json(secret,
|
58
|
+
decoded_data = kube_helm_decode_json(secret, yaml_load_file(secret_values_file))
|
58
59
|
kube_tmp_chart_secret_values_paths[index].write(decoded_data.to_yaml)
|
59
60
|
end
|
60
61
|
end
|
@@ -75,14 +76,14 @@ module Dapp
|
|
75
76
|
|
76
77
|
{{- define "dimg" -}}
|
77
78
|
{{- if (ge (len (index .)) 2) -}}
|
78
|
-
{{- $name := index . 0 -}}
|
79
|
-
{{- $context := index . 1 -}}
|
79
|
+
{{- $name := index . 0 -}}
|
80
|
+
{{- $context := index . 1 -}}
|
80
81
|
{{- printf "%s:%s-%s" $context.Values.global.dapp.repo $name $context.Values.global.dapp.image_version -}}
|
81
82
|
{{- else -}}
|
82
83
|
{{- $context := index . 0 -}}
|
83
84
|
{{- printf "%s:%s" $context.Values.global.dapp.repo $context.Values.global.dapp.image_version -}}
|
84
|
-
{{- end -}}
|
85
|
-
{{- end -}}
|
85
|
+
{{- end -}}
|
86
|
+
{{- end -}}
|
86
87
|
|
87
88
|
{{- define "dapp_secret_file" -}}
|
88
89
|
{{- $relative_file_path := index . 0 -}}
|
@@ -93,16 +94,16 @@ module Dapp
|
|
93
94
|
kube_tmp_chart_path('templates/_dapp_helpers.tpl').write(cont)
|
94
95
|
end
|
95
96
|
|
96
|
-
def kube_flush_hooks_jobs(
|
97
|
-
return if (config_jobs_names =
|
97
|
+
def kube_flush_hooks_jobs(hooks_jobs)
|
98
|
+
return if (config_jobs_names = hooks_jobs.keys).empty?
|
98
99
|
config_jobs_names.select { |name| kube_job_list.include? name }.each do |name|
|
99
100
|
log_process("Delete hooks job `#{name}` for release #{kube_release_name} ", short: true) { kube_delete_job!(name) }
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
|
-
def
|
104
|
+
def kube_helm_hooks_jobs(additional_values, set_options)
|
104
105
|
generator = proc do |text|
|
105
|
-
text.split(/# Source.*|---/).reject {|c| c.strip.empty? }.map {|c|
|
106
|
+
text.split(/# Source.*|---/).reject {|c| c.strip.empty? }.map {|c| yaml_load(c) }.reduce({}) do |objects, c|
|
106
107
|
objects[c['kind']] ||= {}
|
107
108
|
objects[c['kind']][(c['metadata'] || {})['name']] = c
|
108
109
|
objects
|
@@ -114,7 +115,7 @@ module Dapp
|
|
114
115
|
|
115
116
|
manifest_start_index = output.lines.index("MANIFEST:\n") + 1
|
116
117
|
hook_start_index = output.lines.index("HOOKS:\n") + 1
|
117
|
-
configs = generator.call(output.lines[hook_start_index..manifest_start_index-
|
118
|
+
configs = generator.call(output.lines[hook_start_index..manifest_start_index-2].join)
|
118
119
|
|
119
120
|
(configs['Job'] || {}).reject do |_, c|
|
120
121
|
c['metadata'] ||= {}
|
@@ -135,11 +136,44 @@ module Dapp
|
|
135
136
|
end
|
136
137
|
end
|
137
138
|
|
138
|
-
def kube_run_deploy(additional_values, set_options)
|
139
|
+
def kube_run_deploy(additional_values, set_options, hooks_jobs: {})
|
139
140
|
log_process("Deploy release #{kube_release_name}") do
|
141
|
+
release_exists = shellout("helm status #{kube_release_name}").status.success?
|
142
|
+
|
143
|
+
hooks_jobs_by_type = hooks_jobs
|
144
|
+
.reduce({}) do |res, (job_name, job_spec)|
|
145
|
+
job = Kubernetes::Client::Resource::Job.new(job_spec)
|
146
|
+
|
147
|
+
if job.annotations['dapp/watch-logs'].to_s == 'true'
|
148
|
+
job.annotations['helm.sh/hook'].to_s.split(',').each do |hook_type|
|
149
|
+
res[hook_type] ||= []
|
150
|
+
res[hook_type] << job
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
res
|
155
|
+
end
|
156
|
+
.tap do |res|
|
157
|
+
res.values.each do |jobs|
|
158
|
+
jobs.sort_by! {|job| job.annotations['helm.sh/hook-weight'].to_i}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
watch_jobs = if release_exists
|
163
|
+
hooks_jobs_by_type['pre-upgrade'].to_a + hooks_jobs_by_type['post-upgrade'].to_a
|
164
|
+
else
|
165
|
+
hooks_jobs_by_type['pre-install'].to_a + hooks_jobs_by_type['post-install'].to_a
|
166
|
+
end
|
167
|
+
|
168
|
+
watch_thr = Thread.new do
|
169
|
+
watch_jobs.each {|job| Kubernetes::Manager::Job.new(self, job.name).watch_till_done!}
|
170
|
+
end
|
171
|
+
|
140
172
|
args = [kube_release_name, kube_tmp_chart_path, additional_values, set_options, kube_helm_extra_options].flatten
|
141
173
|
kubernetes.create_namespace!(kube_namespace) unless kubernetes.namespace?(kube_namespace)
|
142
174
|
shellout! "helm upgrade #{args.join(' ')}", verbose: true
|
175
|
+
|
176
|
+
watch_thr.join
|
143
177
|
end
|
144
178
|
end
|
145
179
|
|
@@ -163,11 +197,6 @@ module Dapp
|
|
163
197
|
kube_tmp_chart_path('decoded-secret', *path).tap { |p| p.parent.mkpath }
|
164
198
|
end
|
165
199
|
|
166
|
-
def kube_tmp_chart_path(*path)
|
167
|
-
@kube_tmp_path ||= Dir.mktmpdir('dapp-helm-chart-', tmp_base_dir)
|
168
|
-
make_path(@kube_tmp_path, *path).expand_path.tap { |p| p.parent.mkpath }
|
169
|
-
end
|
170
|
-
|
171
200
|
def kube_values_paths
|
172
201
|
self.options[:helm_values_options].map { |p| Pathname(p).expand_path }.each do |f|
|
173
202
|
raise Error::Command, code: :values_file_not_found, data: { path: f } unless f.file?
|
@@ -190,10 +219,6 @@ module Dapp
|
|
190
219
|
def kube_chart_secret_values_path
|
191
220
|
kube_chart_path('secret-values.yaml').expand_path
|
192
221
|
end
|
193
|
-
|
194
|
-
def kube_chart_secret_path(*path)
|
195
|
-
kube_chart_path('secret', *path).expand_path
|
196
|
-
end
|
197
222
|
end
|
198
223
|
end
|
199
224
|
end
|