120 lines
3.8 KiB
Nix
120 lines
3.8 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
serviceName = "librechat";
|
|
portUtils = import ../../../../lib/port-utils.nix {inherit lib;};
|
|
servicePort = portUtils.getPort serviceName "AZ-CLD-1";
|
|
ragApiPort = portUtils.getPort "rag-api" "AZ-CLD-1";
|
|
envFileProd = config.age.secrets.librechat-env-prod.path;
|
|
envFileCommon = config.age.secrets.librechat.path;
|
|
in {
|
|
virtualisation.oci-containers = {
|
|
containers.meilisearch = {
|
|
image = "getmeili/meilisearch:v1.12.3";
|
|
autoStart = true;
|
|
volumes = ["librechat_meili:/meili_data"];
|
|
environment = {
|
|
MEILI_HTTP_ADDR = "0.0.0.0:7700";
|
|
MEILI_NO_ANALYTICS = "true";
|
|
};
|
|
environmentFiles = [envFileCommon envFileProd];
|
|
extraOptions = ["--ip=10.89.0.20" "--network=web"];
|
|
};
|
|
|
|
containers.rag_api = {
|
|
image = "ghcr.io/danny-avila/librechat-rag-api-dev-lite:latest";
|
|
autoStart = true;
|
|
environment = {
|
|
RAG_PORT = "8000";
|
|
DB_HOST = "10.89.0.1";
|
|
DB_PORT = "5432";
|
|
};
|
|
environmentFiles = [envFileCommon envFileProd];
|
|
dependsOn = ["meilisearch"];
|
|
extraOptions = ["--add-host=postgres:10.89.0.1" "--ip=10.89.0.21" "--network=web"];
|
|
ports = ["127.0.0.1:${toString ragApiPort}:8000"];
|
|
};
|
|
|
|
containers.mongodb = {
|
|
image = "mongo:7";
|
|
autoStart = true;
|
|
volumes = [
|
|
"librechat_mongo:/data/db"
|
|
"/var/backup/mongodb:/data/backups"
|
|
];
|
|
# Enable auth once users exist; see Mongo auth doc.
|
|
# command = [ "mongod", "--auth" ];
|
|
extraOptions = ["--ip=10.89.0.22" "--network=web"];
|
|
};
|
|
|
|
containers.${serviceName} = {
|
|
image = "ghcr.io/danny-avila/librechat-dev-api:latest";
|
|
autoStart = true;
|
|
ports = ["127.0.0.1:${toString servicePort}:3080"];
|
|
dependsOn = ["mongodb" "rag_api" "meilisearch"];
|
|
environment = {
|
|
HOST = "0.0.0.0";
|
|
NODE_ENV = "production";
|
|
# Mongo URI (start without auth; switch to mongodb://user:pass@mongodb:27017/LibreChat after Step 4)
|
|
MONGO_URI = "mongodb://mongodb:27017/LibreChat";
|
|
MEILI_HOST = "http://meilisearch:7700";
|
|
RAG_PORT = "8000";
|
|
RAG_API_URL = "http://rag_api:8000";
|
|
};
|
|
environmentFiles = [envFileCommon envFileProd];
|
|
volumes = [
|
|
# Config file still needs to be a bind mount for host management
|
|
"/var/lib/librechat/librechat.yaml:/app/librechat.yaml:ro"
|
|
# Use named volumes for application data
|
|
"librechat_images:/app/client/public/images"
|
|
"librechat_uploads:/app/uploads"
|
|
"librechat_logs:/app/api/logs"
|
|
];
|
|
extraOptions = ["--ip=10.89.0.23" "--network=web"];
|
|
};
|
|
};
|
|
|
|
systemd.services."mongo-nightly-dump" = {
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
ExecStart = ''
|
|
${pkgs.podman}/bin/podman exec mongodb \
|
|
sh -lc 'mongodump --uri="mongodb://adminUser:securePassword@localhost:27017/?authSource=admin" \
|
|
--out /data/backups/$(date +%F)'
|
|
'';
|
|
ExecStartPost = ''
|
|
# Clean up old backups from within the container
|
|
${pkgs.podman}/bin/podman exec mongodb \
|
|
sh -lc 'find /data/backups -maxdepth 1 -type d -mtime +14 -exec rm -rf {} +'
|
|
'';
|
|
};
|
|
};
|
|
|
|
systemd.timers."mongo-nightly-dump" = {
|
|
wantedBy = ["timers.target"];
|
|
timerConfig.OnCalendar = "daily";
|
|
timerConfig.RandomizedDelaySec = "15m";
|
|
};
|
|
|
|
# Traefik configuration
|
|
services.traefik.dynamicConfigOptions.http = {
|
|
services.${serviceName}.loadBalancer.servers = [
|
|
{
|
|
url = "http://localhost:${toString servicePort}/";
|
|
}
|
|
];
|
|
|
|
routers.${serviceName} = {
|
|
rule = "Host(`chat.az-gruppe.com`)";
|
|
tls = {
|
|
certResolver = "ionos";
|
|
};
|
|
service = serviceName;
|
|
entrypoints = "websecure";
|
|
};
|
|
};
|
|
}
|