Skip to content

Commit e27bcd5

Browse files
committed
Initial attempt at helm chart
1 parent 56af26d commit e27bcd5

20 files changed

+3023
-0
lines changed

.github/ct-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Configuration for chart-testing
2+
chart-dirs:
3+
- helm-chart
4+
5+
chart-repos:
6+
- elastic=https://helm.elastic.co
7+
- opensearch=https://opensearch-project.github.io/helm-charts/
8+
9+
helm-extra-args: --timeout 10m
10+
11+
validate-maintainers: false

.github/workflows/helm-chart.yml

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
name: Helm Chart CI
2+
3+
on:
4+
push:
5+
paths:
6+
- 'helm-chart/**'
7+
- '.github/workflows/helm-chart.yml'
8+
pull_request:
9+
paths:
10+
- 'helm-chart/**'
11+
- '.github/workflows/helm-chart.yml'
12+
13+
env:
14+
HELM_VERSION: v3.13.0
15+
KUBECTL_VERSION: v1.28.0
16+
17+
jobs:
18+
lint-and-test:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
backend: [elasticsearch, opensearch]
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up Helm
31+
uses: azure/setup-helm@v3
32+
with:
33+
version: ${{ env.HELM_VERSION }}
34+
35+
- name: Set up kubectl
36+
uses: azure/setup-kubectl@v3
37+
with:
38+
version: ${{ env.KUBECTL_VERSION }}
39+
40+
- name: Set up Python
41+
uses: actions/setup-python@v4
42+
with:
43+
python-version: '3.11'
44+
45+
- name: Set up chart-testing
46+
uses: helm/[email protected]
47+
48+
- name: Add Helm repositories
49+
run: |
50+
helm repo add elastic https://helm.elastic.co
51+
helm repo add opensearch https://opensearch-project.github.io/helm-charts/
52+
helm repo update
53+
54+
- name: Lint Helm chart
55+
run: |
56+
cd helm-chart/stac-fastapi
57+
helm dependency update
58+
helm lint .
59+
60+
- name: Template Helm chart
61+
run: |
62+
cd helm-chart/stac-fastapi
63+
helm template test-release . \
64+
--set backend=${{ matrix.backend }} \
65+
--set ${{ matrix.backend }}.enabled=true \
66+
--set app.image.tag=latest \
67+
--output-dir /tmp/helm-test-${{ matrix.backend }}
68+
69+
- name: Validate templated manifests
70+
run: |
71+
# Check that all required resources are created
72+
ls -la /tmp/helm-test-${{ matrix.backend }}/stac-fastapi/templates/
73+
74+
# Validate YAML syntax
75+
find /tmp/helm-test-${{ matrix.backend }} -name "*.yaml" -exec kubectl apply --dry-run=client -f {} \;
76+
77+
- name: Run chart-testing (lint)
78+
run: |
79+
ct lint --config .github/ct-config.yaml --charts helm-chart/stac-fastapi
80+
81+
integration-test:
82+
runs-on: ubuntu-latest
83+
needs: lint-and-test
84+
strategy:
85+
matrix:
86+
backend: [elasticsearch, opensearch]
87+
k8s-version: ['1.26.6', '1.27.3', '1.28.0']
88+
89+
steps:
90+
- name: Checkout
91+
uses: actions/checkout@v4
92+
with:
93+
fetch-depth: 0
94+
95+
- name: Set up Helm
96+
uses: azure/setup-helm@v3
97+
with:
98+
version: ${{ env.HELM_VERSION }}
99+
100+
- name: Set up kubectl
101+
uses: azure/setup-kubectl@v3
102+
with:
103+
version: ${{ env.KUBECTL_VERSION }}
104+
105+
- name: Create kind cluster
106+
uses: helm/[email protected]
107+
with:
108+
node_image: kindest/node:v${{ matrix.k8s-version }}
109+
cluster_name: kind
110+
config: |
111+
kind: Cluster
112+
apiVersion: kind.x-k8s.io/v1alpha4
113+
nodes:
114+
- role: control-plane
115+
kubeadmConfigPatches:
116+
- |
117+
kind: InitConfiguration
118+
nodeRegistration:
119+
kubeletExtraArgs:
120+
node-labels: "ingress-ready=true"
121+
extraPortMappings:
122+
- containerPort: 80
123+
hostPort: 80
124+
protocol: TCP
125+
- containerPort: 443
126+
hostPort: 443
127+
protocol: TCP
128+
129+
- name: Add Helm repositories
130+
run: |
131+
helm repo add elastic https://helm.elastic.co
132+
helm repo add opensearch https://opensearch-project.github.io/helm-charts/
133+
helm repo update
134+
135+
- name: Install STAC FastAPI chart
136+
run: |
137+
cd helm-chart/stac-fastapi
138+
helm dependency update
139+
140+
# Install with specific backend
141+
helm install stac-fastapi-test . \
142+
--namespace stac-fastapi \
143+
--create-namespace \
144+
--set backend=${{ matrix.backend }} \
145+
--set ${{ matrix.backend }}.enabled=true \
146+
--set app.image.tag=latest \
147+
--set app.service.type=ClusterIP \
148+
--wait \
149+
--timeout=10m
150+
151+
- name: Wait for deployment
152+
run: |
153+
kubectl wait --for=condition=ready pod \
154+
-l "app.kubernetes.io/name=stac-fastapi" \
155+
-n stac-fastapi \
156+
--timeout=300s
157+
158+
- name: Check deployment status
159+
run: |
160+
kubectl get all -n stac-fastapi
161+
helm status stac-fastapi-test -n stac-fastapi
162+
163+
- name: Test API endpoints
164+
run: |
165+
# Port forward to the service
166+
kubectl port-forward -n stac-fastapi service/stac-fastapi-test 8080:80 &
167+
sleep 10
168+
169+
# Test root endpoint
170+
curl -f http://localhost:8080/ || exit 1
171+
172+
# Test collections endpoint
173+
curl -f http://localhost:8080/collections || exit 1
174+
175+
# Test search endpoint
176+
curl -f -X POST http://localhost:8080/search \
177+
-H "Content-Type: application/json" \
178+
-d '{}' || exit 1
179+
180+
echo "All API endpoints are working!"
181+
182+
- name: Test database connectivity
183+
run: |
184+
# Check if database is responding
185+
DB_SERVICE=$(kubectl get svc -n stac-fastapi -l "app=stac-fastapi-test-${{ matrix.backend }}-master" -o jsonpath="{.items[0].metadata.name}" || echo "")
186+
187+
if [[ -n "$DB_SERVICE" ]]; then
188+
kubectl port-forward -n stac-fastapi service/$DB_SERVICE 9200:9200 &
189+
sleep 5
190+
curl -f http://localhost:9200/_health || echo "Database health check failed"
191+
else
192+
echo "Database service not found or using external database"
193+
fi
194+
195+
- name: Load test data
196+
run: |
197+
# Port forward to the API service
198+
kubectl port-forward -n stac-fastapi service/stac-fastapi-test 8080:80 &
199+
sleep 5
200+
201+
# Create test collection
202+
curl -X POST http://localhost:8080/collections \
203+
-H "Content-Type: application/json" \
204+
-d '{
205+
"id": "test-collection",
206+
"title": "Test Collection",
207+
"description": "A test collection",
208+
"extent": {
209+
"spatial": {"bbox": [[-180, -90, 180, 90]]},
210+
"temporal": {"interval": [["2020-01-01T00:00:00Z", "2024-12-31T23:59:59Z"]]}
211+
},
212+
"license": "public-domain"
213+
}' || echo "Collection creation failed"
214+
215+
# Create test item
216+
curl -X POST http://localhost:8080/collections/test-collection/items \
217+
-H "Content-Type: application/json" \
218+
-d '{
219+
"id": "test-item",
220+
"type": "Feature",
221+
"stac_version": "1.0.0",
222+
"collection": "test-collection",
223+
"geometry": {
224+
"type": "Polygon",
225+
"coordinates": [[[-1, -1], [1, -1], [1, 1], [-1, 1], [-1, -1]]]
226+
},
227+
"bbox": [-1, -1, 1, 1],
228+
"properties": {"datetime": "2023-06-15T12:00:00Z"},
229+
"assets": {
230+
"thumbnail": {
231+
"href": "https://example.com/thumbnail.jpg",
232+
"type": "image/jpeg"
233+
}
234+
}
235+
}' || echo "Item creation failed"
236+
237+
# Test search
238+
sleep 5 # Allow time for indexing
239+
RESULT=$(curl -s -X POST http://localhost:8080/search \
240+
-H "Content-Type: application/json" \
241+
-d '{"collections": ["test-collection"]}')
242+
243+
echo "Search result: $RESULT"
244+
245+
- name: Cleanup
246+
if: always()
247+
run: |
248+
helm uninstall stac-fastapi-test -n stac-fastapi || true
249+
kubectl delete namespace stac-fastapi || true
250+
251+
security-scan:
252+
runs-on: ubuntu-latest
253+
needs: lint-and-test
254+
255+
steps:
256+
- name: Checkout
257+
uses: actions/checkout@v4
258+
259+
- name: Set up Helm
260+
uses: azure/setup-helm@v3
261+
with:
262+
version: ${{ env.HELM_VERSION }}
263+
264+
- name: Add Helm repositories
265+
run: |
266+
helm repo add elastic https://helm.elastic.co
267+
helm repo add opensearch https://opensearch-project.github.io/helm-charts/
268+
helm repo update
269+
270+
- name: Template chart for security scan
271+
run: |
272+
cd helm-chart/stac-fastapi
273+
helm dependency update
274+
helm template security-scan . \
275+
--set backend=elasticsearch \
276+
--set elasticsearch.enabled=true \
277+
--output-dir /tmp/security-scan
278+
279+
- name: Run Checkov security scan
280+
uses: bridgecrewio/checkov-action@master
281+
with:
282+
directory: /tmp/security-scan
283+
framework: kubernetes
284+
soft_fail: true
285+
output_format: sarif
286+
output_file_path: checkov-results.sarif
287+
288+
- name: Upload Checkov results
289+
uses: github/codeql-action/upload-sarif@v2
290+
if: always()
291+
with:
292+
sarif_file: checkov-results.sarif

0 commit comments

Comments
 (0)