feat: add reload, stop and start in remote server

This commit is contained in:
Mauricio Siu
2024-09-09 23:46:24 -06:00
parent 95f75fdccb
commit 86f1bf31b8
14 changed files with 224 additions and 42 deletions

View File

@@ -5,7 +5,7 @@ import { APPLICATIONS_PATH, docker } from "@/server/constants";
import type { ContainerInfo, ResourceRequirements } from "dockerode";
import { parse } from "dotenv";
import type { ApplicationNested } from "../builders";
import { execAsync } from "../process/execAsync";
import { execAsync, execAsyncRemote } from "../process/execAsync";
import { getRemoteDocker } from "../servers/remote-docker";
interface RegistryAuth {
@@ -116,6 +116,15 @@ export const stopService = async (appName: string) => {
}
};
export const stopServiceRemote = async (serverId: string, appName: string) => {
try {
await execAsyncRemote(serverId, `docker service scale ${appName}=0 `);
} catch (error) {
console.error(error);
return error;
}
};
export const getContainerByName = (name: string): Promise<ContainerInfo> => {
const opts = {
limit: 1,
@@ -196,6 +205,15 @@ export const startService = async (appName: string) => {
}
};
export const startServiceRemote = async (serverId: string, appName: string) => {
try {
await execAsyncRemote(serverId, `docker service scale ${appName}=1 `);
} catch (error) {
console.error(error);
throw error;
}
};
export const removeService = async (appName: string) => {
try {
await execAsync(`docker service rm ${appName}`);

View File

@@ -145,6 +145,19 @@ export const writeConfig = (appName: string, traefikConfig: string) => {
}
};
export const writeConfigRemote = async (
serverId: string,
appName: string,
traefikConfig: string,
) => {
try {
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
await execAsyncRemote(serverId, `echo '${traefikConfig}' > ${configPath}`);
} catch (e) {
console.error("Error saving the YAML config file:", e);
}
};
export const writeTraefikConfigInPath = (
pathFile: string,
traefikConfig: string,