Skip to content

Commit d2370e6

Browse files
author
Mark Priest
authored
[mkdocs-material] Add option for installing the mkdocs-macros-plugin.
[mkdocs-material] Add option for installing the mkdocs-macros-plugin. This PR adds support for the mkdocs-macros-plugin. The template supports the use of optional external yaml values files to be included via a ConfigMap mounted to the pod that builds mkdocs. As explained in detail in a comment in the values.yaml file, this allows docs to define local default values that can be used while testing doc changes locally, which will be overwritten by the external yaml files (which support embedded templating) when deployed. There is also a consolidation of the git-pull and mkdocs-build container specs that are shared between the deployment and the cronjob to reduce maintenance as per DRY.
2 parents 49cc344 + b8a6b8b commit d2370e6

File tree

7 files changed

+221
-209
lines changed

7 files changed

+221
-209
lines changed

charts/mkdocs-material/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.2.8
18+
version: 0.2.9
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to

charts/mkdocs-material/templates/_helpers.tpl

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,150 @@ Subpath prefix value to use for pvc mount points
6767
{{- define "mkdocs-material.subpathPrefix" -}}
6868
{{- $path := default (include "mkdocs-material.fullname" .) .Values.storage.overrideSubpathPrefix -}}
6969
{{- ternary ($path | printf "%s/" ) "" .Values.storage.existingSubpathPrefix -}}
70-
{{- end }}
70+
{{- end }}
71+
72+
{{/*
73+
Shared yaml for the git containers
74+
*/}}
75+
{{- define "mkdocs-material.git-container" }}
76+
{{- if .Values.giturl }}
77+
- name: git-pull
78+
image: "bitnami/git"
79+
command: ["/entry.d/git-pull.sh"]
80+
env:
81+
- name: DOCS_GIT_URL
82+
value: {{ (tpl .Values.giturl .) }}
83+
- name: DOCS_GIT_BRANCH
84+
value: {{ .Values.gitbranch }}
85+
{{- if .Values.gitCredentialsSecret }}
86+
- name: DOCS_GIT_CRED_FILE
87+
value: {{ default ".git-credentials" .Values.gitCredentialsSecretKey }}
88+
{{- end }}
89+
{{- if .Values.gitPath }}
90+
- name: DOCS_GIT_PATH
91+
value: {{ .Values.gitPath | trimPrefix "/" }}
92+
{{- end }}
93+
{{- if .Values.mkdocs.site_url }}
94+
- name: DOCS_SITE_URL
95+
value: {{ .Values.mkdocs.site_url }}
96+
{{- end }}
97+
volumeMounts:
98+
- mountPath: /entry.d
99+
name: {{ include "mkdocs-material.fullname" . }}-entry
100+
- mountPath: /docs
101+
name: {{ include "mkdocs-material.fullname" . }}-vol
102+
subPath: {{ include "mkdocs-material.subpathPrefix" . }}docs
103+
- mountPath: /git
104+
name: {{ include "mkdocs-material.fullname" . }}-vol
105+
subPath: {{ include "mkdocs-material.subpathPrefix" . }}git
106+
{{- if .Values.gitCredentialsSecret }}
107+
- mountPath: /git-credentials
108+
name: {{ include "mkdocs-material.fullname" . }}-git-creds
109+
{{- end }}
110+
{{- if or .Values.certificateMap .Values.cacert }}
111+
- mountPath: /usr/local/share/ca-certificates
112+
name: certificates
113+
{{- end }}
114+
{{- end }}
115+
{{- end }}
116+
117+
{{/*
118+
Shared yaml for the mkdocs containers
119+
*/}}
120+
{{- define "mkdocs-material.mkdocs-container" }}
121+
- name: mkdocs-build
122+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
123+
imagePullPolicy: {{ .Values.image.pullPolicy }}
124+
{{- if .Values.giturl }}
125+
command: ["/entry.d/mkdocs-build.sh"]
126+
{{- else }}
127+
args: ["build"]
128+
{{- end }}
129+
env:
130+
- name: MKDOCS_ADD_MACROS
131+
value: {{ default "false" .Values.macrosPlugin.enabled | toString | quote }}
132+
- name: MKDOCS_MACROS_VERSION
133+
value: {{ default "1.3.9" .Values.macrosPlugin.version | toString | quote }}
134+
{{- if .Values.gitPath }}
135+
- name: DOCS_GIT_PATH
136+
value: {{ .Values.gitPath | trimPrefix "/" }}
137+
{{- end }}
138+
volumeMounts:
139+
{{- if and .Values.macrosPlugin.enabled .Values.macrosPlugin.extraYamlConfig }}
140+
- mountPath: {{ default "/mkdocs-vars" .Values.macrosPlugin.extraYamlConfigMount }}
141+
name: {{ include "mkdocs-material.fullname" . }}-macro-vars
142+
{{- end }}
143+
{{- if .Values.giturl }}
144+
- mountPath: /entry.d
145+
name: {{ include "mkdocs-material.fullname" . }}-entry
146+
- mountPath: /docs
147+
name: {{ include "mkdocs-material.fullname" . }}-vol
148+
subPath: {{ include "mkdocs-material.subpathPrefix" . }}docs
149+
- mountPath: /git
150+
name: {{ include "mkdocs-material.fullname" . }}-vol
151+
subPath: {{ include "mkdocs-material.subpathPrefix" . }}git
152+
{{- else }}
153+
- mountPath: /docs/mkdocs.yml
154+
name: {{ include "mkdocs-material.fullname" . }}
155+
subPath: mkdocs.yml
156+
- mountPath: /docs/docs
157+
name: {{ include "mkdocs-material.fullname" . }}-files
158+
- mountPath: /docs/site
159+
name: {{ include "mkdocs-material.fullname" . }}-vol
160+
subPath: {{ include "mkdocs-material.subpathPrefix" . }}docs/site
161+
{{- end }}
162+
{{- end }}
163+
164+
{{/*
165+
Shared yaml for the volumes
166+
*/}}
167+
{{- define "mkdocs-material.container-volumes" }}
168+
- name: {{ include "mkdocs-material.fullname" . }}
169+
configMap:
170+
name: {{ include "mkdocs-material.fullname" . }}
171+
{{- if .Values.giturl }}
172+
- name: {{ include "mkdocs-material.fullname" . }}-entry
173+
configMap:
174+
name: {{ include "mkdocs-material.fullname" . }}-entry
175+
defaultMode: 0775
176+
{{- if .Values.gitCredentialsSecret }}
177+
- name: {{ include "mkdocs-material.fullname" . }}-git-creds
178+
secret:
179+
secretName: {{ .Values.gitCredentialsSecret }}
180+
defaultMode: 0600
181+
{{- end }}
182+
{{- else }}
183+
- name: {{ include "mkdocs-material.fullname" . }}-files
184+
configMap:
185+
name: {{ include "mkdocs-material.fullname" . }}-files
186+
{{- end }}
187+
{{- if .Values.storage.existing }}
188+
- name: {{ include "mkdocs-material.fullname" . }}-vol
189+
persistentVolumeClaim:
190+
claimName: {{ .Values.storage.existing }}
191+
{{- else if .Values.storage.size }}
192+
- name: {{ include "mkdocs-material.fullname" . }}-vol
193+
persistentVolumeClaim:
194+
claimName: {{ include "mkdocs-material.fullname" . }}
195+
{{- else if .Values.giturl }}
196+
{{- fail "Git deployment mode requires persistent volume" }}
197+
{{- else }}
198+
- name: {{ include "mkdocs-material.fullname" . }}-vol
199+
emptyDir: {}
200+
{{- end }}
201+
{{- if .Values.certificateMap }}
202+
- name: certificates
203+
configMap:
204+
name: {{ .Values.certificateMap }}
205+
{{- end }}
206+
{{- if .Values.cacert }}
207+
- name: certificates
208+
configMap:
209+
name: {{ include "mkdocs-material.fullname" . }}-cacerts
210+
{{- end }}
211+
{{- if and .Values.macrosPlugin.enabled .Values.macrosPlugin.extraYamlConfig }}
212+
- name: {{ include "mkdocs-material.fullname" . }}-macro-vars
213+
configMap:
214+
name: {{ include "mkdocs-material.fullname" . }}-macro-vars
215+
{{- end }}
216+
{{- end }}

