Skip to content

Commit

Permalink
Merge pull request #52 from MadWorldNL/Feature/48-Postgresql
Browse files Browse the repository at this point in the history
Feature: Add Database to save data
  • Loading branch information
oveldman authored Aug 23, 2024
2 parents 5b99c0c + 655bc4a commit 7dc2e84
Show file tree
Hide file tree
Showing 42 changed files with 860 additions and 65 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ Want to see the applications in action? Check out the links below:
## Acknowledgements
I would like to thank the following sources and individuals for their templates, which I used in this application:
- [Bootstrap 5 theme - Elegant](https://themewagon.com/themes/free-bootstrap-5-html-5-admin-dashboard-website-template-elegant/) - Made by: Freebibuges
- [Cloud Native PG](https://cloudnative-pg.io/) - Made by: The CloudNativePG Contributors.

Your work has been incredibly helpful, and I greatly appreciate your contributions and generosity in sharing these resources.
16 changes: 14 additions & 2 deletions deployment/MantaRayPlanCloud/environments/values-production.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace: "manta-ray-plan-production"

image:
tag: "v0.4.6"
tag: "v0.4.7"

clusterIssuer:
enabled: true
Expand All @@ -27,4 +27,16 @@ logging:
enable: true
host:
external: "seq.mad-world.nl"
firstTimePassword: "QFCKH3NTSBQ5zmsH9DpXTB2YefIavEGJKa4SshKb11AXX8b4o4KPjuo9bd6WBfqDkpxKqzNjaOrCsE49ph369Wx84mIrksnJx5OtRcxAOjff"
firstTimePassword: "QFCKH3NTSBQ5zmsH9DpXTB2YefIavEGJKa4SshKb11AXX8b4o4KPjuo9bd6WBfqDkpxKqzNjaOrCsE49ph369Wx84mIrksnJx5OtRcxAOjff"

database:
enabled: true
size:
single: 10Gi
combined: 35Gi

pgadmin:
outsideAccess:
enabled: true
host: "database.mad-world.nl"
username: admin@mad-world.nl
16 changes: 16 additions & 0 deletions deployment/MantaRayPlanCloud/templates/api-grpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ spec:
timeoutSeconds: 1
failureThreshold: 3
env:
- name: Database__Host
value: "postgres-ro"
- name: Database__Port
value: "5432"
- name: Database__DbName
value: "MantaRayPlan"
- name: Database__User
valueFrom:
secretKeyRef:
name: {{ .Values.database.secret.name }}
key: username
- name: Database__Password
valueFrom:
secretKeyRef:
name: {{ .Values.database.secret.name }}
key: password
- name: OpenTelemetry__LoggerEndpoint
value: "{{ .Values.logging.seq.host.internal }}"
- name: OpenTelemetry__LoggerApiKey
Expand Down
16 changes: 16 additions & 0 deletions deployment/MantaRayPlanCloud/templates/api-message-bus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ spec:
timeoutSeconds: 1
failureThreshold: 3
env:
- name: Database__Host
value: "postgres-rw"
- name: Database__Port
value: "5432"
- name: Database__DbName
value: "MantaRayPlan"
- name: Database__User
valueFrom:
secretKeyRef:
name: {{ .Values.database.secret.name }}
key: username
- name: Database__Password
valueFrom:
secretKeyRef:
name: {{ .Values.database.secret.name }}
key: password
- name: OpenTelemetry__LoggerEndpoint
value: "{{ .Values.logging.seq.host.internal }}"
- name: OpenTelemetry__LoggerApiKey
Expand Down
13 changes: 13 additions & 0 deletions deployment/MantaRayPlanCloud/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ spec:
- {{ .Values.viewer.bff.host }}
- {{ .Values.viewer.web.host }}
- {{ .Values.logging.seq.host.external }}
- {{ .Values.pgadmin.host }}
secretName: madworld-tls
{{ end }}
rules:
Expand Down Expand Up @@ -83,4 +84,16 @@ spec:
name: {{ .Values.logging.seq.loadBalancer }}
port:
number: 80
{{ end }}
{{- if .Values.pgadmin.outsideAccess.enabled }}
- host: {{ .Values.pgadmin.host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ .Values.pgadmin.loadBalancer }}
port:
number: 80
{{ end }}
115 changes: 115 additions & 0 deletions deployment/MantaRayPlanCloud/templates/pg-admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{{- $pgadminSecrets := (lookup "v1" "Secret" .Values.namespace .Values.pgadmin.name ) -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.pgadmin.secret.name }}
namespace: {{ .Values.namespace }}
type: kubernetes.io/basic-auth
data:
username: {{ .Values.pgadmin.username | b64enc }}
{{- if and $pgadminSecrets $pgadminSecrets.data }}
{{- if $pgadminSecrets.data.password }}
password: {{ $pgadminSecrets.data.password }}
{{- else }}
password: {{ "nonExistingKey1234" | b64enc }}
{{- end }}
{{- else }}
password: {{ "nonExistingKey1234" | b64enc }}
{{- end }}
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: pgadmin-pv-volume
namespace: {{ .Values.namespace }}
labels:
type: local
app: {{ .Values.pgadmin.app }}
spec:
storageClassName: manual
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
hostPath:
path: "/MantaRayPlan/Pgadmin"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pgadmin-pv-claim
namespace: {{ .Values.namespace }}
labels:
app: {{ .Values.pgadmin.app }}
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.pgadmin.deployment }}
namespace: {{ .Values.namespace }}
labels:
app: {{ .Values.pgadmin.app }}
name: {{ .Values.pgadmin.name }}
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Values.pgadmin.app }}
task: {{ .Values.pgadmin.name }}
template:
metadata:
labels:
app: {{ .Values.pgadmin.app }}
task: {{ .Values.pgadmin.name }}
spec:
containers:
- name: {{ .Values.pgadmin.app }}
image: "dpage/pgadmin4:latest"
imagePullPolicy: Always
securityContext:
runAsUser: 0
runAsGroup: 0
env:
- name: PGADMIN_DEFAULT_EMAIL
valueFrom:
secretKeyRef:
name: {{ .Values.pgadmin.secret.name }}
key: username
- name: PGADMIN_DEFAULT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.pgadmin.secret.name }}
key: password
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/var/lib/pgadmin"
name: pgadminvolume
volumes:
- name: pgadminvolume
persistentVolumeClaim:
claimName: pgadmin-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.pgadmin.loadBalancer }}
namespace: {{ .Values.namespace }}
spec:
selector:
app: {{ .Values.pgadmin.app }}
task: {{ .Values.pgadmin.name }}
ports:
- protocol: TCP
name: http
port: 80
targetPort: 80
type: LoadBalancer
75 changes: 75 additions & 0 deletions deployment/MantaRayPlanCloud/templates/postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{{- $postgresSecrets := (lookup "v1" "Secret" .Values.namespace .Values.database.name ) -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.database.secret.name }}
namespace: {{ .Values.namespace }}
type: kubernetes.io/basic-auth
data:
username: {{ "app" | b64enc }}
{{- if and $postgresSecrets $postgresSecrets.data }}
{{- if $postgresSecrets.data.password }}
password: {{ $postgresSecrets.data.password }}
{{- else }}
password: {{ "nonExistingKey1234" | b64enc }}
{{- end }}
{{- else }}
password: {{ "nonExistingKey1234" | b64enc }}
{{- end }}
---
apiVersion: hostpathprovisioner.kubevirt.io/v1beta1
kind: HostPathProvisioner
metadata:
name: hostpath-provisioner
namespace: hostpath-provisioner
spec:
imagePullPolicy: Always
storagePools:
- name: "postgres-pool"
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.database.size.combined }}
path: "/MantaRayPlan/Postgres"
workload:
nodeSelector:
kubernetes.io/os: linux
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: postgres-csi
namespace: hostpath-provisioner
provisioner: kubevirt.io.hostpath-provisioner
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
parameters:
storagePool: postgres-pool
---
{{- if .Values.database.enabled }}
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: {{ .Values.database.name }}
namespace: {{ .Values.namespace }}
spec:
instances: 3
primaryUpdateStrategy: unsupervised
bootstrap:
initdb:
database: maintenance
owner: app
secret:
name: postgres-secret
storage:
size: {{ .Values.database.size.single }}
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.database.size.single }}
storageClassName: postgres-csi
{{ end }}
21 changes: 21 additions & 0 deletions deployment/MantaRayPlanCloud/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,24 @@ logging:
secrets:
name: "seq-secrets"
firstTimePassword: "QFCKH3NTSBQ5zmsH9DpXTB2YefIavEGJKa4SshKb11AXX8b4o4KPjuo9bd6WBfqDkpxKqzNjaOrCsE49ph369Wx84mIrksnJx5OtRcxAOjff"

database:
enabled: true
name: postgres
size:
single: 1Gi
combined: 4Gi
secret:
name: postgres-secret

pgadmin:
outsideAccess:
enabled: true
app: pgadmin
deployment: pgadmin-deployment
loadBalancer: "pgadmin-loadbalancer"
name: pgadmin
username: test@test.nl
host: "database.mantarayplan"
secret:
name: pgadmin-secret
22 changes: 22 additions & 0 deletions docs/database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dotnet Database
## Pre-requisites
```bash
dotnet tool install --global dotnet-ef
# If already installed
dotnet tool update --global dotnet-ef
```
## Migrations
### Create Migration
Default add migrations command:
```bash
dotnet ef migrations add InitialCreate
```

When the migrations is saved in another project:
```bash
dotnet ef migrations add InitialCreate --context MantaRayPlanDbContext --project ../Server.DataAccess.Database -o ../Server.DataAccess.Database/Migrations
```
### Remove Migration
```bash
dotnet ef migrations remove
```
Loading

0 comments on commit 7dc2e84

Please sign in to comment.