Files
Olares/framework/analytics/.olares/config/cluster/deploy/analytics_deploy.yaml
2025-06-23 11:22:31 +08:00

148 lines
3.8 KiB
YAML

{{ $analytics_rootpath := printf "%s%s" .Values.rootPath "/rootfs/analytics" }}
{{- $namespace := printf "%s" "os-framework" -}}
{{- $analytics_secret := (lookup "v1" "Secret" $namespace "analytics-secrets") -}}
{{- $pg_password := "" -}}
{{ if $analytics_secret -}}
{{ $pg_password = (index $analytics_secret "data" "pg_password") }}
{{ else -}}
{{ $pg_password = randAlphaNum 16 | b64enc }}
{{- end -}}
---
apiVersion: v1
kind: Secret
metadata:
name: analytics-secrets
namespace: {{ .Release.Namespace }}
type: Opaque
data:
pg_password: {{ $pg_password }}
---
apiVersion: apr.bytetrade.io/v1alpha1
kind: MiddlewareRequest
metadata:
name: analytics-pg
namespace: {{ .Release.Namespace }}
spec:
app: analytics
appNamespace: {{ .Release.Namespace }}
middleware: postgres
postgreSQL:
user: analytics_os_framework
password:
valueFrom:
secretKeyRef:
key: pg_password
name: analytics-secrets
databases:
- name: analytics
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: analytics-server
namespace: {{ .Release.Namespace }}
labels:
app: analytics-server
applications.app.bytetrade.io/author: bytetrade.io
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: analytics-server
template:
metadata:
labels:
app: analytics-server
spec:
initContainers:
- name: init-container
image: 'postgres:16.0-alpine3.18'
command:
- sh
- '-c'
- >-
echo -e "Checking for the availability of PostgreSQL Server deployment"; until psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDB -c "SELECT 1"; do sleep 1; printf "-"; done; sleep 5; echo -e " >> PostgreSQL DB Server has started";
env:
- name: PGHOST
value: citus-0.citus-headless.os-platform
- name: PGPORT
value: "5432"
- name: PGUSER
value: analytics_os_framework
- name: PGPASSWORD
value: {{ $pg_password | b64dec }}
- name: PGDB
value: os_framework_analytics
containers:
- name: analytics-server
image: beclab/analytics-api:v0.0.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3010
env:
- name: PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING
value: '1'
- name: PL_DATA_BACKEND
value: postgres
- name: PL_DATA_POSTGRES_HOST
value: citus-0.citus-headless.os-platform
- name: PL_DATA_POSTGRES_PORT
value: "5432"
- name: PL_DATA_POSTGRES_DATABASE
value: os_framework_analytics
- name: PL_DATA_POSTGRES_USER
value: analytics_os_framework
- name: PL_DATA_POSTGRES_PASSWORD
value: {{ $pg_password | b64dec }}
- name: DATABASE_URL
value: postgres://$(PL_DATA_POSTGRES_USER):$(PL_DATA_POSTGRES_PASSWORD)@$(PL_DATA_POSTGRES_HOST)/$(PL_DATA_POSTGRES_DATABASE)?sslmode=disable
---
apiVersion: v1
kind: Service
metadata:
name: analytics-server
namespace: {{ .Release.Namespace }}
spec:
type: ClusterIP
selector:
app: analytics-server
ports:
- name: server
protocol: TCP
port: 3010
targetPort: 3010
---
apiVersion: apr.bytetrade.io/v1alpha1
kind: SysEventRegistry
metadata:
name: analytics-user-create-cb
namespace: {{ .Release.Namespace }}
spec:
type: subscriber
event: user.create
callback: http://analytics-server.{{ .Release.Namespace }}:3010/callback/create
---
apiVersion: apr.bytetrade.io/v1alpha1
kind: SysEventRegistry
metadata:
name: analytics-user-delete-cb
namespace: {{ .Release.Namespace }}
spec:
type: subscriber
event: user.delete
callback: http://analytics-server.{{ .Release.Namespace }}:3010/callback/delete