feat: add surrealdb nixlet

This commit is contained in:
technofab 2024-04-13 16:26:57 +02:00
parent b343866134
commit ba81fba6b2
5 changed files with 140 additions and 0 deletions

View file

@ -25,6 +25,7 @@
attic = utils.mkNixlet ./nixlets/attic; attic = utils.mkNixlet ./nixlets/attic;
postgres = utils.mkNixlet ./nixlets/postgres; postgres = utils.mkNixlet ./nixlets/postgres;
tikv = utils.mkNixlet ./nixlets/tikv; tikv = utils.mkNixlet ./nixlets/tikv;
surrealdb = utils.mkNixlet ./nixlets/surrealdb;
}; };
}; };
perSystem = { perSystem = {

View file

@ -0,0 +1,6 @@
{...}: {
imports = [
./deployment.nix
./service.nix
];
}

View file

@ -0,0 +1,56 @@
{
values,
lib,
...
}: {
kubernetes.resources = {
deployments."${values.uniqueName}" = {
spec = {
replicas = values.replicaCount;
selector.matchLabels.app = "${values.uniqueName}";
template = {
metadata.labels.app = "${values.uniqueName}";
spec = {
securityContext = {
fsGroup = 1000;
runAsUser = 1000;
runAsGroup = 1000;
};
containers."surrealdb" = rec {
image = "${values.image.repository}:${values.image.tag}";
imagePullPolicy = values.image.pullPolicy;
args = ["start"];
env = [
{
name = "SURREAL_NO_BANNER";
value = "true";
}
{
name = "SURREAL_PATH";
value = values.surrealdb.path;
}
{
name = "SURREAL_LOG";
value = values.surrealdb.log;
}
{
name = "SURREAL_BIND";
value = "0.0.0.0:8000";
}
];
envFrom = [
{secretRef.name = "${values.uniqueName}-env";}
];
ports."http".containerPort = 8000;
livenessProbe.httpGet = {
path = "/health";
port = "http";
};
readinessProbe = livenessProbe;
};
};
};
};
};
};
}

View file

@ -0,0 +1,17 @@
{values, ...}: {
kubernetes.resources = {
services."${values.uniqueName}" = {
spec = {
selector.app = "${values.uniqueName}";
ports = [
{
name = "http";
targetPort = "http";
port = values.service.port;
}
];
type = values.service.type;
};
};
};
}

View file

@ -0,0 +1,60 @@
{
lib,
utils,
project,
...
}:
with lib; {
# for some basic values see https://github.com/helm/examples/blob/4888ba8fb8180dd0c36d1e84c1fcafc6efd81532/charts/hello-world/values.yaml
options = {
replicaCount = mkOption {
type = types.int;
default = 1;
};
image = utils.mkNestedOption {
repository = mkOption {
type = types.str;
default = "surrealdb/surrealdb";
};
pullPolicy = mkOption {
type = types.str;
default = "IfNotPresent";
};
tag = mkOption {
type = types.str;
default = "latest";
};
};
service = utils.mkNestedOption {
port = mkOption {
type = types.int;
default = 8000;
};
type = mkOption {
type = types.str;
default = "ClusterIP";
};
};
surrealdb = utils.mkNestedOption {
log = mkOption {
type = types.str;
default = "info";
};
path = mkOption {
type = types.str;
default = "memory";
description = ''
Path to database.
Examples: "memory", "file://<path>", "tikv://<tikv-pd-service>:2379"
'';
};
};
# internal
uniqueName = mkOption {
internal = true;
type = types.str;
default = "${project}-surrealdb";
};
};
}