Skip to content

Commit

Permalink
Merge pull request #100 from terrestris/create-geofence-db
Browse files Browse the repository at this point in the history
feat: create geofence db in case it does not yet exist
  • Loading branch information
buehner authored Oct 15, 2024
2 parents 37505d2 + f02ba98 commit 9ae8222
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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: 5.0.0
version: 6.0.0
appVersion: 2.26.0
4 changes: 3 additions & 1 deletion charts/geoserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ The following parameters can be configured in (a custom) `values.yaml`:
* `persistence.useExisting`: Should an existing pvc (persistent volume claim) be used, default: `false`
* `persistence.existingPvcName`: The name of an existing pvc (persistent volume claim) that should be used to store geoserver data
* `geofence.enableInitScript`: A flag to control whether a init script for geofence should run or not. default: `false`.
* `geofence.dataSourceUrl`: This will only be used if `geofence.enableInitScript` is `true`. Have a look at the `values.yaml` for an example value.
* `geofence.databaseHost`: This will only be used if `geofence.enableInitScript` is `true`. The host of a postgis database. default: `shogun-postgis`
* `geofence.databasePort`: This will only be used if `geofence.enableInitScript` is `true`. The port of a postgis database. default: `5432`
* `geofence.databaseName`: This will only be used if `geofence.enableInitScript` is `true`. The name of the database in the postgis database. default: `geofence`
* `geofence.env`: This will only be used if `geofence.enableInitScript` is `true`. Have a look at the `values.yaml` for an example value.
* `monitoring.enableInitScript`: A flag to control whether a init script for the gs monitoring extension should run or not. default: `false`.
* `monitoring.filterProperties`: The file content of the [filter.properties](https://docs.geoserver.org/stable/en/user/extensions/monitoring/configuration.html) used by the monitoring extension. This will only be used if `monitoring.enableInitScript` is `true`. default: see `values.yaml`
Expand Down
6 changes: 5 additions & 1 deletion charts/geoserver/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ data:
cat > {{ .Values.storage.dataDir }}/geofence/geofence-datasource-ovr.properties << EOL
geofenceVendorAdapter.databasePlatform=org.hibernatespatial.postgis.PostgisDialect
geofenceDataSource.driverClassName=org.postgresql.Driver
geofenceDataSource.url={{ .Values.geofence.dataSourceUrl }}
geofenceDataSource.url=jdbc:postgresql://{{ .Values.geofence.databaseHost }}:{{ .Values.geofence.databasePort }}/{{ .Values.geofence.databaseName }}
geofenceDataSource.username=${GEOFENCE_DB_USER}
geofenceDataSource.password=${GEOFENCE_DB_PASSWORD}
geofenceEntityManagerFactory.jpaPropertyMap[hibernate.default_schema]=public
geofenceEntityManagerFactory.jpaPropertyMap[hibernate.hbm2ddl.auto]=update
EOL
until pg_isready -h '{{ .Values.geofence.databaseHost }}' -p {{ .Values.geofence.databasePort }};
do echo waiting for database; sleep 2; done;
echo "Creating geofence database now (if it does not yet exist)"
echo "SELECT 'CREATE DATABASE {{ .Values.geofence.databaseName }}' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '{{ .Values.geofence.databaseName }}')\gexec" | PGPASSWORD="${GEOFENCE_DB_PASSWORD}" psql -h '{{ .Values.geofence.databaseHost }}' -p {{ .Values.geofence.databasePort }} -U ${GEOFENCE_DB_USER}
{{- end}}
{{- if .Values.monitoring.enableInitScript }}
init-monitoring.sh: |-
Expand Down
2 changes: 1 addition & 1 deletion charts/geoserver/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
{{- end }}
{{- if .Values.geofence.enableInitScript }}
- name: init-geofence
image: docker.terrestris.de/alpine
image: docker.terrestris.de/postgis/postgis:16-3.4-alpine
command: [ "/bin/sh","/mnt/init-geofence.sh" ]
volumeMounts:
- name: init-geofence-volume
Expand Down
4 changes: 3 additions & 1 deletion charts/geoserver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ probes:

geofence:
enableInitScript: false
dataSourceUrl: jdbc:postgresql://shogun-postgis:5432/geofence
databaseHost: shogun-postgis
databasePort: 5432
databaseName: geofence
env: |
- name: GEOFENCE_DB_USER
value: shogun
Expand Down

0 comments on commit 9ae8222

Please sign in to comment.