Skip to content

Commit

Permalink
geoserver init container
Browse files Browse the repository at this point in the history
  • Loading branch information
ahennr committed Apr 11, 2024
1 parent ed65123 commit cf004f0
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 27 deletions.
4 changes: 2 additions & 2 deletions charts/geoserver/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: geoserver
description: Helm chart for GeoServer
icon: https://geoserver.org/img/uploads/geoserver_icon.png
version: 2.1.0
appVersion: 2.24.1
version: 3.0.0
appVersion: 2.24.2
42 changes: 40 additions & 2 deletions charts/geoserver/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
{{- if or .Values.initData.enabled .Values.environment.communityExtensions.names -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "geoserver.fullname" . }}
name: geoserver-init-configmap
labels:
{{ include "geoserver.labels" . | indent 4 }}
data:
init-data.sh: |-
#!/bin/sh
if {{ not .Values.initData.enabled }}; then
exit 0
fi
echo "Checking if geoserver_data is already initialized…"
FILE={{ .Values.storage.dataDir }}/.init
if [ -f "$FILE" ]; then
echo "Directory geoserver_data already initialized."
else
echo "Downloading geoserver_data.tgz …"
CMD="wget -q -O /mnt/download/geoserver_data.tgz '{{ .Values.storage.initDataUrl }}'"
if ([ -z "$DL_USER" ] || [ -z "$DL_PASSWORD" ] || {{ not .Values.initData.credentials.authenticationRequired}} ); then
echo "Downloading without credentials…"
CMD="wget -O /mnt/download/geoserver_data.tgz '{{ .Values.initData.initDataUrl }}'"
else
echo "Downloading with basic auth credentials…"
CMD="wget --user $DL_USER --password $DL_PASSWORD -O /mnt/download/geoserver_data.tgz '{{ .Values.initData.initDataUrl }}'"
fi
echo $CMD
eval $CMD
CMD="cd {{ .Values.storage.dataDir }}"
Expand All @@ -27,3 +37,31 @@ data:
eval $CMD
echo "Successfully extracted geoserver_data directory to '{{ .Values.storage.dataDir }}'!"
fi
init-community-modules.sh: |-
#!/bin/sh
apk update && apk add ca-certificates
echo "Checking if community modules are already loaded…"
FILE={{ .Values.storage.additionalLibsDir }}/.community_modules_loaded
if [ -f "$FILE" ]; then
echo "Community modules already initialized."
else
echo "Downloading community modules …"
for EXTENSION in $(echo "{{ .Values.environment.communityExtensions.names }}" | tr ',' ' '); do
FILE_NAME="geoserver-{{ .Values.environment.communityExtensions.version }}-${EXTENSION}-plugin.zip"
URL="{{ .Values.environment.communityExtensions.baseUrl }}$FILE_NAME"
CMD="wget -c --no-check-certificate $URL -O $FILE_NAME"
echo $CMD
eval $CMD
CMD="unzip -q -o -d '{{ .Values.storage.additionalLibsDir}}' $FILE_NAME '*.jar'"
echo $CMD
eval $CMD
done
CMD="ls {{ .Values.storage.additionalLibsDir }}"
echo $CMD
eval $CMD
CMD="touch $FILE"
echo $CMD
eval $CMD
echo "Successfully installed community modules to '{{ .Values.storage.additionalLibsDir }}'!"
fi
{{- end}}
31 changes: 11 additions & 20 deletions charts/geoserver/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@ spec:
app.kubernetes.io/name: {{ include "geoserver.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
{{- with .Values.imagePullSecrets }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- with .Values.initContainers }}
initContainers:
{{- if and .Values.storage.initDataUrl }}
- name: download-data
image: alpine
command: ["/bin/sh","/mnt/init-data.sh"]
volumeMounts:
- name: temp
mountPath: /mnt/download
- name: init-configmap
mountPath: /mnt/
- name: datadir
mountPath: {{ .Values.storage.dataDir }}
{{- end }}
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand Down Expand Up @@ -75,17 +66,14 @@ spec:
mountPath: {{ .Values.storage.dataDir }}
- name: additional-libs
mountPath: {{ .Values.storage.additionalLibsDir }}
{{- if .Values.extraVolumeMounts }}
{{- toYaml .Values.extraVolumeMounts | nindent 12 }}
{{- end }}
volumes:
- name: temp
emptyDir: {}
- name: additional-libs
emptyDir: {}
- name: init-configmap
configMap:
name: {{ include "geoserver.fullname" . }}
items:
- key: init-data.sh
path: init-data.sh
{{- if and .Values.persistence.enabled (not .Values.persistence.useExisting) }}
- name: datadir
persistentVolumeClaim:
Expand All @@ -98,3 +86,6 @@ spec:
- name: datadir
emptyDir: {}
{{- end }}
{{- if .Values.extraVolumes }}
{{- toYaml .Values.extraVolumes | nindent 8 }}
{{- end }}
50 changes: 47 additions & 3 deletions charts/geoserver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ resources:
limits:
memory: 2500Mi
requests:
cpu: 500m
memory: 1500Mi
memory: 1250Mi

nodeSelector: {}

Expand All @@ -43,14 +42,59 @@ affinity: {}
environment:
installExtensions: false
stableExtensions:
communityExtensions:
names: sec-keycloak
version: 2.24-SNAPSHOT
baseUrl: https://build.geoserver.org/geoserver/2.24.x/community-latest/
# replace example.com with your host
javaOptions: -Xms1g -Xmx2g -DGEOSERVER_CSRF_WHITELIST=localhost,example.com

storage:
dataDir: /opt/geoserver_data
# https://github.com/terrestris/shogun-docker/tree/main/shogun-geoserver/additional_libs
additionalLibsDir: /opt/additional_libs
# initDataUrl: https://files.example.com/geoserver_data.tgz

initData:
enabled: false
initDataUrl: https://files.example.com/geoserver_data.tgz
credentials:
authenticationRequired: false
secretName: my-secret
usernameKey: user
passwordKey: password

# init container config (can be used to add community modules or initial datasets)
initContainers:
- name: init-data-directory
image: docker.terrestris.de/alpine
command: [ "/bin/sh", "/mnt/init-data.sh" ]
volumeMounts:
- name: temp
mountPath: /mnt/download
- name: init-configmap
mountPath: /mnt/
- name: datadir
mountPath: /opt/geoserver_data
- name: init-community-modules
image: docker.terrestris.de/alpine
command: [ "/bin/sh","/mnt/init-community-modules.sh" ]
volumeMounts:
- name: temp
mountPath: /mnt/download
- name: init-configmap
mountPath: /mnt/
- name: additional-libs
mountPath: /opt/additional_libs
extraVolumes:
- name: init-configmap
configMap:
name: geoserver-init-configmap
items:
- key: init-data.sh
path: init-data.sh
- key: init-community-modules.sh
path: init-community-modules.sh
extraVolumeMounts:

# optional existing pvc for persistent geoserver data
persistence:
Expand Down

0 comments on commit cf004f0

Please sign in to comment.