fix: cleanupStuckedContainers
This commit is contained in:
@@ -0,0 +1,384 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var databases_exports = {};
|
||||
__export(databases_exports, {
|
||||
databasesRouter: () => databasesRouter
|
||||
});
|
||||
module.exports = __toCommonJS(databases_exports);
|
||||
var import_zod = require("zod");
|
||||
var import_promises = __toESM(require("fs/promises"));
|
||||
var import_trpc = require("../../trpc");
|
||||
var import_common = require("../../../lib/common");
|
||||
var import_prisma = require("../../../prisma");
|
||||
var import_executeCommand = require("../../../lib/executeCommand");
|
||||
var import_docker = require("../../../lib/docker");
|
||||
var import_lib = require("./lib");
|
||||
var import_js_yaml = __toESM(require("js-yaml"));
|
||||
var import_lib2 = require("../services/lib");
|
||||
const databasesRouter = (0, import_trpc.router)({
|
||||
usage: import_trpc.privateProcedure.input(
|
||||
import_zod.z.object({
|
||||
id: import_zod.z.string()
|
||||
})
|
||||
).query(async ({ ctx, input }) => {
|
||||
const teamId = ctx.user?.teamId;
|
||||
const { id } = input;
|
||||
let usage = {};
|
||||
const database = await import_prisma.prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
if (database.dbUserPassword)
|
||||
database.dbUserPassword = (0, import_common.decrypt)(database.dbUserPassword);
|
||||
if (database.rootUserPassword)
|
||||
database.rootUserPassword = (0, import_common.decrypt)(database.rootUserPassword);
|
||||
if (database.destinationDockerId) {
|
||||
[usage] = await Promise.all([(0, import_common.getContainerUsage)(database.destinationDocker.id, id)]);
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
usage
|
||||
}
|
||||
};
|
||||
}),
|
||||
save: import_trpc.privateProcedure.input(
|
||||
import_zod.z.object({
|
||||
id: import_zod.z.string()
|
||||
})
|
||||
).mutation(async ({ ctx, input }) => {
|
||||
const teamId = ctx.user?.teamId;
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
defaultDatabase,
|
||||
dbUser,
|
||||
dbUserPassword,
|
||||
rootUser,
|
||||
rootUserPassword,
|
||||
version,
|
||||
isRunning
|
||||
} = input;
|
||||
const database = await import_prisma.prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
if (database.dbUserPassword)
|
||||
database.dbUserPassword = (0, import_common.decrypt)(database.dbUserPassword);
|
||||
if (database.rootUserPassword)
|
||||
database.rootUserPassword = (0, import_common.decrypt)(database.rootUserPassword);
|
||||
if (isRunning) {
|
||||
if (database.dbUserPassword !== dbUserPassword) {
|
||||
await (0, import_lib.updatePasswordInDb)(database, dbUser, dbUserPassword, false);
|
||||
} else if (database.rootUserPassword !== rootUserPassword) {
|
||||
await (0, import_lib.updatePasswordInDb)(database, rootUser, rootUserPassword, true);
|
||||
}
|
||||
}
|
||||
const encryptedDbUserPassword = dbUserPassword && (0, import_common.encrypt)(dbUserPassword);
|
||||
const encryptedRootUserPassword = rootUserPassword && (0, import_common.encrypt)(rootUserPassword);
|
||||
await import_prisma.prisma.database.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name,
|
||||
defaultDatabase,
|
||||
dbUser,
|
||||
dbUserPassword: encryptedDbUserPassword,
|
||||
rootUser,
|
||||
rootUserPassword: encryptedRootUserPassword,
|
||||
version
|
||||
}
|
||||
});
|
||||
}),
|
||||
saveSettings: import_trpc.privateProcedure.input(
|
||||
import_zod.z.object({
|
||||
id: import_zod.z.string(),
|
||||
isPublic: import_zod.z.boolean(),
|
||||
appendOnly: import_zod.z.boolean().default(true)
|
||||
})
|
||||
).mutation(async ({ ctx, input }) => {
|
||||
const teamId = ctx.user?.teamId;
|
||||
const { id, isPublic, appendOnly = true } = input;
|
||||
let publicPort = null;
|
||||
const {
|
||||
destinationDocker: { remoteEngine, engine, remoteIpAddress }
|
||||
} = await import_prisma.prisma.database.findUnique({ where: { id }, include: { destinationDocker: true } });
|
||||
if (isPublic) {
|
||||
publicPort = await (0, import_lib2.getFreePublicPort)({ id, remoteEngine, engine, remoteIpAddress });
|
||||
}
|
||||
await import_prisma.prisma.database.update({
|
||||
where: { id },
|
||||
data: {
|
||||
settings: {
|
||||
upsert: { update: { isPublic, appendOnly }, create: { isPublic, appendOnly } }
|
||||
}
|
||||
}
|
||||
});
|
||||
const database = await import_prisma.prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
const { arch } = await (0, import_common.listSettings)();
|
||||
if (database.dbUserPassword)
|
||||
database.dbUserPassword = (0, import_common.decrypt)(database.dbUserPassword);
|
||||
if (database.rootUserPassword)
|
||||
database.rootUserPassword = (0, import_common.decrypt)(database.rootUserPassword);
|
||||
const { destinationDockerId, destinationDocker, publicPort: oldPublicPort } = database;
|
||||
const { privatePort } = (0, import_lib.generateDatabaseConfiguration)(database, arch);
|
||||
if (destinationDockerId) {
|
||||
if (isPublic) {
|
||||
await import_prisma.prisma.database.update({ where: { id }, data: { publicPort } });
|
||||
await (0, import_common.startTraefikTCPProxy)(destinationDocker, id, publicPort, privatePort);
|
||||
} else {
|
||||
await import_prisma.prisma.database.update({ where: { id }, data: { publicPort: null } });
|
||||
await (0, import_docker.stopTcpHttpProxy)(id, destinationDocker, oldPublicPort);
|
||||
}
|
||||
}
|
||||
return { publicPort };
|
||||
}),
|
||||
saveSecret: import_trpc.privateProcedure.input(
|
||||
import_zod.z.object({
|
||||
id: import_zod.z.string(),
|
||||
name: import_zod.z.string(),
|
||||
value: import_zod.z.string(),
|
||||
isNew: import_zod.z.boolean().default(true)
|
||||
})
|
||||
).mutation(async ({ ctx, input }) => {
|
||||
let { id, name, value, isNew } = input;
|
||||
if (isNew) {
|
||||
const found = await import_prisma.prisma.databaseSecret.findFirst({ where: { name, databaseId: id } });
|
||||
if (found) {
|
||||
throw `Secret ${name} already exists.`;
|
||||
} else {
|
||||
value = (0, import_common.encrypt)(value.trim());
|
||||
await import_prisma.prisma.databaseSecret.create({
|
||||
data: { name, value, database: { connect: { id } } }
|
||||
});
|
||||
}
|
||||
} else {
|
||||
value = (0, import_common.encrypt)(value.trim());
|
||||
const found = await import_prisma.prisma.databaseSecret.findFirst({ where: { databaseId: id, name } });
|
||||
if (found) {
|
||||
await import_prisma.prisma.databaseSecret.updateMany({
|
||||
where: { databaseId: id, name },
|
||||
data: { value }
|
||||
});
|
||||
} else {
|
||||
await import_prisma.prisma.databaseSecret.create({
|
||||
data: { name, value, database: { connect: { id } } }
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
start: import_trpc.privateProcedure.input(import_zod.z.object({ id: import_zod.z.string() })).mutation(async ({ ctx, input }) => {
|
||||
const { id } = input;
|
||||
const teamId = ctx.user?.teamId;
|
||||
const database = await import_prisma.prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { destinationDocker: true, settings: true, databaseSecret: true }
|
||||
});
|
||||
const { arch } = await (0, import_common.listSettings)();
|
||||
if (database.dbUserPassword)
|
||||
database.dbUserPassword = (0, import_common.decrypt)(database.dbUserPassword);
|
||||
if (database.rootUserPassword)
|
||||
database.rootUserPassword = (0, import_common.decrypt)(database.rootUserPassword);
|
||||
const {
|
||||
type,
|
||||
destinationDockerId,
|
||||
destinationDocker,
|
||||
publicPort,
|
||||
settings: { isPublic },
|
||||
databaseSecret
|
||||
} = database;
|
||||
const { privatePort, command, environmentVariables, image, volume, ulimits } = (0, import_lib.generateDatabaseConfiguration)(database, arch);
|
||||
const network = destinationDockerId && destinationDocker.network;
|
||||
const volumeName = volume.split(":")[0];
|
||||
const labels = await (0, import_lib.makeLabelForStandaloneDatabase)({ id, image, volume });
|
||||
const { workdir } = await (0, import_common.createDirectories)({ repository: type, buildId: id });
|
||||
if (databaseSecret.length > 0) {
|
||||
databaseSecret.forEach((secret) => {
|
||||
environmentVariables[secret.name] = (0, import_common.decrypt)(secret.value);
|
||||
});
|
||||
}
|
||||
const composeFile = {
|
||||
version: "3.8",
|
||||
services: {
|
||||
[id]: {
|
||||
container_name: id,
|
||||
image,
|
||||
command,
|
||||
environment: environmentVariables,
|
||||
volumes: [volume],
|
||||
ulimits,
|
||||
labels,
|
||||
...(0, import_docker.defaultComposeConfiguration)(network)
|
||||
}
|
||||
},
|
||||
networks: {
|
||||
[network]: {
|
||||
external: true
|
||||
}
|
||||
},
|
||||
volumes: {
|
||||
[volumeName]: {
|
||||
name: volumeName
|
||||
}
|
||||
}
|
||||
};
|
||||
const composeFileDestination = `${workdir}/docker-compose.yaml`;
|
||||
await import_promises.default.writeFile(composeFileDestination, import_js_yaml.default.dump(composeFile));
|
||||
await (0, import_executeCommand.executeCommand)({
|
||||
dockerId: destinationDocker.id,
|
||||
command: `docker compose -f ${composeFileDestination} up -d`
|
||||
});
|
||||
if (isPublic)
|
||||
await (0, import_common.startTraefikTCPProxy)(destinationDocker, id, publicPort, privatePort);
|
||||
}),
|
||||
stop: import_trpc.privateProcedure.input(import_zod.z.object({ id: import_zod.z.string() })).mutation(async ({ ctx, input }) => {
|
||||
const { id } = input;
|
||||
const teamId = ctx.user?.teamId;
|
||||
const database = await import_prisma.prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
if (database.dbUserPassword)
|
||||
database.dbUserPassword = (0, import_common.decrypt)(database.dbUserPassword);
|
||||
if (database.rootUserPassword)
|
||||
database.rootUserPassword = (0, import_common.decrypt)(database.rootUserPassword);
|
||||
const everStarted = await (0, import_docker.stopDatabaseContainer)(database);
|
||||
if (everStarted)
|
||||
await (0, import_docker.stopTcpHttpProxy)(id, database.destinationDocker, database.publicPort);
|
||||
await import_prisma.prisma.database.update({
|
||||
where: { id },
|
||||
data: {
|
||||
settings: { upsert: { update: { isPublic: false }, create: { isPublic: false } } }
|
||||
}
|
||||
});
|
||||
await import_prisma.prisma.database.update({ where: { id }, data: { publicPort: null } });
|
||||
}),
|
||||
getDatabaseById: import_trpc.privateProcedure.input(import_zod.z.object({ id: import_zod.z.string() })).query(async ({ ctx, input }) => {
|
||||
const { id } = input;
|
||||
const teamId = ctx.user?.teamId;
|
||||
const database = await import_prisma.prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
if (!database) {
|
||||
throw { status: 404, message: "Database not found." };
|
||||
}
|
||||
const settings = await (0, import_common.listSettings)();
|
||||
if (database.dbUserPassword)
|
||||
database.dbUserPassword = (0, import_common.decrypt)(database.dbUserPassword);
|
||||
if (database.rootUserPassword)
|
||||
database.rootUserPassword = (0, import_common.decrypt)(database.rootUserPassword);
|
||||
const configuration = (0, import_lib.generateDatabaseConfiguration)(database, settings.arch);
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
privatePort: configuration?.privatePort,
|
||||
database,
|
||||
versions: await (0, import_lib.getDatabaseVersions)(database.type, settings.arch),
|
||||
settings
|
||||
}
|
||||
};
|
||||
}),
|
||||
status: import_trpc.privateProcedure.input(import_zod.z.object({ id: import_zod.z.string() })).query(async ({ ctx, input }) => {
|
||||
const id = input.id;
|
||||
const teamId = ctx.user?.teamId;
|
||||
let isRunning = false;
|
||||
const database = await import_prisma.prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
if (database) {
|
||||
const { destinationDockerId, destinationDocker } = database;
|
||||
if (destinationDockerId) {
|
||||
try {
|
||||
const { stdout } = await (0, import_executeCommand.executeCommand)({
|
||||
dockerId: destinationDocker.id,
|
||||
command: `docker inspect --format '{{json .State}}' ${id}`
|
||||
});
|
||||
if (JSON.parse(stdout).Running) {
|
||||
isRunning = true;
|
||||
}
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
isRunning
|
||||
}
|
||||
};
|
||||
}),
|
||||
cleanup: import_trpc.privateProcedure.query(async ({ ctx }) => {
|
||||
const teamId = ctx.user?.teamId;
|
||||
let databases = await import_prisma.prisma.database.findMany({
|
||||
where: { teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { settings: true, destinationDocker: true, teams: true }
|
||||
});
|
||||
for (const database of databases) {
|
||||
if (!database?.version) {
|
||||
const { id } = database;
|
||||
if (database.destinationDockerId) {
|
||||
const everStarted = await (0, import_docker.stopDatabaseContainer)(database);
|
||||
if (everStarted)
|
||||
await (0, import_docker.stopTcpHttpProxy)(id, database.destinationDocker, database.publicPort);
|
||||
}
|
||||
await import_prisma.prisma.databaseSettings.deleteMany({ where: { databaseId: id } });
|
||||
await import_prisma.prisma.databaseSecret.deleteMany({ where: { databaseId: id } });
|
||||
await import_prisma.prisma.database.delete({ where: { id } });
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}),
|
||||
delete: import_trpc.privateProcedure.input(import_zod.z.object({ id: import_zod.z.string(), force: import_zod.z.boolean().default(false) })).mutation(async ({ ctx, input }) => {
|
||||
const { id, force } = input;
|
||||
const teamId = ctx.user?.teamId;
|
||||
const database = await import_prisma.prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === "0" ? void 0 : teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
if (!force) {
|
||||
if (database.dbUserPassword)
|
||||
database.dbUserPassword = (0, import_common.decrypt)(database.dbUserPassword);
|
||||
if (database.rootUserPassword)
|
||||
database.rootUserPassword = (0, import_common.decrypt)(database.rootUserPassword);
|
||||
if (database.destinationDockerId) {
|
||||
const everStarted = await (0, import_docker.stopDatabaseContainer)(database);
|
||||
if (everStarted)
|
||||
await (0, import_docker.stopTcpHttpProxy)(id, database.destinationDocker, database.publicPort);
|
||||
}
|
||||
}
|
||||
await import_prisma.prisma.databaseSettings.deleteMany({ where: { databaseId: id } });
|
||||
await import_prisma.prisma.databaseSecret.deleteMany({ where: { databaseId: id } });
|
||||
await import_prisma.prisma.database.delete({ where: { id } });
|
||||
return {};
|
||||
})
|
||||
});
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
databasesRouter
|
||||
});
|
||||
@@ -0,0 +1,316 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var lib_exports = {};
|
||||
__export(lib_exports, {
|
||||
generateDatabaseConfiguration: () => generateDatabaseConfiguration,
|
||||
getDatabaseImage: () => getDatabaseImage,
|
||||
getDatabaseVersions: () => getDatabaseVersions,
|
||||
makeLabelForStandaloneDatabase: () => makeLabelForStandaloneDatabase,
|
||||
supportedDatabaseTypesAndVersions: () => supportedDatabaseTypesAndVersions,
|
||||
updatePasswordInDb: () => updatePasswordInDb
|
||||
});
|
||||
module.exports = __toCommonJS(lib_exports);
|
||||
var import_common = require("../../../lib/common");
|
||||
var import_executeCommand = require("../../../lib/executeCommand");
|
||||
var import_prisma = require("../../../prisma");
|
||||
const supportedDatabaseTypesAndVersions = [
|
||||
{
|
||||
name: "mongodb",
|
||||
fancyName: "MongoDB",
|
||||
baseImage: "bitnami/mongodb",
|
||||
baseImageARM: "mongo",
|
||||
versions: ["5.0", "4.4", "4.2"],
|
||||
versionsARM: ["5.0", "4.4", "4.2"]
|
||||
},
|
||||
{
|
||||
name: "mysql",
|
||||
fancyName: "MySQL",
|
||||
baseImage: "bitnami/mysql",
|
||||
baseImageARM: "mysql",
|
||||
versions: ["8.0", "5.7"],
|
||||
versionsARM: ["8.0", "5.7"]
|
||||
},
|
||||
{
|
||||
name: "mariadb",
|
||||
fancyName: "MariaDB",
|
||||
baseImage: "bitnami/mariadb",
|
||||
baseImageARM: "mariadb",
|
||||
versions: ["10.8", "10.7", "10.6", "10.5", "10.4", "10.3", "10.2"],
|
||||
versionsARM: ["10.8", "10.7", "10.6", "10.5", "10.4", "10.3", "10.2"]
|
||||
},
|
||||
{
|
||||
name: "postgresql",
|
||||
fancyName: "PostgreSQL",
|
||||
baseImage: "bitnami/postgresql",
|
||||
baseImageARM: "postgres",
|
||||
versions: ["14.5.0", "13.8.0", "12.12.0", "11.17.0", "10.22.0"],
|
||||
versionsARM: ["14.5", "13.8", "12.12", "11.17", "10.22"]
|
||||
},
|
||||
{
|
||||
name: "redis",
|
||||
fancyName: "Redis",
|
||||
baseImage: "bitnami/redis",
|
||||
baseImageARM: "redis",
|
||||
versions: ["7.0", "6.2", "6.0", "5.0"],
|
||||
versionsARM: ["7.0", "6.2", "6.0", "5.0"]
|
||||
},
|
||||
{
|
||||
name: "couchdb",
|
||||
fancyName: "CouchDB",
|
||||
baseImage: "bitnami/couchdb",
|
||||
baseImageARM: "couchdb",
|
||||
versions: ["3.2.2", "3.1.2", "2.3.1"],
|
||||
versionsARM: ["3.2.2", "3.1.2", "2.3.1"]
|
||||
},
|
||||
{
|
||||
name: "edgedb",
|
||||
fancyName: "EdgeDB",
|
||||
baseImage: "edgedb/edgedb",
|
||||
versions: ["latest", "2.1", "2.0", "1.4"]
|
||||
}
|
||||
];
|
||||
function getDatabaseImage(type, arch) {
|
||||
const found = supportedDatabaseTypesAndVersions.find((t) => t.name === type);
|
||||
if (found) {
|
||||
if ((0, import_common.isARM)(arch)) {
|
||||
return found.baseImageARM || found.baseImage;
|
||||
}
|
||||
return found.baseImage;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function generateDatabaseConfiguration(database, arch) {
|
||||
const { id, dbUser, dbUserPassword, rootUser, rootUserPassword, defaultDatabase, version: version2, type } = database;
|
||||
const baseImage = getDatabaseImage(type, arch);
|
||||
if (type === "mysql") {
|
||||
const configuration = {
|
||||
privatePort: 3306,
|
||||
environmentVariables: {
|
||||
MYSQL_USER: dbUser,
|
||||
MYSQL_PASSWORD: dbUserPassword,
|
||||
MYSQL_ROOT_PASSWORD: rootUserPassword,
|
||||
MYSQL_ROOT_USER: rootUser,
|
||||
MYSQL_DATABASE: defaultDatabase
|
||||
},
|
||||
image: `${baseImage}:${version2}`,
|
||||
volume: `${id}-${type}-data:/bitnami/mysql/data`,
|
||||
ulimits: {}
|
||||
};
|
||||
if ((0, import_common.isARM)(arch)) {
|
||||
configuration.volume = `${id}-${type}-data:/var/lib/mysql`;
|
||||
}
|
||||
return configuration;
|
||||
} else if (type === "mariadb") {
|
||||
const configuration = {
|
||||
privatePort: 3306,
|
||||
environmentVariables: {
|
||||
MARIADB_ROOT_USER: rootUser,
|
||||
MARIADB_ROOT_PASSWORD: rootUserPassword,
|
||||
MARIADB_USER: dbUser,
|
||||
MARIADB_PASSWORD: dbUserPassword,
|
||||
MARIADB_DATABASE: defaultDatabase
|
||||
},
|
||||
image: `${baseImage}:${version2}`,
|
||||
volume: `${id}-${type}-data:/bitnami/mariadb`,
|
||||
ulimits: {}
|
||||
};
|
||||
if ((0, import_common.isARM)(arch)) {
|
||||
configuration.volume = `${id}-${type}-data:/var/lib/mysql`;
|
||||
}
|
||||
return configuration;
|
||||
} else if (type === "mongodb") {
|
||||
const configuration = {
|
||||
privatePort: 27017,
|
||||
environmentVariables: {
|
||||
MONGODB_ROOT_USER: rootUser,
|
||||
MONGODB_ROOT_PASSWORD: rootUserPassword
|
||||
},
|
||||
image: `${baseImage}:${version2}`,
|
||||
volume: `${id}-${type}-data:/bitnami/mongodb`,
|
||||
ulimits: {}
|
||||
};
|
||||
if ((0, import_common.isARM)(arch)) {
|
||||
configuration.environmentVariables = {
|
||||
MONGO_INITDB_ROOT_USERNAME: rootUser,
|
||||
MONGO_INITDB_ROOT_PASSWORD: rootUserPassword
|
||||
};
|
||||
configuration.volume = `${id}-${type}-data:/data/db`;
|
||||
}
|
||||
return configuration;
|
||||
} else if (type === "postgresql") {
|
||||
const configuration = {
|
||||
privatePort: 5432,
|
||||
environmentVariables: {
|
||||
POSTGRESQL_POSTGRES_PASSWORD: rootUserPassword,
|
||||
POSTGRESQL_PASSWORD: dbUserPassword,
|
||||
POSTGRESQL_USERNAME: dbUser,
|
||||
POSTGRESQL_DATABASE: defaultDatabase
|
||||
},
|
||||
image: `${baseImage}:${version2}`,
|
||||
volume: `${id}-${type}-data:/bitnami/postgresql`,
|
||||
ulimits: {}
|
||||
};
|
||||
if ((0, import_common.isARM)(arch)) {
|
||||
configuration.volume = `${id}-${type}-data:/var/lib/postgresql`;
|
||||
configuration.environmentVariables = {
|
||||
POSTGRES_PASSWORD: dbUserPassword,
|
||||
POSTGRES_USER: dbUser,
|
||||
POSTGRES_DB: defaultDatabase
|
||||
};
|
||||
}
|
||||
return configuration;
|
||||
} else if (type === "redis") {
|
||||
const {
|
||||
settings: { appendOnly }
|
||||
} = database;
|
||||
const configuration = {
|
||||
privatePort: 6379,
|
||||
command: void 0,
|
||||
environmentVariables: {
|
||||
REDIS_PASSWORD: dbUserPassword,
|
||||
REDIS_AOF_ENABLED: appendOnly ? "yes" : "no"
|
||||
},
|
||||
image: `${baseImage}:${version2}`,
|
||||
volume: `${id}-${type}-data:/bitnami/redis/data`,
|
||||
ulimits: {}
|
||||
};
|
||||
if ((0, import_common.isARM)(arch)) {
|
||||
configuration.volume = `${id}-${type}-data:/data`;
|
||||
configuration.command = `/usr/local/bin/redis-server --appendonly ${appendOnly ? "yes" : "no"} --requirepass ${dbUserPassword}`;
|
||||
}
|
||||
return configuration;
|
||||
} else if (type === "couchdb") {
|
||||
const configuration = {
|
||||
privatePort: 5984,
|
||||
environmentVariables: {
|
||||
COUCHDB_PASSWORD: dbUserPassword,
|
||||
COUCHDB_USER: dbUser
|
||||
},
|
||||
image: `${baseImage}:${version2}`,
|
||||
volume: `${id}-${type}-data:/bitnami/couchdb`,
|
||||
ulimits: {}
|
||||
};
|
||||
if ((0, import_common.isARM)(arch)) {
|
||||
configuration.volume = `${id}-${type}-data:/opt/couchdb/data`;
|
||||
}
|
||||
return configuration;
|
||||
} else if (type === "edgedb") {
|
||||
const configuration = {
|
||||
privatePort: 5656,
|
||||
environmentVariables: {
|
||||
EDGEDB_SERVER_PASSWORD: rootUserPassword,
|
||||
EDGEDB_SERVER_USER: rootUser,
|
||||
EDGEDB_SERVER_DATABASE: defaultDatabase,
|
||||
EDGEDB_SERVER_TLS_CERT_MODE: "generate_self_signed"
|
||||
},
|
||||
image: `${baseImage}:${version2}`,
|
||||
volume: `${id}-${type}-data:/var/lib/edgedb/data`,
|
||||
ulimits: {}
|
||||
};
|
||||
return configuration;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getDatabaseVersions(type, arch) {
|
||||
const found = supportedDatabaseTypesAndVersions.find((t) => t.name === type);
|
||||
if (found) {
|
||||
if ((0, import_common.isARM)(arch)) {
|
||||
return found.versionsARM || found.versions;
|
||||
}
|
||||
return found.versions;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
async function updatePasswordInDb(database, user, newPassword, isRoot) {
|
||||
const {
|
||||
id,
|
||||
type,
|
||||
rootUser,
|
||||
rootUserPassword,
|
||||
dbUser,
|
||||
dbUserPassword,
|
||||
defaultDatabase,
|
||||
destinationDockerId,
|
||||
destinationDocker: { id: dockerId }
|
||||
} = database;
|
||||
if (destinationDockerId) {
|
||||
if (type === "mysql") {
|
||||
await (0, import_executeCommand.executeCommand)({
|
||||
dockerId,
|
||||
command: `docker exec ${id} mysql -u ${rootUser} -p${rootUserPassword} -e "ALTER USER '${user}'@'%' IDENTIFIED WITH caching_sha2_password BY '${newPassword}';"`
|
||||
});
|
||||
} else if (type === "mariadb") {
|
||||
await (0, import_executeCommand.executeCommand)({
|
||||
dockerId,
|
||||
command: `docker exec ${id} mysql -u ${rootUser} -p${rootUserPassword} -e "SET PASSWORD FOR '${user}'@'%' = PASSWORD('${newPassword}');"`
|
||||
});
|
||||
} else if (type === "postgresql") {
|
||||
if (isRoot) {
|
||||
await (0, import_executeCommand.executeCommand)({
|
||||
dockerId,
|
||||
command: `docker exec ${id} psql postgresql://postgres:${rootUserPassword}@${id}:5432/${defaultDatabase} -c "ALTER role postgres WITH PASSWORD '${newPassword}'"`
|
||||
});
|
||||
} else {
|
||||
await (0, import_executeCommand.executeCommand)({
|
||||
dockerId,
|
||||
command: `docker exec ${id} psql postgresql://${dbUser}:${dbUserPassword}@${id}:5432/${defaultDatabase} -c "ALTER role ${user} WITH PASSWORD '${newPassword}'"`
|
||||
});
|
||||
}
|
||||
} else if (type === "mongodb") {
|
||||
await (0, import_executeCommand.executeCommand)({
|
||||
dockerId,
|
||||
command: `docker exec ${id} mongo 'mongodb://${rootUser}:${rootUserPassword}@${id}:27017/admin?readPreference=primary&ssl=false' --eval "db.changeUserPassword('${user}','${newPassword}')"`
|
||||
});
|
||||
} else if (type === "redis") {
|
||||
await (0, import_executeCommand.executeCommand)({
|
||||
dockerId,
|
||||
command: `docker exec ${id} redis-cli -u redis://${dbUserPassword}@${id}:6379 --raw CONFIG SET requirepass ${newPassword}`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
async function makeLabelForStandaloneDatabase({ id, image, volume }) {
|
||||
const database = await import_prisma.prisma.database.findFirst({ where: { id } });
|
||||
delete database.destinationDockerId;
|
||||
delete database.createdAt;
|
||||
delete database.updatedAt;
|
||||
return [
|
||||
"coolify.managed=true",
|
||||
`coolify.version=${import_common.version}`,
|
||||
`coolify.type=standalone-database`,
|
||||
`coolify.name=${database.name}`,
|
||||
`coolify.configuration=${(0, import_common.base64Encode)(
|
||||
JSON.stringify({
|
||||
version: import_common.version,
|
||||
image,
|
||||
volume,
|
||||
...database
|
||||
})
|
||||
)}`
|
||||
];
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
generateDatabaseConfiguration,
|
||||
getDatabaseImage,
|
||||
getDatabaseVersions,
|
||||
makeLabelForStandaloneDatabase,
|
||||
supportedDatabaseTypesAndVersions,
|
||||
updatePasswordInDb
|
||||
});
|
||||
Reference in New Issue
Block a user