Module: Dapp::Kube::Dapp::Command::ChartCreate

Included in:
Dapp
Defined in:
lib/dapp/kube/dapp/command/chart_create.rb

Instance Method Summary collapse

Instance Method Details

#kube_chart_createObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dapp/kube/dapp/command/chart_create.rb', line 6

def kube_chart_create
  with_kube_tmp_chart_dir do
    FileUtils.cp_r kube_chart_path, kube_chart_path_for_helm(name) if kube_chart_path.directory? && !options[:force]

    shellout!("helm create #{name}", cwd: kube_chart_path_for_helm)
    kube_create_chart_samples

    FileUtils.rm_rf kube_chart_path
    FileUtils.mv kube_chart_path_for_helm(name), kube_chart_path
  end
end

#kube_create_chart_samplesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/dapp/kube/dapp/command/chart_create.rb', line 18

def kube_create_chart_samples
  kube_chart_path_for_helm(name, 'secret-values.yaml').tap { |f| FileUtils.touch(f) unless f.file? }
  kube_chart_path_for_helm(name, kube_chart_secret_dir_name).tap { |dir| FileUtils.mkdir(dir) unless dir.directory? }
  kube_chart_path_for_helm(name, 'templates',  '_envs.tpl').tap do |f|
    f.write begin
      "{{- define \"common_envs\" }}\n- name: A\nvalue: value\n{{-   if eq .Values.global.env \"production\" }}\n- name: B\nvalue: value\n{{-   else }}\n- name: B\nvalue: value2\n{{-     if or (eq .Values.global.env \"stage\") (eq .Values.global.env \"test\") }}\n- name: C\nvalue: value3\n{{-     end }}\n{{-   end }}\n{{- end }}\n"
    end unless f.file?
  end
  kube_chart_path_for_helm(name, 'templates', 'backend.yaml').tap do |f|
    f.write begin
      "apiVersion: extensions/v1beta1\nkind: Deployment\nmetadata:\nname: {{ .Chart.Name }}-backend\nlabels:\nservice: {{ .Chart.Name }}-backend\nspec:\nminReadySeconds: 60\nstrategy:\ntype: RollingUpdate\nreplicas: 2\ntemplate:\nmetadata:\nlabels:\nservice: {{ .Chart.Name }}-backend\nspec:\nvolumes:\n- name: {{ .Chart.Name }}-backend\nsecret:\nsecretName: {{ .Chart.Name }}-backend\ncontainers:\n- command: [ '/bin/bash', '-l', '-c', 'bundle exec ctl start' ]\n{{ tuple \"dimg-name\" . | include \"dapp_container_image\" | indent 8 }} # or nameless dimg {{ tuple . | include \"dapp_container_image\" }}\nname: {{ .Chart.Name }}-backend\nlivenessProbe:\nhttpGet:\npath: /assets/logo.png\nport: 8080\nscheme: HTTP\ninitialDelaySeconds: 10\nperiodSeconds: 3\nports:\n- containerPort: 8080\nname: http\nprotocol: TCP\nenv:\n{{ tuple \"dimg-name\" . | include \"dapp_container_env\" | indent 10 }}\n---\napiVersion: v1\nkind: Service\nmetadata:\nname: {{ .Chart.Name }}-backend\nspec:\ntype: ClusterIP\nselector:\nservice: {{ .Chart.Name }}-backend\nports:\n- name: http\nport: 8080\nprotocol: TCP\n"
    end unless f.file?
  end
end