Skip to content

Commit 82f2c56

Browse files
committed
feat: added helm charts
1 parent 1fde89c commit 82f2c56

File tree

11 files changed

+355
-4
lines changed

11 files changed

+355
-4
lines changed

app/routers/health.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from app.database.db import get_db
66
from app.database.models.processing_job import ProcessingJobRecord
7+
from fastapi.responses import JSONResponse
8+
from fastapi import status as http_status
79

810
router = APIRouter()
911

@@ -31,7 +33,17 @@ def check_db_status(db: Session) -> dict:
3133

3234
@router.get("/health")
3335
async def health(db: Session = Depends(get_db)):
34-
return {
35-
"status": "ok",
36-
"database": check_db_status(db),
37-
}
36+
db_status = check_db_status(db)
37+
general_status = "ok" if db_status["status"] == "ok" else "error"
38+
status_code = (
39+
http_status.HTTP_200_OK
40+
if general_status == "ok"
41+
else http_status.HTTP_503_SERVICE_UNAVAILABLE
42+
)
43+
return JSONResponse(
44+
status_code=status_code,
45+
content={
46+
"status": general_status,
47+
"database": db_status,
48+
},
49+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: apex-dispatch-api
3+
description: APEx Dispatch API
4+
type: application
5+
version: 0.1.0
6+
appVersion: "latest"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "apex-dispatch-api.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "apex-dispatch-api.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "apex-dispatch-api.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "apex-dispatch-api.labels" -}}
37+
helm.sh/chart: {{ include "apex-dispatch-api.chart" . }}
38+
{{ include "apex-dispatch-api.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "apex-dispatch-api.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "apex-dispatch-api.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "apex-dispatch-api.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "apex-dispatch-api.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "apex-dispatch-api.fullname" . }}-config
5+
data:
6+
APP_NAME: {{ .Values.app.name | quote }}
7+
APP_ENV: {{ .Values.app.environment | quote }}
8+
CORS_ALLOWED_ORIGINS: {{ .Values.app.corsAllowedOrigins | quote }}
9+
KEYCLOAK_HOST: {{ .Values.keycloak.host | quote }}
10+
KEYCLOAK_REALM: {{ .Values.keycloak.realm | quote }}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "apex-dispatch-api.fullname" . }}
5+
spec:
6+
replicas: {{ .Values.replicaCount }}
7+
selector:
8+
matchLabels:
9+
app.kubernetes.io/name: {{ include "apex-dispatch-api.name" . }}
10+
app.kubernetes.io/instance: {{ .Release.Name }}
11+
template:
12+
metadata:
13+
labels:
14+
app.kubernetes.io/name: {{ include "apex-dispatch-api.name" . }}
15+
app.kubernetes.io/instance: {{ .Release.Name }}
16+
spec:
17+
containers:
18+
- name: apex-dispatch-api
19+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
20+
imagePullPolicy: {{ .Values.image.pullPolicy }}
21+
ports:
22+
- containerPort: {{ .Values.service.targetPort }}
23+
envFrom:
24+
- configMapRef:
25+
name: {{ include "apex-dispatch-api.fullname" . }}-config
26+
env:
27+
- name: KEYCLOAK_CLIENT_ID
28+
valueFrom:
29+
secretKeyRef:
30+
name: {{ .Values.secrets.name }}
31+
key: KEYCLOAK_CLIENT_ID
32+
- name: KEYCLOAK_CLIENT_SECRET
33+
valueFrom:
34+
secretKeyRef:
35+
name: {{ .Values.secrets.name }}
36+
key: KEYCLOAK_CLIENT_SECRET
37+
- name: DATABASE_URL
38+
valueFrom:
39+
secretKeyRef:
40+
name: {{ .Values.secrets.name }}
41+
key: DATABASE_URL
42+
- name: OPENEO_BACKENDS
43+
valueFrom:
44+
secretKeyRef:
45+
name: {{ .Values.secrets.name }}
46+
key: OPENEO_BACKENDS
47+
readinessProbe:
48+
httpGet:
49+
path: /health
50+
port: {{ .Values.service.targetPort }}
51+
initialDelaySeconds: 5
52+
periodSeconds: 10
53+
livenessProbe:
54+
httpGet:
55+
path: /health
56+
port: {{ .Values.service.targetPort }}
57+
initialDelaySeconds: 10
58+
periodSeconds: 20
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if .Values.ingress.enabled }}
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: {{ include "apex-dispatch-api.fullname" . }}-ingress
6+
labels:
7+
app.kubernetes.io/name: {{ include "apex-dispatch-api.name" . }}
8+
app.kubernetes.io/instance: {{ .Release.Name }}
9+
annotations:
10+
{{ toYaml .Values.ingress.annotations | indent 4 }}
11+
spec:
12+
{{- if .Values.ingress.tls }}
13+
tls:
14+
{{- range .Values.ingress.tls }}
15+
- hosts: {{ toYaml .hosts | trim | indent 8 }}
16+
secretName: {{ .secretName }}
17+
{{- end }}
18+
{{- end }}
19+
rules:
20+
{{- range .Values.ingress.hosts }}
21+
- host: {{ .host }}
22+
http:
23+
paths:
24+
{{- range .paths }}
25+
- path: {{ .path | default "/" }}
26+
pathType: {{ .pathType | default "Prefix" }}
27+
backend:
28+
service:
29+
name: {{ include "apex-dispatch-api.fullname" $ }}
30+
port:
31+
number: {{ $.Values.service.port }}
32+
{{- end }}
33+
{{- end }}
34+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if .Values.secrets.create }}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: {{ .Values.secrets.name }}
6+
labels:
7+
app.kubernetes.io/name: {{ include "apex-dispatch-api.name" . }}
8+
app.kubernetes.io/instance: {{ .Release.Name }}
9+
type: Opaque
10+
stringData:
11+
KEYCLOAK_CLIENT_ID: {{ .Values.secrets.KEYCLOAK_CLIENT_ID | quote }}
12+
KEYCLOAK_CLIENT_SECRET: {{ .Values.secrets.KEYCLOAK_CLIENT_SECRET | quote }}
13+
DATABASE_URL: {{ .Values.secrets.DATABASE_URL | quote }}
14+
OPENEO_BACKENDS: {{ .Values.secrets.OPENEO_BACKENDS | quote }}
15+
{{- end }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "apex-dispatch-api.fullname" . }}
5+
spec:
6+
type: {{ .Values.service.type }}
7+
ports:
8+
- port: {{ .Values.service.port }}
9+
targetPort: {{ .Values.service.targetPort }}
10+
protocol: TCP
11+
name: http
12+
selector:
13+
app.kubernetes.io/name: {{ include "apex-dispatch-api.name" . }}
14+
app.kubernetes.io/instance: {{ .Release.Name }}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
replicaCount: 1
2+
3+
image:
4+
repository: apex-dispatch-api
5+
tag: latest
6+
pullPolicy: IfNotPresent
7+
8+
service:
9+
type: ClusterIP
10+
port: 8000
11+
targetPort: 8000
12+
13+
ingress:
14+
enabled: true
15+
annotations: {}
16+
hosts:
17+
- host: apex-dispatch-api.local
18+
paths:
19+
- path: /
20+
pathType: Prefix
21+
tls: []
22+
23+
app:
24+
name: "APEx Dispatch API"
25+
environment: "development"
26+
corsAllowedOrigins: "*"
27+
28+
keycloak:
29+
host: "auth.dev.apex.esa.int"
30+
realm: "apex"
31+
32+
secrets:
33+
create: false
34+
name: apex-dispatch-api-secrets
35+
KEYCLOAK_CLIENT_ID: ""
36+
KEYCLOAK_CLIENT_SECRET: ""
37+
DATABASE_URL: ""
38+
OPENEO_BACKENDS: ""
39+
40+
nodeSelector: {}
41+
42+
tolerations: []
43+
44+
affinity: {}

0 commit comments

Comments
 (0)