feat: add option to enable namespaces

This commit is contained in:
Oliver Geneser
2025-09-13 13:45:19 +02:00
parent 4b1f359cb6
commit 803577a403
10 changed files with 300 additions and 110 deletions

View File

@@ -8,8 +8,27 @@ import {
generateVolumeMounts,
prepareEnvironmentVariables,
} from "../docker/utils";
import { execAsync, execAsyncRemote } from "../process/execAsync";
import { getRemoteDocker } from "../servers/remote-docker";
const getServerArchitecture = async (
serverId?: string | null,
): Promise<string> => {
if (!serverId) {
const { stdout } = await execAsync("uname -m");
return stdout.trim();
}
const { stdout } = await execAsyncRemote(serverId, "uname -m");
return stdout.trim();
};
const getLibsqlImage = (arch: string): string => {
if (arch === "aarch64" || arch === "arm64") {
return "ghcr.io/tursodatabase/libsql-server:latest-arm";
}
return "ghcr.io/tursodatabase/libsql-server:latest";
};
export type LibsqlNested = InferResultType<
"libsql",
{ mounts: true; environment: { with: { project: true } } }
@@ -20,6 +39,7 @@ export const buildLibsql = async (libsql: LibsqlNested) => {
env,
externalPort,
externalGRPCPort,
externalAdminPort,
dockerImage,
memoryLimit,
memoryReservation,
@@ -31,8 +51,16 @@ export const buildLibsql = async (libsql: LibsqlNested) => {
cpuReservation,
command,
mounts,
serverId,
enableNamespaces,
} = libsql;
let finalDockerImage = dockerImage;
if (dockerImage === "ghcr.io/tursodatabase/libsql-server:latest") {
const arch = await getServerArchitecture(serverId);
finalDockerImage = getLibsqlImage(arch);
}
const basicAuth = Buffer.from(
`${databaseUser}:${databasePassword}`,
"utf-8",
@@ -69,18 +97,25 @@ export const buildLibsql = async (libsql: LibsqlNested) => {
const docker = await getRemoteDocker(libsql.serverId);
let finalCommand =
command ??
"sqld --db-path iku.db --http-listen-addr 0.0.0.0:8080 --grpc-listen-addr 0.0.0.0:5001 --admin-listen-addr 0.0.0.0:5000";
if (enableNamespaces) {
finalCommand += " --enable-namespaces";
}
const settings: CreateServiceOptions = {
Name: appName,
TaskTemplate: {
ContainerSpec: {
HealthCheck,
Image: dockerImage,
Image: finalDockerImage,
Env: envVariables,
Mounts: [...volumesMount, ...bindsMount, ...filesMount],
...(command
...(finalCommand
? {
Command: ["/bin/sh"],
Args: ["-c", command],
Args: ["-c", finalCommand],
}
: {}),
Labels,
@@ -117,6 +152,16 @@ export const buildLibsql = async (libsql: LibsqlNested) => {
} as PortConfig,
]
: []),
...(externalAdminPort
? [
{
Protocol: "tcp",
TargetPort: 5000,
PublishedPort: externalAdminPort,
PublishMode: "host",
} as PortConfig,
]
: []),
],
},
UpdateConfig,