charts/mkdocs-material/templates/configmap-entry.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ data:
3030
3131
git reset --hard
3232
git clean -f
33-
34-
if [ -n "$DOCS_GIT_BRANCH" ]; then
33+
34+
if [ -n "$DOCS_GIT_BRANCH" ]; then
3535
gitcheckoutoutput=`git checkout "$DOCS_GIT_BRANCH" 2>&1`
3636
echo "$gitcheckoutoutput" | grep "Switch*" > /dev/null 2>&1
3737
if [ "$?" -eq "0" ]; then
@@ -60,16 +60,22 @@ data:
6060
6161
sed -i -r -e "s#^(site_url: )(.*)#\1${DOCS_SITE_URL}#" mkdocs.yml
6262
found_url=`grep -c 'site_url:' mkdocs.yml`
63-
if [ $found_url = 0 ]; then
63+
if [ $found_url = 0 ]; then
6464
echo "site_url: ${DOCS_SITE_URL}" | cat - mkdocs.yml > tmp.yml
6565
mv tmp.yml mkdocs.yml
6666
fi
67-
fi
67+
fi
6868
6969
mkdocs-build.sh: |-
7070
#!/bin/sh
7171
7272
if [ -f "/docs/.dirty" ]; then
73+
74+
if [ "$MKDOCS_ADD_MACROS" = "true" ]; then
75+
echo "Installing mkdocs-macros-plugin version ${MKDOCS_MACROS_VERSION}..."
76+
pip install --no-cache-dir mkdocs-macros-plugin=="$MKDOCS_MACROS_VERSION"
77+
fi
78+
7379
echo "Building docs..."
7480
7581
if [ -n "$DOCS_GIT_PATH" ]; then
@@ -94,7 +100,7 @@ data:
94100
cd /docs
95101
tmp_path=`basename "$new_docs"`
96102
chmod 775 "$tmp_path"
97-
103+
98104
## Delete the previous symbolic link
99105
rm "site"
100106
@@ -104,7 +110,7 @@ data:
104110
if [ -n "$old_docs" ]; then
105111
echo "Removing old docs: $old_docs"
106112
rm -Rf "$old_docs"
107-
else
113+
else
108114
echo "No old docs to remove"
109115
fi
110116
@@ -119,8 +125,8 @@ data:
119125
else
120126
echo "Mkdocs build failed."
121127
fi
122-
else
123-
echo "Docs directory not found: ${docs_dir}"
128+
else
129+
echo "Docs directory not found: ${docs_dir}"
124130
fi
125131
else
126132
echo "Docs are up-to-date."
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if and .Values.macrosPlugin.enabled .Values.macrosPlugin.extraYamlConfig }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ include "mkdocs-material.fullname" . }}-macro-vars
6+
labels:
7+
{{- include "mkdocs-material.labels" . | nindent 4 }}
8+
9+
data:
10+
{{- range .Values.macrosPlugin.extraYamlConfig }}
11+
{{- $configContent := toYaml .values }}
12+
{{ .path }}: |-
13+
{{- (tpl $configContent $) | nindent 4}}
14+
{{- end }}
15+
{{- end }}

