mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-31 17:22:16 +00:00
feat: add bottomless replication
This commit is contained in:
@@ -3,6 +3,8 @@ import { boolean, integer, json, pgTable, text } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { nanoid } from "nanoid";
|
||||
import { z } from "zod";
|
||||
import { backups } from "./backups";
|
||||
import { destinations } from "./destination";
|
||||
import { environments } from "./environment";
|
||||
import { mounts } from "./mount";
|
||||
import { server } from "./server";
|
||||
@@ -42,6 +44,14 @@ export const libsql = pgTable("libsql", {
|
||||
sqldNode: sqldNode("sqldNode").notNull().default("primary"),
|
||||
sqldPrimaryUrl: text("sqldPrimaryUrl"),
|
||||
enableNamespaces: boolean("enableNamespaces").notNull().default(false),
|
||||
enableBottomlessReplication: boolean("enableBottomlessReplication")
|
||||
.notNull()
|
||||
.default(false),
|
||||
bottomlessReplicationDestinationId: text(
|
||||
"bottomlessReplicationDestinationId",
|
||||
).references(() => destinations.destinationId, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
dockerImage: text("dockerImage").notNull(),
|
||||
command: text("command"),
|
||||
env: text("env"),
|
||||
@@ -89,6 +99,10 @@ export const libsqlRelations = relations(libsql, ({ one, many }) => ({
|
||||
fields: [libsql.serverId],
|
||||
references: [server.serverId],
|
||||
}),
|
||||
bottomlessReplicationDestination: one(destinations, {
|
||||
fields: [libsql.bottomlessReplicationDestinationId],
|
||||
references: [destinations.destinationId],
|
||||
}),
|
||||
}));
|
||||
|
||||
const createSchema = createInsertSchema(libsql, {
|
||||
@@ -106,6 +120,8 @@ const createSchema = createInsertSchema(libsql, {
|
||||
sqldNode: z.enum(sqldNode.enumValues),
|
||||
sqldPrimaryUrl: z.string().nullable(),
|
||||
enableNamespaces: z.boolean().default(false),
|
||||
enableBottomlessReplication: z.boolean().default(false),
|
||||
bottomlessReplicationDestinationId: z.string().nullable(),
|
||||
dockerImage: z.string().default("ghcr.io/tursodatabase/libsql-server:latest"),
|
||||
command: z.string().optional(),
|
||||
env: z.string().optional(),
|
||||
|
||||
@@ -59,6 +59,7 @@ export const findLibsqlById = async (libsqlId: string) => {
|
||||
},
|
||||
mounts: true,
|
||||
server: true,
|
||||
bottomlessReplicationDestination: true,
|
||||
// backups: {
|
||||
// with: {
|
||||
// destination: true,
|
||||
|
||||
@@ -31,7 +31,11 @@ const getLibsqlImage = (arch: string): string => {
|
||||
|
||||
export type LibsqlNested = InferResultType<
|
||||
"libsql",
|
||||
{ mounts: true; environment: { with: { project: true } } }
|
||||
{
|
||||
mounts: true;
|
||||
environment: { with: { project: true } };
|
||||
bottomlessReplicationDestination: true;
|
||||
}
|
||||
>;
|
||||
export const buildLibsql = async (libsql: LibsqlNested) => {
|
||||
const {
|
||||
@@ -53,6 +57,8 @@ export const buildLibsql = async (libsql: LibsqlNested) => {
|
||||
mounts,
|
||||
serverId,
|
||||
enableNamespaces,
|
||||
enableBottomlessReplication,
|
||||
bottomlessReplicationDestination,
|
||||
} = libsql;
|
||||
|
||||
let finalDockerImage = dockerImage;
|
||||
@@ -66,10 +72,20 @@ export const buildLibsql = async (libsql: LibsqlNested) => {
|
||||
"utf-8",
|
||||
).toString("base64");
|
||||
|
||||
const defaultLibsqlEnv = `SQLD_NODE="${sqldNode}"\nSQLD_HTTP_AUTH="basic:${basicAuth}"${
|
||||
let defaultLibsqlEnv = `SQLD_NODE="${sqldNode}"\nSQLD_HTTP_AUTH="basic:${basicAuth}"${
|
||||
env ? `\n${env}` : ""
|
||||
}${sqldNode === "replica" ? `\nSQLD_PRIMARY_URL="${sqldPrimaryUrl}"` : ""}`;
|
||||
|
||||
// Add bottomless replication environment variables if destination is configured
|
||||
if (enableBottomlessReplication && bottomlessReplicationDestination) {
|
||||
defaultLibsqlEnv += `\nLIBSQL_BOTTOMLESS_DATABASE_ID="${appName}"`;
|
||||
defaultLibsqlEnv += `\nLIBSQL_BOTTOMLESS_BUCKET="${bottomlessReplicationDestination.bucket}"`;
|
||||
defaultLibsqlEnv += `\nLIBSQL_BOTTOMLESS_ENDPOINT="${bottomlessReplicationDestination.endpoint}"`;
|
||||
defaultLibsqlEnv += `\nLIBSQL_BOTTOMLESS_AWS_SECRET_ACCESS_KEY="${bottomlessReplicationDestination.secretAccessKey}"`;
|
||||
defaultLibsqlEnv += `\nLIBSQL_BOTTOMLESS_AWS_ACCESS_KEY_ID="${bottomlessReplicationDestination.accessKey}"`;
|
||||
defaultLibsqlEnv += `\nLIBSQL_BOTTOMLESS_AWS_DEFAULT_REGION="${bottomlessReplicationDestination.region}"`;
|
||||
}
|
||||
|
||||
const {
|
||||
HealthCheck,
|
||||
RestartPolicy,
|
||||
@@ -103,6 +119,9 @@ export const buildLibsql = async (libsql: LibsqlNested) => {
|
||||
if (enableNamespaces) {
|
||||
finalCommand += " --enable-namespaces";
|
||||
}
|
||||
if (enableBottomlessReplication) {
|
||||
finalCommand += " --enable-bottomless-replication";
|
||||
}
|
||||
|
||||
const settings: CreateServiceOptions = {
|
||||
Name: appName,
|
||||
|
||||
Reference in New Issue
Block a user