Skip to content

Commit e4bd39e

Browse files
Simplify PgSTAC Bootstrap Process (#208)
* feat: Add PgSTAC settings SQL file and update bootstrap process - Introduced a new SQL file for PgSTAC settings to improve maintainability. - Updated the PgSTAC bootstrap process to utilize Kubernetes jobs for database initialization and sample data loading. - Replaced custom Python script with the pypgstac migrate command for schema initialization. - Enhanced configuration structure for better clarity and control over sample data loading. - Deprecated the legacy environment variable approach in favor of a more structured settings approach. * feat: Add EOAPI Helm Chart README and streamline PgSTAC bootstrap process * feat: Enhance debugging output for failed service boot and test failures in CI workflow * fix: reduce timeout for service boot watch to 2 minutes * feat: update pgstac image name to use pgstac-pypgstac variant * fix: update log extraction for pgstac-migrate pod in CI workflow * fix: update wait command to reference pgstac-migrate job in deployment.yaml * fix: disable continue-on-error for test runner step in CI workflow * fix: enhance pgstac-migrate job monitoring and increase timeout for service boot watch * fix: add log extraction for pgstac-migrate pod in CI workflow * fix: add error handling to pgstac-migrate job script * fix: improve database readiness check and add error handling in pgstac-migrate job * fix: add debugging output for environment variables in pgstac-migrate job * fix: update postgres user privileges and clarify comments in values.yaml * fix: configure Patroni for schema permissions and update PostgreSQL settings * fix: update schema permissions for eoapi user in values.yaml * fix: update PostgreSQL schema privileges for eoapi user in values.yaml * fix: update postgrescluster options to SUPERUSER for enhanced privileges * fix: update database initialization SQL and modify postgrescluster options for enhanced privileges * fix: simplify database initialization SQL configuration in values.yaml * fix: correct database options formatting in values.yaml * fix: add CREATE privilege for eoapi user on public schema in initdb.sql * fix: update privileges for eoapi user in initdb.sql * fix: update initdb.sql to set default privileges for eoapi user * fix: streamline database initialization and add verification in pgstac bootstrap job * fix: enhance database initialization verification in pgstac bootstrap job * fix: enhance search_path verification for PgSTAC functionality in database initialization * fix: improve database initialization verification by checking eoapi role and search_path * fix: ensure immediate exit on command failure in PgSTAC migration script * fix: add database owner assignment and remove redundant initialization verification in pgstac bootstrap job * fix: streamline PgSTAC migration job by removing redundant PostGIS extension registration and permission settings * fix: add debugging steps for pgstac-migrate job failures and allow continuation on error * fix: enhance logging extraction for pgstac-migrate job by implementing multiple pod retrieval methods * fix: update initdb ConfigMap to include role creation and privileges for pgstac * fix: ensure exit status is captured after helm test execution * fix: add initdb ConfigMap for PostgreSQL setup with necessary roles and extensions * fix: update helm render/install step to include an ID for better tracking * fix: update database connection settings in pgstac bootstrap ConfigMap and job for improved flexibility * fix: remove redundant pod log extraction methods for pgstac-migrate * fix: remove debugging environment variable prints and unused initContainer from pgstac-load-samples job * fix: remove unnecessary sleep step from helm-tests workflow
1 parent 0cbb6d7 commit e4bd39e

File tree

11 files changed

+371
-167
lines changed

11 files changed

+371
-167
lines changed

.github/workflows/helm-tests.yml

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ jobs:
7474
oci://registry.developers.crunchydata.com/crunchydata/pgo \
7575
--version ${{ env.PGO_VERSION }}
7676
77-
- name: helm render/install eoapi templates
77+
- id: helm-render-install-eoapi-templates
78+
name: helm render/install eoapi templates
79+
continue-on-error: true
7880
run: |
7981
export GITSHA='${{github.sha}}'
8082
@@ -87,18 +89,53 @@ jobs:
8789
-f ./eoapi/test-k3s-unittest-values.yaml \
8890
./eoapi
8991
90-
- name: sleep for 10s seconds while services boot
91-
shell: bash
92-
run: sleep 10s
92+
exit $?
9393
94-
# - name: Setup upterm session
95-
# uses: lhotari/action-upterm@v1
94+
- name: debug pgstac-migrate job failure
95+
if: steps.helm-render-install-eoapi-templates.outcome == 'failure'
96+
continue-on-error: true
97+
run: |
98+
echo "Extracting pgstac-migrate job info and logs for debugging..."
99+
100+
# Get job details
101+
echo "===== pgstac-migrate Job Details ====="
102+
kubectl get job pgstac-migrate -o yaml || echo "Could not get pgstac-migrate job details"
103+
104+
# Get pod details
105+
echo "===== pgstac-migrate Pod Details ====="
106+
kubectl get pods -l app=pgstac-migrate --all-namespaces || echo "Could not find pgstac-migrate pods"
107+
108+
# Extract logs from pgstac-migrate pod(s)
109+
echo "===== pgstac-migrate Pod Logs ====="
110+
echo "Looking for completed pods from pgstac-migrate job..."
111+
COMPLETED_PODS=$(kubectl get pods --selector=job-name=pgstac-migrate --field-selector=status.phase=Succeeded,status.phase=Failed -o jsonpath='{.items[*].metadata.name}' 2>/dev/null)
112+
if [ -n "$COMPLETED_PODS" ]; then
113+
echo "Found completed pods from pgstac-migrate job. Extracting logs from each:"
114+
for POD in $COMPLETED_PODS; do
115+
echo "--- Logs from completed pod $POD ---"
116+
kubectl logs pod/$POD || echo "Could not get logs from pod $POD"
117+
done
118+
else
119+
echo "No completed pods found for pgstac-migrate job"
120+
fi
121+
122+
# Get details about the database pods/services
123+
echo "===== Database Pod/Service Details ====="
124+
# Find database service
125+
kubectl get svc | grep "db" || echo "Could not find database services"
126+
# Find database pods
127+
kubectl get pods | grep "db-" || echo "Could not find database pods"
128+
129+
# Check for any events related to the job or pods
130+
echo "===== Related Kubernetes Events ====="
131+
kubectl get events | grep -E "pgstac|db" || echo "No relevant events found"
96132
97133
- id: watchservices
98134
name: watch services boot
99-
timeout-minutes: 10
135+
timeout-minutes: 3
100136
continue-on-error: true
101137
run: |
138+
# Now wait for services to boot up
102139
while [[ -z "$(kubectl get pod | grep "^raster-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "GET /.*/healthz" | head -n 1)" ]]; do
103140
echo "still waiting for raster service to start..."
104141
sleep 1
@@ -124,14 +161,6 @@ jobs:
124161
echo "===== Pod Status ====="
125162
kubectl get pods
126163
127-
# Extract logs from database pod
128-
echo "===== Database Pod Logs ====="
129-
kubectl get pod | grep "^db-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get database logs"
130-
131-
# Extract logs from pgstacbootstrap pod
132-
echo "===== PGSTACBootstrap Pod Logs ====="
133-
kubectl get pod | grep "^pgstacbootstrap-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get pgstacbootstrap logs"
134-
135164
# Extract logs from raster pod init container (wait-for-pgstacbootstrap)
136165
echo "===== Raster Pod Init Container Logs (wait-for-pgstacbootstrap) ====="
137166
kubectl get pod | grep "^raster-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} -c wait-for-pgstacbootstrap --tail=100 || echo "Could not get raster init container logs"
@@ -161,7 +190,7 @@ jobs:
161190
162191
- name: run the tests
163192
id: testrunner
164-
continue-on-error: true
193+
# continue-on-error: true
165194
run: |
166195
kubectl get svc --all-namespaces
167196
kubectl get ingress --all-namespaces -o jsonpath='{range .items[0]}kubectl describe ingress {.metadata.name} -n {.metadata.namespace}{end}' | sh
@@ -192,14 +221,6 @@ jobs:
192221
echo "===== Pod Status ====="
193222
kubectl get pods
194223
195-
# Extract logs from database pod
196-
echo "===== Database Pod Logs ====="
197-
kubectl get pod | grep "^db-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get database logs"
198-
199-
# Extract logs from pgstacbootstrap pod
200-
echo "===== PGSTACBootstrap Pod Logs ====="
201-
kubectl get pod | grep "^pgstacbootstrap-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} --tail=100 || echo "Could not get pgstacbootstrap logs"
202-
203224
# Extract logs from raster pod init container (wait-for-pgstacbootstrap)
204225
echo "===== Raster Pod Init Container Logs (wait-for-pgstacbootstrap) ====="
205226
kubectl get pod | grep "^raster-$RELEASE_NAME" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} -c wait-for-pgstacbootstrap --tail=100 || echo "Could not get raster init container logs"
@@ -225,4 +246,4 @@ jobs:
225246
226247
- name: helm uninstall eoapi templates
227248
run: |
228-
helm uninstall $RELEASE_NAME
249+
helm uninstall $RELEASE_NAME

helm-chart/eoapi/README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# EOAPI Helm Chart
2+
3+
This Helm chart deploys the EOAPI (Earth Observation API) stack, which includes STAC API, raster tile services, vector tile services, and a multidimensional data service.
4+
5+
## Overview
6+
7+
The chart sets up:
8+
9+
- A PostgreSQL database with PostGIS and PgSTAC extensions
10+
- STAC API service for metadata discovery and search
11+
- Titiler for raster tile services
12+
- TIPG for vector tile services
13+
- Optional multidimensional data service
14+
15+
## Prerequisites
16+
17+
- Kubernetes 1.16+
18+
- Helm 3.0+
19+
- PV provisioner support in the underlying infrastructure
20+
- CrunchyData Postgres Operator (for the PostgreSQL database)
21+
22+
## Installation
23+
24+
```bash
25+
# Install Postgres Operator first
26+
helm install --set disable_check_for_upgrades=true pgo oci://registry.developers.crunchydata.com/crunchydata/pgo
27+
28+
# Then install eoapi
29+
helm install eoapi ./eoapi
30+
```
31+
32+
## Configuration
33+
34+
The chart can be configured via `values.yaml`. See the chart's `values.yaml` file for all available options and detailed descriptions.
35+
36+
Key configuration sections:
37+
38+
```yaml
39+
# Services to enable
40+
apiServices:
41+
- raster
42+
- stac
43+
- vector
44+
# - multidim (disabled by default)
45+
46+
# Ingress configuration
47+
ingress:
48+
enabled: true
49+
className: "nginx"
50+
# ...
51+
52+
# Database configuration
53+
postgrescluster:
54+
enabled: true
55+
# ...
56+
```
57+
58+
## PgSTAC Bootstrap Process
59+
60+
The chart includes a streamlined process for initializing and setting up the PgSTAC database.
61+
62+
### PgSTAC Bootstrap Overview
63+
64+
The setup process consists of two main jobs:
65+
66+
1. **pgstac-migrate job**: Runs the pypgstac migrate command to initialize the database schema, applies settings, and sets necessary permissions.
67+
2. **pgstac-load-samples job**: (Optional) Loads sample STAC data only when sample loading is enabled.
68+
69+
### Improvements in PgSTAC Bootstrap
70+
71+
- Replaced custom Python script with pypgstac migrate command
72+
- Moved SQL settings to a dedicated SQL file for better maintainability
73+
- Separated sample data loading into an optional job
74+
- Uses standard PostgreSQL environment variables
75+
- Ensures the process remains idempotent for safe re-runs
76+
77+
### PgSTAC Directory Structure
78+
79+
The codebase has been reorganized to separate different types of files:
80+
81+
- `initdb-data/settings/`: Contains configuration settings like the PgSTAC settings SQL file
82+
- `initdb-data/samples/`: Contains sample data files that are loaded only when sample loading is enabled
83+
84+
### PgSTAC Configuration
85+
86+
- Enable/disable the setup process through `pgstacBootstrap.enabled`
87+
- Control sample data loading:
88+
- New approach: `pgstacBootstrap.settings.loadSamples` (recommended)
89+
- Legacy approach: `pgstacBootstrap.settings.envVars.LOAD_FIXTURES` (deprecated)
90+
91+
Example configuration:
92+
93+
```yaml
94+
pgstacBootstrap:
95+
enabled: true
96+
settings:
97+
# General configuration options
98+
loadSamples: true # Set to false to disable sample data loading
99+
100+
resources:
101+
requests:
102+
cpu: "512m"
103+
memory: "1024Mi"
104+
limits:
105+
cpu: "512m"
106+
memory: "1024Mi"
107+
```
108+
109+
## Services
110+
111+
### STAC API
112+
113+
The STAC API service provides a standardized way to search and discover geospatial data.
114+
115+
### Raster Services (Titiler)
116+
117+
Provides dynamic tiling for raster data through the TiTiler implementation.
118+
119+
### Vector Services (TIPG)
120+
121+
Provides vector tile services for PostGIS data through the TIPG implementation.
122+
123+
### Multidimensional Services (Optional)
124+
125+
Provides services for multidimensional data (time series, etc.).
126+
127+
## Persistence
128+
129+
The chart uses PostgreSQL for data persistence. Make sure to configure appropriate storage for production use.
130+
131+
## Upgrading
132+
133+
When upgrading the chart, consider any changes to values.yaml and migrations that might need to be applied.
134+
135+
## Uninstallation
136+
137+
```bash
138+
helm delete eoapi
139+
```
140+
141+
Note that PVs may need to be manually deleted if you want to remove all data.

helm-chart/eoapi/initdb-data/pgstac-setup.py

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Apply pgstac settings
2+
DELETE FROM pgstac.pgstac_settings WHERE name = 'context';
3+
INSERT INTO pgstac.pgstac_settings (name, value) VALUES ('context', 'auto');
4+
5+
DELETE FROM pgstac.pgstac_settings WHERE name = 'context_estimated_count';
6+
INSERT INTO pgstac.pgstac_settings (name, value) VALUES ('context_estimated_count', '100000');
7+
8+
DELETE FROM pgstac.pgstac_settings WHERE name = 'context_estimated_cost';
9+
INSERT INTO pgstac.pgstac_settings (name, value) VALUES ('context_estimated_cost', '100000');
10+
11+
DELETE FROM pgstac.pgstac_settings WHERE name = 'context_stats_ttl';
12+
INSERT INTO pgstac.pgstac_settings (name, value) VALUES ('context_stats_ttl', '1 day');

helm-chart/eoapi/templates/db/configmap.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{{- if .Values.db.enabled }}
2-
---
32
apiVersion: v1
43
kind: ConfigMap
54
metadata:

0 commit comments

Comments
 (0)