[autofix.ci] apply automated fixes

This commit is contained in:
autofix-ci[bot] 2025-04-25 08:17:18 +00:00 committed by GitHub
parent d4c6e5b048
commit 79d55d8d34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 111 additions and 113 deletions

View File

@ -133,8 +133,6 @@ export const UserNav = () => {
Servers Servers
</DropdownMenuItem> </DropdownMenuItem>
)} )}
</> </>
)} )}
</DropdownMenuGroup> </DropdownMenuGroup>

View File

@ -1,17 +1,17 @@
import path from "node:path"; import path from "node:path";
import { paths } from "@dokploy/server/constants"; import { paths } from "@dokploy/server/constants";
import { import {
createServerDeployment, createServerDeployment,
updateDeploymentStatus, updateDeploymentStatus,
} from "@dokploy/server/services/deployment"; } from "@dokploy/server/services/deployment";
import { findServerById } from "@dokploy/server/services/server"; import { findServerById } from "@dokploy/server/services/server";
import { import {
TRAEFIK_HTTP3_PORT, TRAEFIK_HTTP3_PORT,
TRAEFIK_PORT, TRAEFIK_PORT,
TRAEFIK_SSL_PORT, TRAEFIK_SSL_PORT,
TRAEFIK_VERSION, TRAEFIK_VERSION,
getDefaultMiddlewares, getDefaultMiddlewares,
getDefaultServerTraefikConfig, getDefaultServerTraefikConfig,
} from "@dokploy/server/setup/traefik-setup"; } from "@dokploy/server/setup/traefik-setup";
import { Client } from "ssh2"; import { Client } from "ssh2";
import { recreateDirectory } from "../utils/filesystem/directory"; import { recreateDirectory } from "../utils/filesystem/directory";
@ -19,55 +19,55 @@ import { recreateDirectory } from "../utils/filesystem/directory";
import slug from "slugify"; import slug from "slugify";
export const slugify = (text: string | undefined) => { export const slugify = (text: string | undefined) => {
if (!text) { if (!text) {
return ""; return "";
} }
const cleanedText = text.trim().replace(/[^a-zA-Z0-9\s]/g, ""); const cleanedText = text.trim().replace(/[^a-zA-Z0-9\s]/g, "");
return slug(cleanedText, { return slug(cleanedText, {
lower: true, lower: true,
trim: true, trim: true,
strict: true, strict: true,
}); });
}; };
export const serverSetup = async ( export const serverSetup = async (
serverId: string, serverId: string,
onData?: (data: any) => void onData?: (data: any) => void,
) => { ) => {
const server = await findServerById(serverId); const server = await findServerById(serverId);
const { LOGS_PATH } = paths(); const { LOGS_PATH } = paths();
const slugifyName = slugify(`server ${server.name}`); const slugifyName = slugify(`server ${server.name}`);
const fullPath = path.join(LOGS_PATH, slugifyName); const fullPath = path.join(LOGS_PATH, slugifyName);
await recreateDirectory(fullPath); await recreateDirectory(fullPath);
const deployment = await createServerDeployment({ const deployment = await createServerDeployment({
serverId: server.serverId, serverId: server.serverId,
title: "Setup Server", title: "Setup Server",
description: "Setup Server", description: "Setup Server",
}); });
try { try {
onData?.("\nInstalling Server Dependencies: ✅\n"); onData?.("\nInstalling Server Dependencies: ✅\n");
await installRequirements(serverId, onData); await installRequirements(serverId, onData);
await updateDeploymentStatus(deployment.deploymentId, "done"); await updateDeploymentStatus(deployment.deploymentId, "done");
onData?.("\nSetup Server: ✅\n"); onData?.("\nSetup Server: ✅\n");
} catch (err) { } catch (err) {
console.log(err); console.log(err);
await updateDeploymentStatus(deployment.deploymentId, "error"); await updateDeploymentStatus(deployment.deploymentId, "error");
onData?.(`${err}\n`); onData?.(`${err}\n`);
} }
}; };
export const defaultCommand = () => { export const defaultCommand = () => {
const bashCommand = ` const bashCommand = `
set -e; set -e;
DOCKER_VERSION=27.0.3 DOCKER_VERSION=27.0.3
OS_TYPE=$(grep -w "ID" /etc/os-release | cut -d "=" -f 2 | tr -d '"') OS_TYPE=$(grep -w "ID" /etc/os-release | cut -d "=" -f 2 | tr -d '"')
@ -176,83 +176,83 @@ echo -e "13. Installing Railpack"
${installRailpack()} ${installRailpack()}
`; `;
return bashCommand; return bashCommand;
}; };
const installRequirements = async ( const installRequirements = async (
serverId: string, serverId: string,
onData?: (data: any) => void onData?: (data: any) => void,
) => { ) => {
const client = new Client(); const client = new Client();
const server = await findServerById(serverId); const server = await findServerById(serverId);
if (!server.sshKeyId) { if (!server.sshKeyId) {
onData?.("❌ No SSH Key found, please assign one to this server"); onData?.("❌ No SSH Key found, please assign one to this server");
throw new Error("No SSH Key found"); throw new Error("No SSH Key found");
} }
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
client client
.once("ready", () => { .once("ready", () => {
const command = server.command || defaultCommand(); const command = server.command || defaultCommand();
client.exec(command, (err, stream) => { client.exec(command, (err, stream) => {
if (err) { if (err) {
onData?.(err.message); onData?.(err.message);
reject(err); reject(err);
return; return;
} }
stream stream
.on("close", () => { .on("close", () => {
client.end(); client.end();
resolve(); resolve();
}) })
.on("data", (data: string) => { .on("data", (data: string) => {
onData?.(data.toString()); onData?.(data.toString());
}) })
.stderr.on("data", (data) => { .stderr.on("data", (data) => {
onData?.(data.toString()); onData?.(data.toString());
}); });
}); });
}) })
.on("error", (err) => { .on("error", (err) => {
client.end(); client.end();
if (err.level === "client-authentication") { if (err.level === "client-authentication") {
onData?.( onData?.(
`Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}` `Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`,
); );
reject( reject(
new Error( new Error(
`Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}` `Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`,
) ),
); );
} else { } else {
onData?.(`SSH connection error: ${err.message} ${err.level}`); onData?.(`SSH connection error: ${err.message} ${err.level}`);
reject(new Error(`SSH connection error: ${err.message}`)); reject(new Error(`SSH connection error: ${err.message}`));
} }
}) })
.connect({ .connect({
host: server.ipAddress, host: server.ipAddress,
port: server.port, port: server.port,
username: server.username, username: server.username,
privateKey: server.sshKey?.privateKey, privateKey: server.sshKey?.privateKey,
}); });
}); });
}; };
const setupDirectories = () => { const setupDirectories = () => {
const { SSH_PATH } = paths(true); const { SSH_PATH } = paths(true);
const directories = Object.values(paths(true)); const directories = Object.values(paths(true));
const createDirsCommand = directories const createDirsCommand = directories
.map((dir) => `mkdir -p "${dir}"`) .map((dir) => `mkdir -p "${dir}"`)
.join(" && "); .join(" && ");
const chmodCommand = `chmod 700 "${SSH_PATH}"`; const chmodCommand = `chmod 700 "${SSH_PATH}"`;
const command = ` const command = `
${createDirsCommand} ${createDirsCommand}
${chmodCommand} ${chmodCommand}
`; `;
return command; return command;
}; };
const setupMainDirectory = () => ` const setupMainDirectory = () => `
@ -502,9 +502,9 @@ fi
`; `;
const createTraefikConfig = () => { const createTraefikConfig = () => {
const config = getDefaultServerTraefikConfig(); const config = getDefaultServerTraefikConfig();
const command = ` const command = `
if [ -f "/etc/dokploy/traefik/dynamic/acme.json" ]; then if [ -f "/etc/dokploy/traefik/dynamic/acme.json" ]; then
chmod 600 "/etc/dokploy/traefik/dynamic/acme.json" chmod 600 "/etc/dokploy/traefik/dynamic/acme.json"
fi fi
@ -515,19 +515,19 @@ const createTraefikConfig = () => {
fi fi
`; `;
return command; return command;
}; };
const createDefaultMiddlewares = () => { const createDefaultMiddlewares = () => {
const config = getDefaultMiddlewares(); const config = getDefaultMiddlewares();
const command = ` const command = `
if [ -f "/etc/dokploy/traefik/dynamic/middlewares.yml" ]; then if [ -f "/etc/dokploy/traefik/dynamic/middlewares.yml" ]; then
echo "Middlewares config already exists ✅" echo "Middlewares config already exists ✅"
else else
echo "${config}" > /etc/dokploy/traefik/dynamic/middlewares.yml echo "${config}" > /etc/dokploy/traefik/dynamic/middlewares.yml
fi fi
`; `;
return command; return command;
}; };
export const installRClone = () => ` export const installRClone = () => `
@ -541,7 +541,7 @@ export const installRClone = () => `
`; `;
export const createTraefikInstance = () => { export const createTraefikInstance = () => {
const command = ` const command = `
# Check if dokpyloy-traefik exists # Check if dokpyloy-traefik exists
if docker service inspect dokploy-traefik > /dev/null 2>&1; then if docker service inspect dokploy-traefik > /dev/null 2>&1; then
echo "Migrating Traefik to Standalone..." echo "Migrating Traefik to Standalone..."
@ -570,7 +570,7 @@ export const createTraefikInstance = () => {
fi fi
`; `;
return command; return command;
}; };
const installNixpacks = () => ` const installNixpacks = () => `