initial commit

This commit is contained in:
Peter 2024-12-10 08:43:59 +01:00
commit 734e1b22f9
Signed by: prskr
GPG key ID: F56BED6903BC5E37
11 changed files with 201 additions and 0 deletions

94
examples/db/cluster.yaml Normal file
View file

@ -0,0 +1,94 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: pgsodium-config
data:
pgsodium_getkey.sh: |
#!/bin/bash
set -euo pipefail
if [[ -z "${VAULT_KEY}" ]]; then
echo "PGSODIUM_KEY is not set" >&2
exit 1
fi
echo -n "$VAULT_KEY"
---
apiVersion: v1
kind: Secret
metadata:
name: pgsodium-key
data:
# Generate a 32-byte key
# head -c 32 /dev/urandom | od -A n -t x1 | tr -d ' \n' | base64
key: NmE4YzQwMWY3NzI4YzdiMWViOTE5NmJhMWRlYmFkOTRhMDRlZTgwZDUzZDg4NWE5MWZlODY0MzdkOGIyYmQ2OA==
---
apiVersion: v1
kind: Secret
metadata:
name: supabase-admin-credentials
labels:
cnpg.io/reload: "true"
type: kubernetes.io/basic-auth
stringData:
username: supabase_admin
password: 1n1t-R00t!
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 1
imageName: ghcr.io/supabase/postgres:15.6.1.145
postgresUID: 105
postgresGID: 106
bootstrap:
initdb:
database: app
owner: supabase_admin
postgresql:
shared_preload_libraries:
- pg_stat_statements
- pgaudit
- plpgsql
- plpgsql_check
- pg_cron
- pg_net
- pgsodium
- timescaledb
- auto_explain
- pg_tle
- plan_filter
parameters:
pgsodium.getkey_script: /projected/bin/pgsodium_getkey.sh
cron.database_name: app
auto_explain.log_min_duration: 10s
projectedVolumeTemplate:
sources:
- configMap:
name: pgsodium-config
items:
- key: pgsodium_getkey.sh
path: bin/pgsodium_getkey.sh
mode: 0755
env:
# cloudnative-pg reserves all env variables that start with PG for internal use
- name: VAULT_KEY
valueFrom:
secretKeyRef:
name: pgsodium-key
key: key
managed:
roles:
- name: supabase_admin
ensure: present
superuser: true
login: true
passwordSecret:
name: supabase-admin-credentials
storage:
size: 1Gi

5
go.mod Normal file
View file

@ -0,0 +1,5 @@
module code.icb4dc0.de/prskr/supabase-operator
go 1.23.4
require github.com/magefile/mage v1.15.0

2
go.sum Normal file
View file

@ -0,0 +1,2 @@
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=

6
go.work Normal file
View file

@ -0,0 +1,6 @@
go 1.23.4
use (
.
./tools
)

3
hack/clean.sql Normal file
View file

@ -0,0 +1,3 @@
-- drop publication if exists supabase_realtime;
-- reach clean state for supabase-operator
drop publication if exists supabase_realtime;

13
mage.go Normal file
View file

@ -0,0 +1,13 @@
//go:build ignore
package main
import (
"os"
"github.com/magefile/mage/mage"
)
func main() {
os.Exit(mage.Main())
}

30
magefiles/common.go Normal file
View file

@ -0,0 +1,30 @@
package main
import (
"log/slog"
"os"
_ "github.com/magefile/mage/sh"
)
var workingDir string
func init() {
logLevel := new(slog.LevelVar)
if val, set := os.LookupEnv("MAGE_LOG_LEVEL"); set {
_ = logLevel.UnmarshalText([]byte(val))
}
handler := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: logLevel,
})
slog.SetDefault(slog.New(handler))
if wd, err := os.Getwd(); err != nil {
panic(err)
} else {
workingDir = wd
}
}

4
magefiles/generate.go Normal file
View file

@ -0,0 +1,4 @@
package main
func FetchImageMeta() {
}

41
magefiles/magefile.go Normal file
View file

@ -0,0 +1,41 @@
package main
import (
"fmt"
"os"
"os/exec"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
)
// Default target to run when none is specified
// If not set, running mage will list available targets
// var Default = Build
// A build step that requires additional params, or platform specific steps for example
func Build() error {
mg.Deps(InstallDeps)
fmt.Println("Building...")
cmd := exec.Command("go", "build", "-o", "MyApp", ".")
return cmd.Run()
}
// A custom install step if you need your bin someplace other than go/bin
func Install() error {
mg.Deps(Build)
fmt.Println("Installing...")
return os.Rename("./MyApp", "/usr/bin/MyApp")
}
// Manage your deps, or running package managers.
func InstallDeps() error {
fmt.Println("Installing Deps...")
cmd := exec.Command("go", "get", "github.com/stretchr/piglatin")
return cmd.Run()
}
// Clean up after yourself
func Clean() {
fmt.Println("Cleaning...")
os.RemoveAll("MyApp")
}

3
tools/go.mod Normal file
View file

@ -0,0 +1,3 @@
module tools
go 1.23.4

0
tools/go.sum Normal file
View file