From c8fb9598a67348ba240b58d1b5a59ea12ef930a7 Mon Sep 17 00:00:00 2001 From: Nathan Rashleigh Date: Sat, 12 Apr 2025 21:11:40 +1000 Subject: [PATCH] crates --- .gitignore | 1 + crates/crates.cron.yaml | 141 ++++++++++++++++--------------------- crates/crates.ingress.yaml | 30 ++------ crates/crates.yaml | 43 +++++------ ntwl.sublime-project | 8 +++ 5 files changed, 94 insertions(+), 129 deletions(-) create mode 100644 ntwl.sublime-project diff --git a/.gitignore b/.gitignore index 5bda649..dd4a79b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ pvs/ *.sql *.tar.gz *.secret.yaml +ntwl.sublime-workspace diff --git a/crates/crates.cron.yaml b/crates/crates.cron.yaml index e0d5604..6a07008 100644 --- a/crates/crates.cron.yaml +++ b/crates/crates.cron.yaml @@ -1,88 +1,67 @@ ---- +# --- -apiVersion: v1 -kind: PersistentVolume -metadata: - name: crates-postgres-backup-pv -spec: - storageClassName: "" - capacity: - storage: 1Gi - accessModes: - - ReadWriteOnce - persistentVolumeReclaimPolicy: Retain - claimRef: - namespace: default - name: crates-postgres-backup-pvc - hostPath: - # Into homedir so we can scp it ez - path: "/home/ntr/archives/crates-postgres" - type: DirectoryOrCreate +# kind: PersistentVolumeClaim +# apiVersion: v1 +# metadata: +# name: crates-postgres-backup-pvc +# spec: +# volumeName: crates-postgres-backup-pv +# accessModes: +# - ReadWriteOnce +# resources: +# requests: +# storage: 1Gi ---- +# --- -kind: PersistentVolumeClaim -apiVersion: v1 -metadata: - name: crates-postgres-backup-pvc -spec: - volumeName: crates-postgres-backup-pv - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi +# apiVersion: batch/v1 +# kind: CronJob +# metadata: +# name: crates-db-backup +# spec: +# schedule: "20 4 * * *" +# jobTemplate: +# spec: +# template: +# metadata: +# labels: +# app: crates-postgres-backup +# spec: +# restartPolicy: Never +# containers: +# - name: crates-postgres-backup +# image: postgres:16 +# command: +# - "/bin/sh" +# - "-c" +# - +# | +# cd /mnt/dest/ +# TZ="Australia/Melbourne" +# TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S') +# DEST=crates-$TIMESTAMP.sql.gz ---- +# echo "Backing up to $DEST" +# pg_dump --dbname=$POSTGRES_URL | gzip > $DEST +# echo "Backup Complete" -apiVersion: batch/v1 -kind: CronJob -metadata: - name: crates-db-backup -spec: - schedule: "20 4 * * *" - jobTemplate: - spec: - template: - metadata: - labels: - app: crates-postgres-backup - spec: - restartPolicy: Never - containers: - - name: crates-postgres-backup - image: postgres:16 - command: - - "/bin/sh" - - "-c" - - - | - cd /mnt/dest/ - TZ="Australia/Melbourne" - TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S') - DEST=crates-$TIMESTAMP.sql.gz +# echo "Removing old copies..." +# find . -type f -name "*.sql.gz" -mtime 7 | xargs rm -v - echo "Backing up to $DEST" - pg_dump --dbname=$POSTGRES_URL | gzip > $DEST - echo "Backup Complete" +# echo "Setting latest link..." +# ln -nfs $DEST latest.sql.gz +# env: +# - name: POSTGRES_URL +# valueFrom: +# secretKeyRef: +# name: crates +# key: POSTGRES_URL +# volumeMounts: +# - name: crates-postgres-backup-storage +# mountPath: /mnt/dest +# volumes: +# - name: crates-postgres-backup-storage +# persistentVolumeClaim: +# claimName: crates-postgres-backup-pvc - echo "Removing old copies..." - find . -type f -name "*.sql.gz" -mtime 7 | xargs rm -v - - echo "Setting latest link..." - ln -nfs $DEST latest.sql.gz - env: - - name: POSTGRES_URL - valueFrom: - secretKeyRef: - name: crates - key: POSTGRES_URL - volumeMounts: - - name: crates-postgres-backup-storage - mountPath: /mnt/dest - volumes: - - name: crates-postgres-backup-storage - persistentVolumeClaim: - claimName: crates-postgres-backup-pvc - ---- +# --- diff --git a/crates/crates.ingress.yaml b/crates/crates.ingress.yaml index 31eee76..0829cfb 100644 --- a/crates/crates.ingress.yaml +++ b/crates/crates.ingress.yaml @@ -7,6 +7,7 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: + namespace: crates name: crates-client annotations: cert-manager.io/cluster-issuer: "letsencrypt-prod" @@ -14,19 +15,9 @@ spec: ingressClassName: haproxy tls: - hosts: - - crates.strix.systems - secretName: crates-strix-systems-tls + - crates.ntwl.xyz + secretName: crates-ntwl-xyz-tls rules: - - host: crates.strix.systems - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: crates-client - port: - number: 8080 - host: crates.ntwl.xyz http: paths: @@ -43,6 +34,7 @@ spec: apiVersion: networking.k8s.io/v1 kind: Ingress metadata: + namespace: crates annotations: cert-manager.io/cluster-issuer: "letsencrypt-prod" haproxy.org/path-rewrite: "/api(/)?(.*) /$2" @@ -52,19 +44,9 @@ spec: ingressClassName: haproxy tls: - hosts: - - crates.strix.systems - secretName: crates-strix-systems-tls + - crates.ntwl.xyz + secretName: crates-ntwl-xyz-tls rules: - - host: crates.strix.systems - http: - paths: - - path: /api(/|$)(.*) - pathType: ImplementationSpecific - backend: - service: - name: crates-api - port: - number: 41337 - host: crates.ntwl.xyz http: paths: diff --git a/crates/crates.yaml b/crates/crates.yaml index ebed5de..85a96af 100644 --- a/crates/crates.yaml +++ b/crates/crates.yaml @@ -1,26 +1,13 @@ -# ----------------------------------------------------------------------- -# VOLUMES -# ----------------------------------------------------------------------- - --- apiVersion: v1 -kind: PersistentVolume +kind: Namespace metadata: - name: crates-postgres-pv -spec: - storageClassName: "" - capacity: - storage: 1Gi - accessModes: - - ReadWriteOnce - persistentVolumeReclaimPolicy: Retain - claimRef: - namespace: default - name: crates-postgres-pvc - hostPath: - path: "/var/lib/rancher/k3s/storage/crates-postgres-pv" - type: DirectoryOrCreate + name: crates + +# ----------------------------------------------------------------------- +# VOLUMES +# ----------------------------------------------------------------------- --- @@ -28,13 +15,14 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: name: crates-postgres-pvc + namespace: crates spec: - volumeName: crates-postgres-pv + storageClassName: zfs-fast accessModes: - ReadWriteOnce resources: requests: - storage: 1Gi + storage: 2Gi --- @@ -46,6 +34,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: crates-postgres + namespace: crates spec: replicas: 1 selector: @@ -91,6 +80,7 @@ spec: apiVersion: apps/v1 kind: Deployment metadata: + namespace: crates name: crates-api spec: replicas: 1 @@ -104,7 +94,7 @@ spec: spec: containers: - name: crates-api - image: registry.strix.systems/crates-api + image: registry.ntwl.xyz/crates-api imagePullPolicy: Always ports: - containerPort: 80 @@ -136,6 +126,7 @@ spec: apiVersion: apps/v1 kind: Deployment metadata: + namespace: crates name: crates-migrate spec: replicas: 1 @@ -149,7 +140,7 @@ spec: spec: containers: - name: crates-migrate - image: registry.strix.systems/crates-api + image: registry.ntwl.xyz/crates-api imagePullPolicy: IfNotPresent command: ["npx"] args: ["prisma", "migrate", "deploy"] @@ -165,6 +156,7 @@ spec: apiVersion: apps/v1 kind: Deployment metadata: + namespace: crates name: crates-client spec: replicas: 1 @@ -178,7 +170,7 @@ spec: spec: containers: - name: crates-client - image: registry.strix.systems/crates-client + image: registry.ntwl.xyz/crates-client imagePullPolicy: Always ports: - containerPort: 8080 @@ -192,6 +184,7 @@ spec: apiVersion: v1 kind: Service metadata: + namespace: crates name: crates-api spec: selector: @@ -204,6 +197,7 @@ spec: apiVersion: v1 kind: Service metadata: + namespace: crates name: crates-postgres spec: selector: @@ -216,6 +210,7 @@ spec: apiVersion: v1 kind: Service metadata: + namespace: crates name: crates-client spec: selector: diff --git a/ntwl.sublime-project b/ntwl.sublime-project new file mode 100644 index 0000000..24db303 --- /dev/null +++ b/ntwl.sublime-project @@ -0,0 +1,8 @@ +{ + "folders": + [ + { + "path": "." + } + ] +}