-
Notifications
You must be signed in to change notification settings - Fork 18
/
deployment.yaml
184 lines (173 loc) · 7.07 KB
/
deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
{{- $nodeDevInstall := and .Values.developer.enabled (empty .Values.developer.mountedNodeModuleToInstall | not) -}}
{{- $nodeMountedModulePath := $nodeDevInstall | ternary (printf "%s/%s" .Values.developer.sourcePath .Values.developer.mountedNodeModuleToInstall) "" -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "diracx.fullname" . }}-web
labels:
{{- include "diracx.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "diracxWeb.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "diracxWeb.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "diracx.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
{{- if $nodeDevInstall }}
# This volume is used to mount the source code of the diracx-web repository
- name: diracx-web-code-mount
persistentVolumeClaim:
claimName: pvc-diracx-code
# These volumes override the node_modules directories to
# start from a clean state
- name: diracx-web-scratch-node-modules
emptyDir:
sizeLimit: 2Gi
{{- range $module := .Values.developer.nodeWorkspacesDirectories }}
- name: 'diracx-web-scratch-node-modules-{{ replace "/" "-" $module -}}'
emptyDir:
sizeLimit: 2Gi
{{- end }}
{{- else }}
{{- if .Values.diracxWeb.branch }}
# This volume is used to clone the specified diracx-web repository branch
- name: diracx-web-code
emptyDir:
sizeLimit: 2Gi
# This volume is used to store the static files of the diracx-web repository
- name: diracx-web-static-files
emptyDir:
sizeLimit: 2Gi
{{- end }}
{{- end }}
initContainers:
{{- if and (not $nodeDevInstall) .Values.diracxWeb.branch }}
# This init container is used to clone the specified diracx-web repository branch
- name: clone-diracx-web
image: ghcr.io/diracgrid/diracx/secret-generation:latest
imagePullPolicy: {{ .Values.global.imagePullPolicy }}
command: ["/bin/sh", "-c"]
args:
- |
# Clone the specified diracx-web repository branch
git clone --single-branch -b {{ .Values.diracxWeb.branch }} {{ required "A valid .Values.diracxWeb.repoURL is required!" .Values.diracxWeb.repoURL }} /diracx-web;
volumeMounts:
- mountPath: "/diracx-web"
name: "diracx-web-code"
{{- end }}
{{- if or $nodeDevInstall .Values.diracxWeb.branch }}
# This init container is used to install the node module
- name: install-diracx-web
image: {{ .Values.developer.nodeImage }}
imagePullPolicy: {{ .Values.global.imagePullPolicy }}
{{- if $nodeDevInstall }}
# Install the mounted node module
command: ["npm", "ci"]
workingDir: "{{ $nodeMountedModulePath }}"
# These volumes contain the source code of the mounted diracx-web directory,
# minus the node_modules and next directories
volumeMounts:
- mountPath: "{{ $nodeMountedModulePath }}"
name: "diracx-web-code-mount"
subPath: "{{ .Values.developer.mountedNodeModuleToInstall }}"
- mountPath: "{{ $nodeMountedModulePath }}/node_modules"
name: "diracx-web-scratch-node-modules"
{{- range $module := .Values.developer.nodeWorkspacesDirectories }}
- mountPath: "{{ $nodeMountedModulePath }}/{{ $module }}/node_modules"
name: 'diracx-web-scratch-node-modules-{{ replace "/" "-" $module -}}'
{{- end }}
{{- else }}
# Install the diracx-web repository, specific branch
command: ["/bin/sh", "-c"]
args:
- |
# Install dependencies and build the app
npm ci && \
NEXT_TELEMETRY_DISABLED=1 npm run build && \
mv out/* /app/
workingDir: "/diracx-web"
volumeMounts:
# This volume contains the source code of the cloned diracx-web repository
- mountPath: "/diracx-web"
name: "diracx-web-code"
# This volume will contain the static files of the diracx-web repository
- mountPath: "/app"
name: "diracx-web-static-files"
{{- end }}
{{- end }}
containers:
- name: {{ .Chart.Name }}-web
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
imagePullPolicy: {{ .Values.global.imagePullPolicy }}
ports:
- name: http
containerPort: {{ .Values.diracxWeb.service.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
{{- if $nodeDevInstall }}
# Start the node module in development mode
image: {{ .Values.developer.nodeImage }}
command: ["npm", "run", "dev"]
workingDir: "{{ $nodeMountedModulePath }}"
env:
- name: NEXT_TELEMETRY_DISABLED
value: "1"
- name: PORT
value: "{{ .Values.diracxWeb.service.port }}"
volumeMounts:
- mountPath: "{{ $nodeMountedModulePath }}"
name: "diracx-web-code-mount"
subPath: "{{ .Values.developer.mountedNodeModuleToInstall }}"
- mountPath: "{{ $nodeMountedModulePath }}/node_modules"
name: "diracx-web-scratch-node-modules"
{{- range $module := .Values.developer.nodeWorkspacesDirectories }}
- mountPath: "{{ $nodeMountedModulePath }}/{{ $module }}/node_modules"
name: 'diracx-web-scratch-node-modules-{{ replace "/" "-" $module -}}'
{{- end }}
{{- else }}
# Start the node module in production mode
image: {{ .Values.global.images.web.repository }}:{{ .Values.global.images.web.tag }}
{{ if .Values.diracxWeb.branch }}
# Start it from the specified branch
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: "diracx-web-static-files"
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}