mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-25 17:15:22 +02:00
feat(multi-server): add actions to the server
This commit is contained in:
@@ -149,27 +149,39 @@ export const getContainerByName = (name: string): Promise<ContainerInfo> => {
|
||||
});
|
||||
});
|
||||
};
|
||||
export const cleanUpUnusedImages = async () => {
|
||||
export const cleanUpUnusedImages = async (serverId?: string) => {
|
||||
try {
|
||||
await execAsync("docker image prune --all --force");
|
||||
if (serverId) {
|
||||
await execAsyncRemote(serverId, "docker image prune --all --force");
|
||||
} else {
|
||||
await execAsync("docker image prune --all --force");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const cleanStoppedContainers = async () => {
|
||||
export const cleanStoppedContainers = async (serverId?: string) => {
|
||||
try {
|
||||
await execAsync("docker container prune --force");
|
||||
if (serverId) {
|
||||
await execAsyncRemote(serverId, "docker container prune --force");
|
||||
} else {
|
||||
await execAsync("docker container prune --force");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const cleanUpUnusedVolumes = async () => {
|
||||
export const cleanUpUnusedVolumes = async (serverId?: string) => {
|
||||
try {
|
||||
await execAsync("docker volume prune --all --force");
|
||||
if (serverId) {
|
||||
await execAsyncRemote(serverId, "docker volume prune --all --force");
|
||||
} else {
|
||||
await execAsync("docker volume prune --all --force");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
@@ -193,12 +205,23 @@ export const cleanUpInactiveContainers = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const cleanUpDockerBuilder = async () => {
|
||||
await execAsync("docker builder prune --all --force");
|
||||
export const cleanUpDockerBuilder = async (serverId?: string) => {
|
||||
if (serverId) {
|
||||
await execAsyncRemote(serverId, "docker builder prune --all --force");
|
||||
} else {
|
||||
await execAsync("docker builder prune --all --force");
|
||||
}
|
||||
};
|
||||
|
||||
export const cleanUpSystemPrune = async () => {
|
||||
await execAsync("docker system prune --all --force --volumes");
|
||||
export const cleanUpSystemPrune = async (serverId?: string) => {
|
||||
if (serverId) {
|
||||
await execAsyncRemote(
|
||||
serverId,
|
||||
"docker system prune --all --force --volumes",
|
||||
);
|
||||
} else {
|
||||
await execAsync("docker system prune --all --force --volumes");
|
||||
}
|
||||
};
|
||||
|
||||
export const startService = async (appName: string) => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { paths } from "@/server/constants";
|
||||
import { dump, load } from "js-yaml";
|
||||
import { execAsyncRemote } from "../process/execAsync";
|
||||
import type { FileConfig, HttpLoadBalancerService } from "./file-types";
|
||||
import { encodeBase64 } from "../docker/utils";
|
||||
|
||||
export const createTraefikConfig = (appName: string) => {
|
||||
const defaultPort = 3000;
|
||||
@@ -146,8 +147,14 @@ export const readMonitoringConfig = () => {
|
||||
return null;
|
||||
};
|
||||
|
||||
export const readConfigInPath = (pathFile: string) => {
|
||||
export const readConfigInPath = async (pathFile: string, serverId?: string) => {
|
||||
const configPath = path.join(pathFile);
|
||||
|
||||
if (serverId) {
|
||||
const { stdout } = await execAsyncRemote(serverId, `cat ${configPath}`);
|
||||
if (!stdout) return null;
|
||||
return stdout;
|
||||
}
|
||||
if (fs.existsSync(configPath)) {
|
||||
const yamlStr = fs.readFileSync(configPath, "utf8");
|
||||
return yamlStr;
|
||||
@@ -179,12 +186,22 @@ export const writeConfigRemote = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const writeTraefikConfigInPath = (
|
||||
export const writeTraefikConfigInPath = async (
|
||||
pathFile: string,
|
||||
traefikConfig: string,
|
||||
serverId?: string,
|
||||
) => {
|
||||
try {
|
||||
const configPath = path.join(pathFile);
|
||||
if (serverId) {
|
||||
const encoded = encodeBase64(traefikConfig);
|
||||
await execAsyncRemote(
|
||||
serverId,
|
||||
`echo "${encoded}" | base64 -d > "${configPath}"`,
|
||||
);
|
||||
} else {
|
||||
fs.writeFileSync(configPath, traefikConfig, "utf8");
|
||||
}
|
||||
fs.writeFileSync(configPath, traefikConfig, "utf8");
|
||||
} catch (e) {
|
||||
console.error("Error saving the YAML config file:", e);
|
||||
|
||||
Reference in New Issue
Block a user