From 4a5cc44c7c30f31924e91c8e7db4c87af07af47e Mon Sep 17 00:00:00 2001 From: Alejandro Moreno Date: Fri, 4 Oct 2019 14:04:01 +0000 Subject: [PATCH] Allow mounting files from files/ directory --- bitnami/apache/README.md | 4 +++- bitnami/apache/files/README.md | 1 + bitnami/apache/files/vhosts/README.md | 1 + bitnami/apache/templates/_helpers.tpl | 22 +++++++++++++++++++ .../apache/templates/configmap-vhosts.yaml | 13 +++++++++++ bitnami/apache/templates/configmap.yaml | 13 +++++++++++ bitnami/apache/templates/deployment.yaml | 12 +++++----- 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 bitnami/apache/files/README.md create mode 100644 bitnami/apache/files/vhosts/README.md create mode 100644 bitnami/apache/templates/configmap-vhosts.yaml create mode 100644 bitnami/apache/templates/configmap.yaml diff --git a/bitnami/apache/README.md b/bitnami/apache/README.md index b1ac3b2c4b..cabd0679cd 100644 --- a/bitnami/apache/README.md +++ b/bitnami/apache/README.md @@ -128,7 +128,9 @@ In the following example you can deploy a example web application using git: helm install bitnami/apache --set cloneHtdocsFromGit.enabled=true --set cloneHtdocsFromGit.repository=https://github.com/mdn/beginner-html-site-styled.git --set cloneHtdocsFromGit.branch=master ``` -You may also want to mount different virtual host configurations. This can be done using the `vhostsConfigMap` value. This a pointer to a ConfigMap with the desired Apache virtual host configurations. +To use your own `httpd.conf` file you can mount it using the `httpdConfConfigMap` parameter, which is the name of a Config Map with the contents of your `httpd.conf`. Additionaly, you can copy your `httpd.conf` to `/files/httpd.conf` in your current working directory to mount it to the container. + +You may also want to mount different virtual host configurations. This can be done using the `vhostsConfigMap` value. This is a pointer to a ConfigMap with the desired Apache virtual host configurations. You can also copy your virtual host configurations under the `files/vhosts/` directory in your current working directory to mount them as a Config Map to the container. ### [Rolling VS Immutable tags](https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/) diff --git a/bitnami/apache/files/README.md b/bitnami/apache/files/README.md new file mode 100644 index 0000000000..97e0581865 --- /dev/null +++ b/bitnami/apache/files/README.md @@ -0,0 +1 @@ +Copy here your `httpd.conf` file to use mount it as a config map. \ No newline at end of file diff --git a/bitnami/apache/files/vhosts/README.md b/bitnami/apache/files/vhosts/README.md new file mode 100644 index 0000000000..584300f784 --- /dev/null +++ b/bitnami/apache/files/vhosts/README.md @@ -0,0 +1 @@ +Copy here your `*.conf` virtual host files to have them mounted to the container as a config map. \ No newline at end of file diff --git a/bitnami/apache/templates/_helpers.tpl b/bitnami/apache/templates/_helpers.tpl index fe02026415..c157c25bd7 100644 --- a/bitnami/apache/templates/_helpers.tpl +++ b/bitnami/apache/templates/_helpers.tpl @@ -195,3 +195,25 @@ Also, we can't use a single if because lazy evaluation is not an option {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} {{- end -}} {{- end -}} + +{{/* +Get the vhosts config map name. +*/}} +{{- define "apache.vhostsConfigMap" -}} +{{- if .Values.vhostsConfigMap -}} + {{- printf "%s" (tpl .Values.vhostsConfigMap $) -}} +{{- else -}} + {{- printf "%s-vhosts" (include "apache.fullname" . ) -}} +{{- end -}} +{{- end -}} + +{{/* +Get the httpd.conf config map name. +*/}} +{{- define "apache.httpdConfConfigMap" -}} +{{- if .Values.httpdConfConfigMap -}} + {{- printf "%s" (tpl .Values.httpdConfConfigMap $) -}} +{{- else -}} + {{- printf "%s-httpd-conf" (include "apache.fullname" . ) -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/bitnami/apache/templates/configmap-vhosts.yaml b/bitnami/apache/templates/configmap-vhosts.yaml new file mode 100644 index 0000000000..9a625f4ac8 --- /dev/null +++ b/bitnami/apache/templates/configmap-vhosts.yaml @@ -0,0 +1,13 @@ +{{- if and (.Files.Glob "files/vhosts/*.conf") (not .Values.vhostsConfigMap) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "apache.fullname" . }}-vhosts + labels: + app.kubernetes.io/name: {{ include "apache.fullname" . }} + helm.sh/chart: {{ include "apache.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +data: +{{ (.Files.Glob "files/vhosts/*.conf").AsConfig | indent 2 }} +{{ end }} \ No newline at end of file diff --git a/bitnami/apache/templates/configmap.yaml b/bitnami/apache/templates/configmap.yaml new file mode 100644 index 0000000000..f6b0ab1e41 --- /dev/null +++ b/bitnami/apache/templates/configmap.yaml @@ -0,0 +1,13 @@ +{{ if and (.Files.Glob "files/httpd.conf") (not .Values.httpdConfConfigMap) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "apache.fullname" . }}-httpd-conf + labels: + app.kubernetes.io/name: {{ include "apache.fullname" . }} + helm.sh/chart: {{ include "apache.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +data: +{{ (.Files.Glob "files/httpd.conf").AsConfig | indent 2 }} +{{ end }} \ No newline at end of file diff --git a/bitnami/apache/templates/deployment.yaml b/bitnami/apache/templates/deployment.yaml index d5ade2bf26..6919b5355c 100644 --- a/bitnami/apache/templates/deployment.yaml +++ b/bitnami/apache/templates/deployment.yaml @@ -102,11 +102,11 @@ spec: - name: htdocs mountPath: /app {{- end }} - {{- if .Values.vhostsConfigMap }} + {{- if or (.Files.Glob "files/vhosts/*.conf") (.Values.vhostsConfigMap) }} - name: vhosts mountPath: /vhosts {{- end }} - {{- if .Values.httpdConfConfigMap }} + {{- if or (.Files.Glob "files/httpd.conf") (.Values.httpdConfConfigMap) }} - name: httpd-conf mountPath: /opt/bitnami/apache/conf/httpd.conf subPath: httpd.conf @@ -138,15 +138,15 @@ spec: - name: htdocs {{- include "apache.htdocsVolume" . | nindent 8 }} {{- end }} - {{- if .Values.vhostsConfigMap }} + {{- if or (.Files.Glob "files/vhosts/*.conf") (.Values.vhostsConfigMap) }} - name: vhosts configMap: - name: {{ .Values.vhostsConfigMap }} + name: {{ include "apache.vhostsConfigMap" . }} {{- end }} - {{- if .Values.httpdConfConfigMap }} + {{- if or (.Files.Glob "files/httpd.conf") (.Values.httpdConfConfigMap) }} - name: httpd-conf configMap: - name: {{ .Values.httpdConfConfigMap }} + name: {{ include "apache.httpdConfConfigMap" . }} {{- end }} {{- with .Values.affinity }} affinity: