From e5465f08ea8fea155c6d42ed02a401795fb77601 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Wed, 6 May 2026 22:18:08 +0200 Subject: [PATCH] A couple of updates Signed-off-by: Nikolai Rodionov --- .gitignore | 1 + Taskfile.yml | 51 +++++++++++++++++++ .../templates/deployment.yaml | 12 +++++ .../templates/extra/database.yaml | 14 +++++ .../templates/{ => traefik}/ingressroute.yaml | 6 ++- .../templates/{ => traefik}/middleware.yaml | 0 migrations/20260425183515_init.down.sql | 1 - .../20260506200734_accounts_init.down.sql | 1 + ...ql => 20260506200734_accounts_init.up.sql} | 2 +- 9 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 helm/softplayer-backend/templates/extra/database.yaml rename helm/softplayer-backend/templates/{ => traefik}/ingressroute.yaml (77%) rename helm/softplayer-backend/templates/{ => traefik}/middleware.yaml (100%) delete mode 100644 migrations/20260425183515_init.down.sql create mode 100644 migrations/20260506200734_accounts_init.down.sql rename migrations/{20260425183515_init.up.sql => 20260506200734_accounts_init.up.sql} (88%) diff --git a/.gitignore b/.gitignore index 567609b..d5697ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +bin/ diff --git a/Taskfile.yml b/Taskfile.yml index 7740a72..b0e3b0b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -2,6 +2,11 @@ version: "3" +vars: + LOCALBIN: + sh: echo "$(pwd)/bin" + MIGRATE: "{{.LOCALBIN}}/migrate" + tasks: build: desc: Build go code @@ -51,3 +56,49 @@ tasks: - go get gitea.badhouseplants.net/softplayer/softplayer-go-proto@$(git -C '{{ .WORKDIR }}' rev-parse HEAD) - rm -rf '{{ .WORKDIR }}' - go mod tidy + + add-migration: + desc: Add a new database migration + silent: true + cmd: "{{.MIGRATE}} create -dir migrations -ext sql {{.CLI_ARGS}}" + + # Install required tools + localbin: + desc: Create local bin directory + silent: true + cmds: + - mkdir -p "{{.LOCALBIN}}" + + migrate: + desc: Download migrate if necessary + silent: true + deps: + - localbin + cmds: + - task: go-install-tool + vars: + TARGET: "{{.MIGRATE}}" + PACKAGE: github.com/golang-migrate/migrate/v4/cmd/migrate + VERSION: latest + + go-install-tool: + internal: true + silent: true + cmd: |- + set -e + TARGET="{{.TARGET}}" + PACKAGE="{{.PACKAGE}}@{{.VERSION}}" + VERSIONED="${TARGET}-{{.VERSION}}" + + if [ -f "$VERSIONED" ] && [ "$(readlink -- "$TARGET" 2>/dev/null)" = "$VERSIONED" ]; then + echo "$PACKAGE already installed" + exit 0 + fi + + echo "Downloading $PACKAGE" + rm -f "$TARGET" + + GOBIN="{{.LOCALBIN}}" go install "$PACKAGE" + + mv "{{.LOCALBIN}}/$(basename "$TARGET")" "$VERSIONED" + ln -sf "$(realpath "$VERSIONED")" "$TARGET" diff --git a/helm/softplayer-backend/templates/deployment.yaml b/helm/softplayer-backend/templates/deployment.yaml index 04761f2..70fdf1e 100644 --- a/helm/softplayer-backend/templates/deployment.yaml +++ b/helm/softplayer-backend/templates/deployment.yaml @@ -34,6 +34,12 @@ spec: {{- end }} initContainers: - name: {{ .Chart.Name }}-migrations + env: + - name: SOFTPLAYER_DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: {{ include "softplayer-backend.fullname" . }}-db-creds + key: CONNECTION_STRING {{- with .Values.securityContext }} securityContext: {{- toYaml . | nindent 12 }} @@ -53,6 +59,12 @@ spec: {{- end }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: SOFTPLAYER_DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: {{ include "softplayer-backend.fullname" . }}-db-creds + key: CONNECTION_STRING args: - serve - --dev-mode diff --git a/helm/softplayer-backend/templates/extra/database.yaml b/helm/softplayer-backend/templates/extra/database.yaml new file mode 100644 index 0000000..14d2d6e --- /dev/null +++ b/helm/softplayer-backend/templates/extra/database.yaml @@ -0,0 +1,14 @@ +apiVersion: kinda.rocks/v1beta1 +kind: Database +metadata: + name: {{ include "softplayer-backend.fullname" . }} + labels: + {{- include "softplayer-backend.labels" . | nindent 4 }} +spec: + backup: + cron: 0 0 * * * + enable: false + deletionProtected: true + instance: cloudnative-pg17-softplayer + postgres: {} + secretName: {{ include "softplayer-backend.fullname" . }}-db-creds diff --git a/helm/softplayer-backend/templates/ingressroute.yaml b/helm/softplayer-backend/templates/traefik/ingressroute.yaml similarity index 77% rename from helm/softplayer-backend/templates/ingressroute.yaml rename to helm/softplayer-backend/templates/traefik/ingressroute.yaml index b9c1d8f..c007c75 100644 --- a/helm/softplayer-backend/templates/ingressroute.yaml +++ b/helm/softplayer-backend/templates/traefik/ingressroute.yaml @@ -1,7 +1,9 @@ apiVersion: traefik.io/v1alpha1 kind: IngressRoute metadata: - name: grpc-route + name: {{ include "softplayer-backend.fullname" . }} + labels: + {{- include "softplayer-backend.labels" . | nindent 4 }} annotations: external-dns.alpha.kubernetes.io/target: {{ .Values.ingressRoute.target }} kubernetes.io/ingress.class: {{ .Values.ingressRoute.class }} @@ -15,7 +17,7 @@ spec: - name: {{ include "softplayer-backend.fullname" . | replace "-" "" }} services: - name: {{ include "softplayer-backend.fullname" . }} - port: 4020 + port: {{ .Values.service.port }} scheme: h2c tls: secretName: {{ .Values.ingressRoute.url }} diff --git a/helm/softplayer-backend/templates/middleware.yaml b/helm/softplayer-backend/templates/traefik/middleware.yaml similarity index 100% rename from helm/softplayer-backend/templates/middleware.yaml rename to helm/softplayer-backend/templates/traefik/middleware.yaml diff --git a/migrations/20260425183515_init.down.sql b/migrations/20260425183515_init.down.sql deleted file mode 100644 index c99ddcd..0000000 --- a/migrations/20260425183515_init.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS users; diff --git a/migrations/20260506200734_accounts_init.down.sql b/migrations/20260506200734_accounts_init.down.sql new file mode 100644 index 0000000..1616db4 --- /dev/null +++ b/migrations/20260506200734_accounts_init.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS accounts; diff --git a/migrations/20260425183515_init.up.sql b/migrations/20260506200734_accounts_init.up.sql similarity index 88% rename from migrations/20260425183515_init.up.sql rename to migrations/20260506200734_accounts_init.up.sql index a0e8f9a..9c2a401 100644 --- a/migrations/20260425183515_init.up.sql +++ b/migrations/20260506200734_accounts_init.up.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS users ( +CREATE TABLE IF NOT EXISTS accounts ( uuid UUID PRIMARY KEY, email VARCHAR(255) NOT NULL CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$') UNIQUE,