mirror of
https://github.com/ershisan99/coolify.git
synced 2025-12-26 12:33:25 +00:00
feat: working on remote docker engine
This commit is contained in:
@@ -72,7 +72,7 @@ export async function getApplication(request: FastifyRequest<OnlyId>) {
|
||||
let isExited = false;
|
||||
const application: any = await getApplicationFromDB(id, teamId);
|
||||
if (application?.destinationDockerId && application.destinationDocker?.engine) {
|
||||
isRunning = await checkContainer(application.destinationDocker.engine, id);
|
||||
isRunning = await checkContainer({ dockerId: application.destinationDocker.id, container: id });
|
||||
isExited = await isContainerExited(application.destinationDocker.engine, id);
|
||||
}
|
||||
return {
|
||||
@@ -285,10 +285,10 @@ export async function stopApplication(request: FastifyRequest<OnlyId>, reply: Fa
|
||||
const { teamId } = request.user
|
||||
const application: any = await getApplicationFromDB(id, teamId);
|
||||
if (application?.destinationDockerId && application.destinationDocker?.engine) {
|
||||
const { engine } = application.destinationDocker;
|
||||
const found = await checkContainer(engine, id);
|
||||
const { engine, id: dockerId } = application.destinationDocker;
|
||||
const found = await checkContainer({ dockerId, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: application.destinationDocker.id });
|
||||
}
|
||||
}
|
||||
return reply.code(201).send();
|
||||
@@ -314,7 +314,7 @@ export async function deleteApplication(request: FastifyRequest<DeleteApplicatio
|
||||
for (const container of containersArray) {
|
||||
const containerObj = JSON.parse(container);
|
||||
const id = containerObj.ID;
|
||||
await removeContainer({ id, engine: application.destinationDocker.engine });
|
||||
await removeContainer({ id, dockerId: application.destinationDocker.id });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,7 +375,7 @@ export async function getUsage(request) {
|
||||
|
||||
const application: any = await getApplicationFromDB(id, teamId);
|
||||
if (application.destinationDockerId) {
|
||||
[usage] = await Promise.all([getContainerUsage(application.destinationDocker.engine, id)]);
|
||||
[usage] = await Promise.all([getContainerUsage(application.destinationDocker.id, id)]);
|
||||
}
|
||||
return {
|
||||
usage
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { FastifyRequest } from 'fastify';
|
||||
import { FastifyReply } from 'fastify';
|
||||
import yaml from 'js-yaml';
|
||||
import fs from 'fs/promises';
|
||||
import { asyncExecShell, ComposeFile, createDirectories, decrypt, encrypt, errorHandler, generateDatabaseConfiguration, generatePassword, getContainerUsage, getDatabaseImage, getDatabaseVersions, getFreePort, listSettings, makeLabelForStandaloneDatabase, prisma, startTcpProxy, startTraefikTCPProxy, stopDatabaseContainer, stopTcpHttpProxy, supportedDatabaseTypesAndVersions, uniqueName, updatePasswordInDb } from '../../../../lib/common';
|
||||
import { asyncExecShell, ComposeFile, createDirectories, decrypt, encrypt, errorHandler, executeDockerCmd, generateDatabaseConfiguration, generatePassword, getContainerUsage, getDatabaseImage, getDatabaseVersions, getFreePort, listSettings, makeLabelForStandaloneDatabase, prisma, startTraefikTCPProxy, stopDatabaseContainer, stopTcpHttpProxy, supportedDatabaseTypesAndVersions, uniqueName, updatePasswordInDb } from '../../../../lib/common';
|
||||
import { dockerInstance, getEngine } from '../../../../lib/docker';
|
||||
import { day } from '../../../../lib/dayjs';
|
||||
import { GetDatabaseLogs, OnlyId, SaveDatabase, SaveDatabaseDestination, SaveDatabaseSettings, SaveVersion } from '../../../../types';
|
||||
@@ -56,6 +56,36 @@ export async function newDatabase(request: FastifyRequest, reply: FastifyReply)
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
}
|
||||
export async function getDatabaseStatus(request: FastifyRequest<OnlyId>) {
|
||||
try {
|
||||
const { id } = request.params;
|
||||
const teamId = request.user.teamId;
|
||||
let isRunning = false;
|
||||
|
||||
const database = await prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId === '0' ? undefined : teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
const { destinationDockerId, destinationDocker } = database;
|
||||
if (destinationDockerId) {
|
||||
try {
|
||||
const { stdout } = await executeDockerCmd({ dockerId: destinationDocker.id, command: `docker inspect --format '{{json .State}}' ${id}` })
|
||||
|
||||
if (JSON.parse(stdout).Running) {
|
||||
isRunning = true;
|
||||
}
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
}
|
||||
return {
|
||||
isRunning
|
||||
}
|
||||
} catch ({ status, message }) {
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDatabase(request: FastifyRequest<OnlyId>) {
|
||||
try {
|
||||
const { id } = request.params;
|
||||
@@ -68,30 +98,12 @@ export async function getDatabase(request: FastifyRequest<OnlyId>) {
|
||||
throw { status: 404, message: 'Database not found.' }
|
||||
}
|
||||
if (database.dbUserPassword) database.dbUserPassword = decrypt(database.dbUserPassword);
|
||||
if (database.rootUserPassword) database.rootUserPassword = decrypt(database.rootUserPassword);
|
||||
const { destinationDockerId, destinationDocker } = database;
|
||||
let isRunning = false;
|
||||
if (destinationDockerId) {
|
||||
const host = getEngine(destinationDocker.engine);
|
||||
|
||||
try {
|
||||
const { stdout } = await asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker inspect --format '{{json .State}}' ${id}`
|
||||
);
|
||||
|
||||
if (JSON.parse(stdout).Running) {
|
||||
isRunning = true;
|
||||
}
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
}
|
||||
if (database.rootUserPassword) database.rootUserPassword = decrypt(database.rootUserPassword);
|
||||
const configuration = generateDatabaseConfiguration(database);
|
||||
const settings = await listSettings();
|
||||
return {
|
||||
privatePort: configuration?.privatePort,
|
||||
database,
|
||||
isRunning,
|
||||
versions: await getDatabaseVersions(database.type),
|
||||
settings
|
||||
};
|
||||
@@ -164,16 +176,15 @@ export async function saveDatabaseDestination(request: FastifyRequest<SaveDataba
|
||||
|
||||
const {
|
||||
destinationDockerId,
|
||||
destinationDocker: { engine },
|
||||
destinationDocker: { engine, id: dockerId },
|
||||
version,
|
||||
type
|
||||
} = await prisma.database.findUnique({ where: { id }, include: { destinationDocker: true } });
|
||||
|
||||
if (destinationDockerId) {
|
||||
const host = getEngine(engine);
|
||||
if (type && version) {
|
||||
const baseImage = getDatabaseImage(type);
|
||||
asyncExecShell(`DOCKER_HOST=${host} docker pull ${baseImage}:${version}`);
|
||||
executeDockerCmd({ dockerId, command: `docker pull ${baseImage}:${version}` })
|
||||
}
|
||||
}
|
||||
return reply.code(201).send({})
|
||||
@@ -194,7 +205,7 @@ export async function getDatabaseUsage(request: FastifyRequest<OnlyId>) {
|
||||
if (database.dbUserPassword) database.dbUserPassword = decrypt(database.dbUserPassword);
|
||||
if (database.rootUserPassword) database.rootUserPassword = decrypt(database.rootUserPassword);
|
||||
if (database.destinationDockerId) {
|
||||
[usage] = await Promise.all([getContainerUsage(database.destinationDocker.engine, id)]);
|
||||
[usage] = await Promise.all([getContainerUsage(database.destinationDocker.id, id)]);
|
||||
}
|
||||
return {
|
||||
usage
|
||||
@@ -267,13 +278,13 @@ export async function startDatabase(request: FastifyRequest<OnlyId>) {
|
||||
const composeFileDestination = `${workdir}/docker-compose.yaml`;
|
||||
await fs.writeFile(composeFileDestination, yaml.dump(composeFile));
|
||||
try {
|
||||
await asyncExecShell(`DOCKER_HOST=${host} docker volume create ${volumeName}`);
|
||||
await executeDockerCmd({ dockerId: destinationDocker.id, command: `docker volume create ${volumeName}` })
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
try {
|
||||
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
||||
if (isPublic) await startTcpProxy(destinationDocker, id, publicPort, privatePort);
|
||||
await executeDockerCmd({ dockerId: destinationDocker.id, command: `docker compose -f ${composeFileDestination} up -d` })
|
||||
if (isPublic) await startTraefikTCPProxy(destinationDocker, id, publicPort, privatePort);
|
||||
return {};
|
||||
} catch (error) {
|
||||
throw {
|
||||
@@ -453,11 +464,7 @@ export async function saveDatabaseSettings(request: FastifyRequest<SaveDatabaseS
|
||||
if (destinationDockerId) {
|
||||
if (isPublic) {
|
||||
await prisma.database.update({ where: { id }, data: { publicPort } });
|
||||
if (settings.isTraefikUsed) {
|
||||
await startTraefikTCPProxy(destinationDocker, id, publicPort, privatePort);
|
||||
} else {
|
||||
await startTcpProxy(destinationDocker, id, publicPort, privatePort);
|
||||
}
|
||||
await startTraefikTCPProxy(destinationDocker, id, publicPort, privatePort);
|
||||
} else {
|
||||
await prisma.database.update({ where: { id }, data: { publicPort: null } });
|
||||
await stopTcpHttpProxy(id, destinationDocker, oldPublicPort);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { FastifyPluginAsync } from 'fastify';
|
||||
import { deleteDatabase, getDatabase, getDatabaseLogs, getDatabaseTypes, getDatabaseUsage, getVersions, listDatabases, newDatabase, saveDatabase, saveDatabaseDestination, saveDatabaseSettings, saveDatabaseType, saveVersion, startDatabase, stopDatabase } from './handlers';
|
||||
import { deleteDatabase, getDatabase, getDatabaseLogs, getDatabaseStatus, getDatabaseTypes, getDatabaseUsage, getVersions, listDatabases, newDatabase, saveDatabase, saveDatabaseDestination, saveDatabaseSettings, saveDatabaseType, saveVersion, startDatabase, stopDatabase } from './handlers';
|
||||
|
||||
import type { GetDatabaseLogs, OnlyId, SaveDatabase, SaveDatabaseDestination, SaveDatabaseSettings, SaveVersion } from '../../../../types';
|
||||
import type { SaveDatabaseType } from './types';
|
||||
@@ -12,6 +12,7 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {
|
||||
fastify.post('/new', async (request, reply) => await newDatabase(request, reply));
|
||||
|
||||
fastify.get<OnlyId>('/:id', async (request) => await getDatabase(request));
|
||||
fastify.get<OnlyId>('/:id/status', async (request) => await getDatabaseStatus(request));
|
||||
fastify.post<SaveDatabase>('/:id', async (request, reply) => await saveDatabase(request, reply));
|
||||
fastify.delete<OnlyId>('/:id', async (request) => await deleteDatabase(request));
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { FastifyRequest } from 'fastify';
|
||||
import { FastifyReply } from 'fastify';
|
||||
import sshConfig from 'ssh-config'
|
||||
import fs from 'fs/promises'
|
||||
import { asyncExecShell, decrypt, errorHandler, listSettings, prisma, startCoolifyProxy, startTraefikProxy, stopTraefikProxy } from '../../../../lib/common';
|
||||
import { asyncExecShell, decrypt, errorHandler, listSettings, prisma, startTraefikProxy, stopTraefikProxy } from '../../../../lib/common';
|
||||
import { checkContainer, dockerInstance, getEngine } from '../../../../lib/docker';
|
||||
|
||||
import type { OnlyId } from '../../../../types';
|
||||
@@ -55,23 +55,8 @@ export async function getDestination(request: FastifyRequest<OnlyId>) {
|
||||
const settings = await listSettings();
|
||||
let payload = {
|
||||
destination,
|
||||
settings,
|
||||
state: false
|
||||
settings
|
||||
};
|
||||
|
||||
if (destination?.remoteEngine) {
|
||||
// const { stdout } = await asyncExecShell(
|
||||
// `ssh -p ${destination.port} ${destination.user}@${destination.ipAddress} "docker ps -a"`
|
||||
// );
|
||||
// console.log(stdout)
|
||||
// const engine = await generateRemoteEngine(destination);
|
||||
// // await saveSshKey(destination);
|
||||
// payload.state = await checkContainer(engine, 'coolify-haproxy');
|
||||
} else {
|
||||
const containerName = 'coolify-proxy';
|
||||
payload.state =
|
||||
destination?.engine && (await checkContainer(destination.engine, containerName));
|
||||
}
|
||||
return {
|
||||
...payload
|
||||
};
|
||||
@@ -83,7 +68,7 @@ export async function getDestination(request: FastifyRequest<OnlyId>) {
|
||||
export async function newDestination(request: FastifyRequest<NewDestination>, reply: FastifyReply) {
|
||||
try {
|
||||
const { id } = request.params
|
||||
let { name, network, engine, isCoolifyProxyUsed, ipAddress, user, port, sshPrivateKey } = request.body
|
||||
let { name, network, engine, isCoolifyProxyUsed, remoteIpAddress, remoteUser, remotePort } = request.body
|
||||
const teamId = request.user.teamId;
|
||||
if (id === 'new') {
|
||||
if (engine) {
|
||||
@@ -111,16 +96,14 @@ export async function newDestination(request: FastifyRequest<NewDestination>, re
|
||||
if (isCoolifyProxyUsed) {
|
||||
const settings = await prisma.setting.findFirst();
|
||||
if (settings?.isTraefikUsed) {
|
||||
await startTraefikProxy(engine);
|
||||
} else {
|
||||
await startCoolifyProxy(engine);
|
||||
await startTraefikProxy(id);
|
||||
}
|
||||
}
|
||||
return reply.code(201).send({ id: destination.id });
|
||||
}
|
||||
if (ipAddress) {
|
||||
if (remoteIpAddress) {
|
||||
await prisma.destinationDocker.create({
|
||||
data: { name, teams: { connect: { id: teamId } }, engine, network, isCoolifyProxyUsed, remoteEngine: true, remoteIpAddress: ipAddress, remoteUser: user, remotePort: port }
|
||||
data: { name, teams: { connect: { id: teamId } }, engine, network, isCoolifyProxyUsed, remoteEngine: true, remoteIpAddress, remoteUser, remotePort }
|
||||
});
|
||||
return reply.code(201).send()
|
||||
|
||||
@@ -180,35 +163,39 @@ export async function saveDestinationSettings(request: FastifyRequest<SaveDestin
|
||||
}
|
||||
}
|
||||
export async function startProxy(request: FastifyRequest<Proxy>) {
|
||||
const { engine } = request.body;
|
||||
const { id } = request.params
|
||||
try {
|
||||
await startTraefikProxy(engine);
|
||||
await startTraefikProxy(id);
|
||||
return {}
|
||||
} catch ({ status, message }) {
|
||||
await stopTraefikProxy(engine);
|
||||
await stopTraefikProxy(id);
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
}
|
||||
export async function stopProxy(request: FastifyRequest<Proxy>) {
|
||||
const { engine } = request.body;
|
||||
const { id } = request.params
|
||||
try {
|
||||
await stopTraefikProxy(engine);
|
||||
await stopTraefikProxy(id);
|
||||
return {}
|
||||
} catch ({ status, message }) {
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
}
|
||||
export async function restartProxy(request: FastifyRequest<Proxy>) {
|
||||
const { engine } = request.body;
|
||||
const { id } = request.params
|
||||
try {
|
||||
await stopTraefikProxy(engine);
|
||||
await startTraefikProxy(engine);
|
||||
await prisma.destinationDocker.updateMany({
|
||||
where: { engine },
|
||||
await stopTraefikProxy(id);
|
||||
await startTraefikProxy(id);
|
||||
await prisma.destinationDocker.update({
|
||||
where: { id },
|
||||
data: { isCoolifyProxyUsed: true }
|
||||
});
|
||||
return {}
|
||||
} catch ({ status, message }) {
|
||||
await prisma.destinationDocker.update({
|
||||
where: { id },
|
||||
data: { isCoolifyProxyUsed: false }
|
||||
});
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
}
|
||||
@@ -217,7 +204,6 @@ export async function assignSSHKey(request: FastifyRequest) {
|
||||
try {
|
||||
const { id: sshKeyId } = request.body;
|
||||
const { id } = request.params;
|
||||
console.log({ id, sshKeyId })
|
||||
await prisma.destinationDocker.update({ where: { id }, data: { sshKey: { connect: { id: sshKeyId } } } })
|
||||
return {}
|
||||
} catch ({ status, message }) {
|
||||
@@ -254,3 +240,16 @@ export async function verifyRemoteDockerEngine(request: FastifyRequest, reply: F
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDestinationStatus(request: FastifyRequest<OnlyId>) {
|
||||
try {
|
||||
const { id } = request.params
|
||||
const destination = await prisma.destinationDocker.findUnique({ where: { id } })
|
||||
const containerName = 'coolify-proxy';
|
||||
return {
|
||||
isRunning: await checkContainer({ dockerId: destination.id, container: containerName })
|
||||
}
|
||||
} catch ({ status, message }) {
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { FastifyPluginAsync } from 'fastify';
|
||||
import { assignSSHKey, checkDestination, deleteDestination, getDestination, listDestinations, newDestination, restartProxy, saveDestinationSettings, startProxy, stopProxy, verifyRemoteDockerEngine } from './handlers';
|
||||
import { assignSSHKey, checkDestination, deleteDestination, getDestination, getDestinationStatus, listDestinations, newDestination, restartProxy, saveDestinationSettings, startProxy, stopProxy, verifyRemoteDockerEngine } from './handlers';
|
||||
|
||||
import type { OnlyId } from '../../../../types';
|
||||
import type { CheckDestination, NewDestination, Proxy, SaveDestinationSettings } from './types';
|
||||
@@ -14,6 +14,7 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {
|
||||
fastify.get<OnlyId>('/:id', async (request) => await getDestination(request));
|
||||
fastify.post<NewDestination>('/:id', async (request, reply) => await newDestination(request, reply));
|
||||
fastify.delete<OnlyId>('/:id', async (request) => await deleteDestination(request));
|
||||
fastify.get<OnlyId>('/:id/status', async (request) => await getDestinationStatus(request));
|
||||
|
||||
fastify.post<SaveDestinationSettings>('/:id/settings', async (request) => await saveDestinationSettings(request));
|
||||
fastify.post<Proxy>('/:id/start', async (request,) => await startProxy(request));
|
||||
|
||||
@@ -20,7 +20,5 @@ export interface SaveDestinationSettings extends OnlyId {
|
||||
}
|
||||
}
|
||||
export interface Proxy extends OnlyId {
|
||||
Body: {
|
||||
engine: string
|
||||
}
|
||||
|
||||
}
|
||||
@@ -282,7 +282,7 @@ export async function getServiceUsage(request: FastifyRequest<OnlyId>) {
|
||||
|
||||
const service = await getServiceFromDB({ id, teamId });
|
||||
if (service.destinationDockerId) {
|
||||
[usage] = await Promise.all([getContainerUsage(service.destinationDocker.engine, id)]);
|
||||
[usage] = await Promise.all([getContainerUsage(service.destinationDocker.id, id)]);
|
||||
}
|
||||
return {
|
||||
usage
|
||||
@@ -877,17 +877,17 @@ async function stopPlausibleAnalyticsService(request: FastifyRequest<ServiceStar
|
||||
if (destinationDockerId) {
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
let found = await checkContainer(engine, id);
|
||||
let found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
found = await checkContainer(engine, `${id}-postgresql`);
|
||||
found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-postgresql` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-postgresql`, engine });
|
||||
await removeContainer({ id: `${id}-postgresql`, dockerId: destinationDocker.id });
|
||||
}
|
||||
found = await checkContainer(engine, `${id}-clickhouse`);
|
||||
found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-clickhouse` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-clickhouse`, engine });
|
||||
await removeContainer({ id: `${id}-clickhouse`, dockerId: destinationDocker.id });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -971,9 +971,9 @@ async function stopNocodbService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const { destinationDockerId, destinationDocker, fqdn } = service;
|
||||
if (destinationDockerId) {
|
||||
const engine = destinationDocker.engine;
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
}
|
||||
return {}
|
||||
@@ -1075,9 +1075,9 @@ async function stopMinioService(request: FastifyRequest<ServiceStartStop>) {
|
||||
await prisma.minio.update({ where: { serviceId: id }, data: { publicPort: null } })
|
||||
if (destinationDockerId) {
|
||||
const engine = destinationDocker.engine;
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
}
|
||||
return {}
|
||||
@@ -1199,9 +1199,9 @@ async function stopVscodeService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const { destinationDockerId, destinationDocker, fqdn } = service;
|
||||
if (destinationDockerId) {
|
||||
const engine = destinationDocker.engine;
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
}
|
||||
return {}
|
||||
@@ -1348,26 +1348,26 @@ async function stopWordpressService(request: FastifyRequest<ServiceStartStop>) {
|
||||
if (destinationDockerId) {
|
||||
const engine = destinationDocker.engine;
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
try {
|
||||
const found = await checkContainer(engine, `${id}-mysql`);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-mysql` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-mysql`, engine });
|
||||
await removeContainer({ id: `${id}-mysql`, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
try {
|
||||
if (ftpEnabled) {
|
||||
const found = await checkContainer(engine, `${id}-ftp`);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-ftp` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-ftp`, engine });
|
||||
await removeContainer({ id: `${id}-ftp`, dockerId: destinationDocker.id });
|
||||
}
|
||||
await prisma.wordpress.update({
|
||||
where: { serviceId: id },
|
||||
@@ -1461,9 +1461,9 @@ async function stopVaultwardenService(request: FastifyRequest<ServiceStartStop>)
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -1553,9 +1553,9 @@ async function stopLanguageToolService(request: FastifyRequest<ServiceStartStop>
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -1645,9 +1645,9 @@ async function stopN8nService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -1736,9 +1736,9 @@ async function stopUptimekumaService(request: FastifyRequest<ServiceStartStop>)
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -1888,13 +1888,13 @@ async function stopGhostService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
let found = await checkContainer(engine, id);
|
||||
let found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
found = await checkContainer(engine, `${id}-mariadb`);
|
||||
found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-mariadb` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-mariadb`, engine });
|
||||
await removeContainer({ id: `${id}-mariadb`, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -1989,9 +1989,9 @@ async function stopMeilisearchService(request: FastifyRequest<ServiceStartStop>)
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -2208,17 +2208,17 @@ async function stopUmamiService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
try {
|
||||
const found = await checkContainer(engine, `${id}-postgresql`);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-postgresql` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-postgresql`, engine });
|
||||
await removeContainer({ id: `${id}-postgresql`, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -2344,17 +2344,17 @@ async function stopHasuraService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
try {
|
||||
const found = await checkContainer(engine, `${id}-postgresql`);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-postgresql` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-postgresql`, engine });
|
||||
await removeContainer({ id: `${id}-postgresql`, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -2507,17 +2507,17 @@ async function stopFiderService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
try {
|
||||
const found = await checkContainer(engine, `${id}-postgresql`);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-postgresql` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-postgresql`, engine });
|
||||
await removeContainer({ id: `${id}-postgresql`, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -2670,17 +2670,17 @@ async function stopMoodleService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const engine = destinationDocker.engine;
|
||||
|
||||
try {
|
||||
const found = await checkContainer(engine, id);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: id });
|
||||
if (found) {
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
try {
|
||||
const found = await checkContainer(engine, `${id}-mariadb`);
|
||||
const found = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-mariadb` });
|
||||
if (found) {
|
||||
await removeContainer({ id: `${id}-mariadb`, engine });
|
||||
await removeContainer({ id: `${id}-mariadb`, dockerId: destinationDocker.id });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -2789,7 +2789,7 @@ export async function activateWordpressFtp(request: FastifyRequest<ActivateWordp
|
||||
});
|
||||
|
||||
try {
|
||||
const isRunning = await checkContainer(engine, `${id}-ftp`);
|
||||
const isRunning = await checkContainer({ dockerId: destinationDocker.id, container: `${id}-ftp` });
|
||||
if (isRunning) {
|
||||
await asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker stop -t 0 ${id}-ftp && docker rm ${id}-ftp`
|
||||
|
||||
@@ -162,8 +162,10 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
|
||||
if (applicationFound.settings.previews) {
|
||||
if (applicationFound.destinationDockerId) {
|
||||
const isRunning = await checkContainer(
|
||||
applicationFound.destinationDocker.engine,
|
||||
applicationFound.id
|
||||
{
|
||||
dockerId: applicationFound.destinationDocker.engine,
|
||||
container: applicationFound.id
|
||||
}
|
||||
);
|
||||
if (!isRunning) {
|
||||
throw { status: 500, message: 'Application not running.' }
|
||||
@@ -205,7 +207,7 @@ export async function gitHubEvents(request: FastifyRequest<GitHubEvents>): Promi
|
||||
if (applicationFound.destinationDockerId) {
|
||||
const id = `${applicationFound.id}-${pullmergeRequestId}`;
|
||||
const engine = applicationFound.destinationDocker.engine;
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: applicationFound.destinationDocker.id });
|
||||
}
|
||||
return {
|
||||
message: 'Removed preview. Thank you!'
|
||||
|
||||
@@ -117,8 +117,10 @@ export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
|
||||
if (applicationFound.settings.previews) {
|
||||
if (applicationFound.destinationDockerId) {
|
||||
const isRunning = await checkContainer(
|
||||
applicationFound.destinationDocker.engine,
|
||||
applicationFound.id
|
||||
{
|
||||
dockerId: applicationFound.destinationDocker.engine,
|
||||
container: applicationFound.id
|
||||
}
|
||||
);
|
||||
if (!isRunning) {
|
||||
throw { status: 500, message: 'Application not running.' }
|
||||
@@ -164,7 +166,7 @@ export async function gitLabEvents(request: FastifyRequest<GitLabEvents>) {
|
||||
if (applicationFound.destinationDockerId) {
|
||||
const id = `${applicationFound.id}-${pullmergeRequestId}`;
|
||||
const engine = applicationFound.destinationDocker.engine;
|
||||
await removeContainer({ id, engine });
|
||||
await removeContainer({ id, dockerId: applicationFound.destinationDocker.id });
|
||||
}
|
||||
return {
|
||||
message: 'Removed preview. Thank you!'
|
||||
|
||||
Reference in New Issue
Block a user