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
99
# 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
      <<-EOF
{{- define "common_envs" }}
- name: A
  value: value
{{-   if eq .Values.global.env "production" }}
- name: B
  value: value
{{-   else }}
- name: B
  value: value2
{{-     if or (eq .Values.global.env "staging") (eq .Values.global.env "testing") }}
- name: C
  value: value3
{{-     end }}
{{-   end }}
{{- end }}
      EOF
    end unless f.file?
  end
  kube_chart_path_for_helm(name, 'templates', 'backend.yaml').tap do |f|
    f.write begin
      <<-EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}-backend
  labels:
    service: {{ .Chart.Name }}-backend
spec:
  minReadySeconds: 60
  strategy:
    type: RollingUpdate
  replicas: 2
  template:
    metadata:
      labels:
        service: {{ .Chart.Name }}-backend
    spec:
      volumes:
      - name: {{ .Chart.Name }}-backend
        secret:
secretName: {{ .Chart.Name }}-backend
      containers:
      - command: [ '/bin/bash', '-l', '-c', 'bundle exec ctl start' ]
        image: {{ tuple "specific-name" . | include "dimg" }} # or nameless dimg {{ tuple . | include "dimg" }}
        imagePullPolicy: Always
        name: {{ .Chart.Name }}-backend
        livenessProbe:
httpGet:
  path: /assets/logo.png
  port: 8080
  scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 3
        ports:
        - containerPort: 8080
name: http
protocol: TCP
        env:
{{- include "common_envs" . | indent 8 }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ .Chart.Name }}-backend
spec:
  type: ClusterIP
  selector:
    service: {{ .Chart.Name }}-backend
  ports:
  - name: http
    port: 8080
    protocol: TCP
      EOF
    end unless f.file?
  end
end