Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 43 additions & 33 deletions .github/workflows/helm-tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: CI


# On every pull request, but only on push to main
on:
push:
Expand Down Expand Up @@ -35,16 +36,25 @@ jobs:

- uses: azure/setup-helm@v3
with:
helm-version: v3.8.2
github-token: ${{ secrets.GITHUB_TOKEN }}
version: v3.8.2
token: ${{ secrets.GITHUB_TOKEN }}

- name: last commit sha if PR
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> ${GITHUB_ENV}

- name: last commit sha if push
if: ${{ github.event_name == 'push' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=${GITHUB_SHA}" >> ${GITHUB_ENV}

- name: set k8s namespace name for parallel tests
- name: set k8s .release.name suffix
run: |
random_number="${RANDOM}${RANDOM}${RANDOM}"
# Limit it to 10 digits
RANDOMNESS=$(echo $random_number | cut -c 1-10)
#echo "NS_NAME=unittest-$RANDOMNESS" >> $GITHUB_ENV
echo "NS_NAME=eoapitest" >> $GITHUB_ENV
RANDOMNESS=$(echo $LAST_COMMIT_SHA | cut -c 1-6)
echo "RELEASE_NAME=eoapi$RANDOMNESS" >> $GITHUB_ENV

- id: 'auth'
uses: 'google-github-actions/auth@v1'
Expand All @@ -57,8 +67,6 @@ jobs:
with:
version: '>= 363.0.0'
project_id: 'devseed-labs'
service_account_key: ${{ secrets.GH_ACTIONS_SA_TOKEN }}
export_default_credentials: true

- name: configure kubectl context
run: |
Expand All @@ -75,37 +83,38 @@ jobs:

cd helm-chart

helm install \
--namespace $NS_NAME \
--create-namespace \
--set gitSha=$GITSHA \
--set db.settings.secrets.PGUSER=$PGUSER \
--set db.settings.secrets.POSTGRES_USER=$POSTGRES_USER \
--set db.settings.secrets.PGPASSWORD=$PGPASSWORD \
--set db.settings.secrets.POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-f ./eoapi/values.yaml \
-f ./eoapi/test-unittest-values.yaml \
eoapi \
./eoapi
helm install $RELEASE_NAME \
--namespace eoapitest \
--create-namespace \
--set db.settings.secrets.POSTGRES_HOST=pgstac-$RELEASE_NAME \
--set db.settings.secrets.POSTGRES_HOST_READER=pgstac-$RELEASE_NAME \
--set db.settings.secrets.POSTGRES_HOST_WRITER=pgstac-$RELEASE_NAME \
--set db.settings.secrets.PGUSER=$PGUSER \
--set db.settings.secrets.POSTGRES_USER=$POSTGRES_USER \
--set db.settings.secrets.PGPASSWORD=$PGPASSWORD \
--set db.settings.secrets.POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-f ./eoapi/values.yaml \
-f ./eoapi/test-unittest-values.yaml \
./eoapi

- name: sleep for 10s seconds while services boot
shell: bash
run: sleep 10s

- name: restart the services
run: |
kubectl config set-context --current --namespace=$NS_NAME
while [[ -z "$(kubectl get pod | grep '^raster-.*$' | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "startup complete" | head -n 1)" ]]; do
kubectl config set-context --current --namespace=eoapitest
while [[ -z "$(kubectl get pod | grep "^raster-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "startup complete" | head -n 1)" ]]; do
echo "still waiting for raster service to start..."
sleep 1
done
echo "raster service has started, moving on..."
while [[ -z "$(kubectl get pod | grep '^vector-.*$' | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "startup complete" | head -n 1)" ]]; do
while [[ -z "$(kubectl get pod | grep "^vector-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "startup complete" | head -n 1)" ]]; do
echo "still waiting for vector service to start..."
sleep 1
done
echo "vector service has started, moving on..."
while [[ -z "$(kubectl get pod | grep '^stac-.*$' | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "startup complete" | head -n 1)" ]]; do
while [[ -z "$(kubectl get pod | grep "^stac-$RELEASE_NAME-.*$" | cut -d' ' -f1 | xargs -I{} kubectl logs pod/{} | grep "startup complete" | head -n 1)" ]]; do
echo "still waiting for stac service to start..."
sleep 1
done
Expand All @@ -120,27 +129,28 @@ jobs:

- name: run the tests
run: |
kubectl config set-context --current --namespace=$NS_NAME
kubectl config set-context --current --namespace=eoapitest
PUBLICIP='http://'$(kubectl -n ingress-nginx get svc/ingress-nginx-controller -o jsonpath='{.spec.loadBalancerIP}')
echo '#################################'
echo $PUBLICIP
echo vector=$PUBLICIP/vector$RELEASE_NAME
echo stac=$PUBLICIP/stac$RELEASE_NAME
echo raster=$PUBLICIP/raster$RELEASE_NAME
echo '#################################'

# first substitute test endpoints in the test files
# TODO: pytest should be able to have a pattern for injection here but moving fast
sed -i "s|vector_endpoint\=.*$|vector_endpoint\='$PUBLICIP/vector'|g" .github/workflows/tests/test_vector.py
sed -i "s|vector_endpoint\=.*$|vector_endpoint\='$PUBLICIP/vector$RELEASE_NAME'|g" .github/workflows/tests/test_vector.py
head -n 5 .github/workflows/tests/test_vector.py
pytest .github/workflows/tests/test_vector.py

sed -i "s|stac_endpoint\=.*$|stac_endpoint\='$PUBLICIP/stac'|g" .github/workflows/tests/test_stac.py
sed -i "s|stac_endpoint\=.*$|stac_endpoint\='$PUBLICIP/stac$RELEASE_NAME'|g" .github/workflows/tests/test_stac.py
head -n 5 .github/workflows/tests/test_stac.py
pytest .github/workflows/tests/test_stac.py

sed -i "s|raster_endpoint\=.*$|raster_endpoint\='$PUBLICIP/raster'|g" .github/workflows/tests/test_raster.py
sed -i "s|raster_endpoint\=.*$|raster_endpoint\='$PUBLICIP/raster$RELEASE_NAME'|g" .github/workflows/tests/test_raster.py
head -n 5 .github/workflows/tests/test_raster.py
pytest .github/workflows/tests/test_raster.py

- name: helm uinstall eoapi templates
run: |
helm uninstall eoapi
kubectl delete ns $NS_NAME
helm uninstall $RELEASE_NAME
5 changes: 5 additions & 0 deletions helm-chart/eoapi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
version numbers below correspond to helm chart `appVersion`: see ./helm-chart/eoapi/Chart.yaml
---
# 0.1.4 (2023-09-09)

* adds a `testing: false` value to `values.yaml`
* plumb through `{{ $.Release.Name }}` into all the right templates so our CI can `helm install` into a single namespace and run tests in parallel

# 0.1.3 (2023-09-05)

* test on GKE and add documentation where needed for [GKE template changes](https://github.com/developmentseed/eoapi-k8s/issues/29)
Expand Down
4 changes: 2 additions & 2 deletions helm-chart/eoapi/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ kubeVersion: ">=1.23.0-0"
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: "0.1.5"
version: "0.1.6"

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.1.3"
appVersion: "0.1.4"
13 changes: 13 additions & 0 deletions helm-chart/eoapi/rm-ci-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# rm deploys (which will remove replicasets and pods)
kubectl get deploy | grep -v NAME | grep $1 | cut -d' ' -f1 | xargs -I{} kubectl delete deploy/{}
# rm svc
kubectl get svc | grep -v NAME | grep $1 | cut -d' ' -f1 | xargs -I{} kubectl delete svc/{}
# rm ingress
kubectl get ingress | grep -v NAME | grep $1 | cut -d' ' -f1 | xargs -I{} kubectl delete ingress/{}
# rm pvc
kubectl get pvc | grep -v NAME | grep $1 | cut -d' ' -f1 | xargs -I{} kubectl delete pvc/{}
# rm secrets
kubectl get secret | grep -v NAME | grep $1 | cut -d' ' -f1 | xargs -I{} kubectl delete secret/{}
# rm configmap
kubectl get configmap | grep -v NAME | grep $1 | cut -d' ' -f1 | xargs -I{} kubectl delete configmap/{}
14 changes: 14 additions & 0 deletions helm-chart/eoapi/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*

Create pgstac host string depending if .Values.testing
*/}}
{{- define "eoapi.pgstacHostName" -}}
{{- if .Values.testing }}
{{- printf "%s-%s" "pgstac" .Release.Name }}
{{- else }}
{{/* need to match what is default in values.yamls */}}
{{- printf "%s" "pgstac" }}
{{- end }}
{{- end }}

6 changes: 3 additions & 3 deletions helm-chart/eoapi/templates/db/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: initdb-sql-config
name: initdb-sql-config-{{ $.Release.Name }}
data:
initdb.sql: |
{{- range $path, $bytes := $.Files.Glob "initdb-data/*.sql" -}}
Expand All @@ -12,7 +12,7 @@ data:
apiVersion: v1
kind: ConfigMap
metadata:
name: initdb-json-config
name: initdb-json-config-{{ $.Release.Name }}
data:
{{- range $path, $bytes := $.Files.Glob "initdb-data/*.json" -}}
{{- base $path | nindent 2 -}}: | {{- $.Files.Get $path | nindent 4 -}}
Expand All @@ -21,7 +21,7 @@ data:
apiVersion: v1
kind: ConfigMap
metadata:
name: initdb-sh-config
name: initdb-sh-config-{{ $.Release.Name }}
data:
load.sh: |
#!/bin/bash
Expand Down
38 changes: 19 additions & 19 deletions helm-chart/eoapi/templates/db/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pgstac
name: {{ include "eoapi.pgstacHostName" . | nindent 8 }}
labels:
app: pgstac
app: {{ include "eoapi.pgstacHostName" . | nindent 10 }}
spec:
selector:
matchLabels:
app: pgstac
app: {{ include "eoapi.pgstacHostName" . | nindent 12 }}
strategy:
type: Recreate
template:
metadata:
labels:
app: pgstac
app: {{ include "eoapi.pgstacHostName" . | nindent 14 }}
spec:
restartPolicy: Always
containers:
Expand All @@ -24,13 +24,13 @@ spec:
{{- toYaml .Values.db.command | nindent 12 }}
envFrom:
- secretRef:
name: pgstac-secrets
name: pgstac-secrets-{{ $.Release.Name }}
ports:
- containerPort: 5432
{{- if not (eq .Values.providerContext "minikube") }}
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: pgstac-claim
name: pgstac-claim-{{ $.Release.Name }}
{{ end }}
{{- if .Values.db.enable_data_fixtures }}
- name: loader
Expand All @@ -41,33 +41,33 @@ spec:
- "/opt/initdb/load.sh"
envFrom:
- secretRef:
name: pgstac-secrets
name: pgstac-secrets-{{ $.Release.Name }}
ports:
- containerPort: 6543
volumeMounts:
{{- if not (eq .Values.providerContext "minikube") }}
- mountPath: /var/lib/postgresql/data
name: pgstac-claim
name: pgstac-claim-{{ $.Release.Name }}
{{ end }}
- mountPath: /opt/initdb/sql-data
name: initdb-sql-volume
name: initdb-sql-volume-{{ $.Release.Name }}
- mountPath: /opt/initdb/json-data
name: initdb-json-volume
name: initdb-json-volume-{{ $.Release.Name }}
- mountPath: /opt/initdb/
name: initdb-sh-volume
name: initdb-sh-volume-{{ $.Release.Name }}
{{- end }}
volumes:
{{- if not (eq .Values.providerContext "minikube") }}
- name: pgstac-claim
- name: pgstac-claim-{{ $.Release.Name }}
persistentVolumeClaim:
claimName: pgstac-claim
claimName: pgstac-claim-{{ $.Release.Name }}
{{- end }}
- name: initdb-sql-volume
- name: initdb-sql-volume-{{ $.Release.Name }}
configMap:
name: initdb-sql-config
- name: initdb-json-volume
name: initdb-sql-config-{{ $.Release.Name }}
- name: initdb-json-volume-{{ $.Release.Name }}
configMap:
name: initdb-json-config
- name: initdb-sh-volume
name: initdb-json-config-{{ $.Release.Name }}
- name: initdb-sh-volume-{{ $.Release.Name }}
configMap:
name: initdb-sh-config
name: initdb-sh-config-{{ $.Release.Name }}
2 changes: 1 addition & 1 deletion helm-chart/eoapi/templates/db/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pgstac-claim
name: pgstac-claim-{{ $.Release.Name }}
spec:
accessModes:
- ReadWriteOnce
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/eoapi/templates/db/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: Secret
metadata:
name: pgstac-secrets
name: pgstac-secrets-{{ $.Release.Name }}
type: "Opaque"
stringData:
{{- range $envKey, $envValue := .Values.db.settings.secrets }}
Expand Down
6 changes: 3 additions & 3 deletions helm-chart/eoapi/templates/db/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apiVersion: v1
kind: Service
metadata:
labels:
app: pgstac
name: pgstac
app: {{ include "eoapi.pgstacHostName" . | nindent 10 }}
name: {{ include "eoapi.pgstacHostName" . | nindent 8 }}
spec:
ports:
- name: "5432"
port: 5432
targetPort: 5432
selector:
app: pgstac
app: {{ include "eoapi.pgstacHostName" . | nindent 10 }}
2 changes: 1 addition & 1 deletion helm-chart/eoapi/templates/services/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $serviceName }}-envvar-configmap
name: {{ $serviceName }}-envvar-configmap-{{ $.Release.Name }}
data:
{{- range $envKey, $envValue := index $v "settings" "envVars" }}
{{ upper $envKey }}: "{{ $envValue }}"
Expand Down
Loading