influx to docker
This commit is contained in:
@@ -22,22 +22,25 @@ in {
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
containers = {
|
containers = {
|
||||||
# db = builder.mkContainer {
|
db = builder.mkContainer {
|
||||||
# subdomain = containerCfg.subdomain;
|
subdomain = containerCfg.subdomain;
|
||||||
# image = "influxdata/influxdb:3.0";
|
image = "influxdb:3-core";
|
||||||
# port = 8181;
|
port = 8181;
|
||||||
# secret = name;
|
secret = name;
|
||||||
# extraEnv = {
|
extraEnv = {
|
||||||
# INFLUXD_DB_PATH = "/db";
|
INFLUXD_DB_PATH = "/db";
|
||||||
# INFLUXD_CONFIG_PATH = "/config";
|
INFLUXD_CONFIG_PATH = "/config";
|
||||||
# };
|
};
|
||||||
# overrides = {
|
overrides = {
|
||||||
# volumes = [
|
cmd = [ "influxdb3" "serve" "--node-id=node0" "--data-dir=/var/lib/influxdb3/data" "--admin-token-file=/var/lib/influxdb3/token.json" ];
|
||||||
# "${serverCfg.path.data}/influxdb:/db:rw"
|
ports = [ "8181:8181" ];
|
||||||
# "${serverCfg.path.config}/influxdb:/config:ro"
|
volumes = [
|
||||||
# ];
|
"${serverCfg.path.data}/influxdb:/var/lib/influxdb3/data:rw"
|
||||||
# };
|
"${serverCfg.path.config}/influxdb/config/admin-token.json:/var/lib/influxdb3/token.json:ro"
|
||||||
# };
|
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
server = builder.mkContainer {
|
server = builder.mkContainer {
|
||||||
tmpfs = true;
|
tmpfs = true;
|
||||||
@@ -47,10 +50,9 @@ in {
|
|||||||
secret = name;
|
secret = name;
|
||||||
extraEnv = {
|
extraEnv = {
|
||||||
DATABASE_URL = "/db/sqlite.db";
|
DATABASE_URL = "/db/sqlite.db";
|
||||||
DEFAULT_INFLUX_SERVER = "http://${builder.host}:8181";
|
DEFAULT_INFLUX_SERVER = "http://influx-db:8181";
|
||||||
};
|
};
|
||||||
overrides = {
|
overrides = {
|
||||||
ports = [ "8888:8080" ];
|
|
||||||
cmd = [ "--mode=admin" ];
|
cmd = [ "--mode=admin" ];
|
||||||
volumes = [
|
volumes = [
|
||||||
"${serverCfg.path.data}/influxdb:/db:rw"
|
"${serverCfg.path.data}/influxdb:/db:rw"
|
||||||
@@ -71,6 +73,15 @@ in {
|
|||||||
"DEFAULT_SERVER_NAME": "${serverCfg.domain}"
|
"DEFAULT_SERVER_NAME": "${serverCfg.domain}"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
cat > ${serverCfg.path.config}/influxdb/config/admin-token.json <<EOF
|
||||||
|
{
|
||||||
|
"token": "$INFLUXDB_TOKEN",
|
||||||
|
"name": "admin",
|
||||||
|
"description": "Admin token for automated deployment"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
chmod -R 755 ${serverCfg.path.config}/influxdb
|
chmod -R 755 ${serverCfg.path.config}/influxdb
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,23 +5,7 @@ let
|
|||||||
listNames = config.syscfg.server.db;
|
listNames = config.syscfg.server.db;
|
||||||
containerNames = lib.concatMap (app: app.requires.databases) (builtins.attrValues config.syscfg.server.loadedContainers);
|
containerNames = lib.concatMap (app: app.requires.databases) (builtins.attrValues config.syscfg.server.loadedContainers);
|
||||||
allApps = lib.unique (listNames ++ containerNames);
|
allApps = lib.unique (listNames ++ containerNames);
|
||||||
influxAdminTokenJson = pkgs.writeShellScript "influxdb3-admin-token-json" ''
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
token="''${INFLUXDB_TOKEN-''${INFLUXDB_TOKEN-}}"
|
|
||||||
if [ -z "$token" ]; then
|
|
||||||
echo "Missing INFLUXDB_TOKEN or INFLUXDB_TOKEN in ${config.sops.secrets."INFLUX".path}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat > "$RUNTIME_DIRECTORY/admin-token.json" <<EOF
|
|
||||||
{
|
|
||||||
"token": "$token",
|
|
||||||
"name": "admin",
|
|
||||||
"description": "Admin token for automated deployment"
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
'';
|
|
||||||
in {
|
in {
|
||||||
config = lib.mkIf ( builtins.length allApps > 0) {
|
config = lib.mkIf ( builtins.length allApps > 0) {
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
@@ -57,31 +41,6 @@ in {
|
|||||||
settings.protected-mode = "no";
|
settings.protected-mode = "no";
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.influxdb3 = {
|
|
||||||
description = "InfluxDB 3 Time Series Database Engine";
|
|
||||||
after = [ "network.target" ];
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
environment = {
|
|
||||||
INFLUXDB3_NODE_IDENTIFIER_PREFIX = "node0";
|
|
||||||
INFLUXDB3_OBJECT_STORE = "file";
|
|
||||||
INFLUXDB3_DATA_DIR = "${config.syscfg.server.path.data}/influxdb";
|
|
||||||
INFLUXDB3_DB_DIR = "${config.syscfg.server.path.data}/influxdb";
|
|
||||||
INFLUXDB3_ENABLE_INTERNAL_DB = "true";
|
|
||||||
};
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "simple";
|
|
||||||
EnvironmentFile = config.sops.secrets."INFLUX".path;
|
|
||||||
RuntimeDirectory = "influxdb3";
|
|
||||||
ExecStartPre = influxAdminTokenJson;
|
|
||||||
ExecStart = "${pkgs.influxdb3}/bin/influxdb3 serve --admin-token-file=%t/influxdb3/admin-token.json";
|
|
||||||
Restart = "on-failure";
|
|
||||||
StateDirectory = "influxdb3";
|
|
||||||
PrivateTmp = true;
|
|
||||||
NoNewPrivileges = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
systemd.services.postgresql-init = {
|
systemd.services.postgresql-init = {
|
||||||
description = "Custom Postgres Setup (Ownership & Passwords)";
|
description = "Custom Postgres Setup (Ownership & Passwords)";
|
||||||
after = [ "postgresql.service" ];
|
after = [ "postgresql.service" ];
|
||||||
|
|||||||
Reference in New Issue
Block a user