charts/mkdocs-material/templates/cronjob.yaml

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -23,92 +23,9 @@ spec:
2323
spec:
2424
restartPolicy: Never
2525
initContainers:
26-
- name: git-pull
27-
image: "bitnami/git"
28-
command: ["/entry.d/git-pull.sh"]
29-
env:
30-
- name: DOCS_GIT_URL
31-
value: {{ (tpl .Values.giturl .) }}
32-
- name: DOCS_GIT_BRANCH
33-
value: {{ .Values.gitbranch }}
34-
{{- if .Values.gitCredentialsSecret }}
35-
- name: DOCS_GIT_CRED_FILE
36-
value: {{ default ".git-credentials" .Values.gitCredentialsSecretKey }}
37-
{{- end }}
38-
{{- if .Values.gitPath }}
39-
- name: DOCS_GIT_PATH
40-
value: {{ .Values.gitPath | trimPrefix "/" }}
41-
{{- end }}
42-
{{- if .Values.mkdocs.site_url }}
43-
- name: DOCS_SITE_URL
44-
value: {{ .Values.mkdocs.site_url }}
45-
{{- end }}
46-
volumeMounts:
47-
- mountPath: /entry.d
48-
name: {{ include "mkdocs-material.fullname" . }}-entry
49-
- mountPath: /docs
50-
name: {{ include "mkdocs-material.fullname" . }}-vol
51-
subPath: {{ include "mkdocs-material.subpathPrefix" . }}docs
52-
- mountPath: /git
53-
name: {{ include "mkdocs-material.fullname" . }}-vol
54-
subPath: {{ include "mkdocs-material.subpathPrefix" . }}git
55-
{{- if .Values.gitCredentialsSecret }}
56-
- mountPath: /git-credentials
57-
name: {{ include "mkdocs-material.fullname" . }}-git-creds
58-
{{- end }}
59-
{{- if or .Values.certificateMap .Values.cacert }}
60-
- mountPath: /usr/local/share/ca-certificates
61-
name: certificates
62-
{{- end }}
26+
{{- include "mkdocs-material.git-container" . | nindent 12 }}
6327
containers:
64-
- name: mkdocs-build
65-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
66-
imagePullPolicy: {{ .Values.image.pullPolicy }}
67-
command: ["/entry.d/mkdocs-build.sh"]
68-
{{- if .Values.gitPath }}
69-
env:
70-
- name: DOCS_GIT_PATH
71-
value: {{ .Values.gitPath | trimPrefix "/" }}
72-
{{- end }}
73-
volumeMounts:
74-
- mountPath: /entry.d
75-
name: {{ include "mkdocs-material.fullname" . }}-entry
76-
- mountPath: /docs
77-
name: {{ include "mkdocs-material.fullname" . }}-vol
78-
subPath: {{ include "mkdocs-material.subpathPrefix" . }}docs
79-
- mountPath: /git
80-
name: {{ include "mkdocs-material.fullname" . }}-vol
81-
subPath: {{ include "mkdocs-material.subpathPrefix" . }}git
28+
{{- include "mkdocs-material.mkdocs-container" . | nindent 12 }}
8229
volumes:
83-
- name: {{ include "mkdocs-material.fullname" . }}-entry
84-
configMap:
85-
name: {{ include "mkdocs-material.fullname" . }}-entry
86-
defaultMode: 0775
87-
{{- if .Values.storage.existing }}
88-
- name: {{ include "mkdocs-material.fullname" . }}-vol
89-
persistentVolumeClaim:
90-
claimName: {{ .Values.storage.existing }}
91-
{{- else }}
92-
- name: {{ include "mkdocs-material.fullname" . }}-vol
93-
persistentVolumeClaim:
94-
claimName: {{ include "mkdocs-material.fullname" . }}
95-
{{- end }}
96-
{{- if .Values.gitCredentialsSecret }}
97-
- name: {{ include "mkdocs-material.fullname" . }}-git-creds
98-
secret:
99-
secretName: {{ .Values.gitCredentialsSecret }}
100-
defaultMode: 0600
101-
{{- end }}
102-
{{- if .Values.certificateMap }}
103-
- name: certificates
104-
configMap:
105-
name: {{ .Values.certificateMap }}
106-
{{- end }}
107-
{{- if .Values.cacert }}
108-
- name: certificates
109-
configMap:
110-
name: {{ include "mkdocs-material.fullname" . }}-cacerts
111-
{{- end }}
112-
30+
{{- include "mkdocs-material.container-volumes" . | nindent 12 }}
11331
{{- end }}
114-

0 commit comments

Comments
 (0)