mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: Streamline Docker service management and error handling
- Removed unnecessary console logging in the mechanizeDockerContainer function to enhance code clarity. - Simplified error handling by directly creating a new service if the existing one is not found, improving the deployment logic. - Updated the buildNixpacks function to ensure container cleanup is attempted without additional error handling, streamlining the process.
This commit is contained in:
parent
4b3e0805a4
commit
707463f973
@ -113,10 +113,6 @@ export const getBuildCommand = (
|
||||
export const mechanizeDockerContainer = async (
|
||||
application: ApplicationNested,
|
||||
) => {
|
||||
console.log(
|
||||
`Starting to mechanize Docker container for ${application.appName}`,
|
||||
);
|
||||
|
||||
const {
|
||||
appName,
|
||||
env,
|
||||
@ -197,10 +193,8 @@ export const mechanizeDockerContainer = async (
|
||||
};
|
||||
|
||||
try {
|
||||
console.log(`Attempting to find existing service: ${appName}`);
|
||||
const service = docker.getService(appName);
|
||||
const inspect = await service.inspect();
|
||||
console.log(`Found existing service, updating: ${appName}`);
|
||||
|
||||
await service.update({
|
||||
version: Number.parseInt(inspect.Version.Index),
|
||||
@ -210,22 +204,8 @@ export const mechanizeDockerContainer = async (
|
||||
ForceUpdate: inspect.Spec.TaskTemplate.ForceUpdate + 1,
|
||||
},
|
||||
});
|
||||
console.log(`Service updated successfully: ${appName}`);
|
||||
} catch (error: unknown) {
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : "Unknown error";
|
||||
console.log(`Service not found or error: ${errorMessage}`);
|
||||
console.log(`Creating new service: ${appName}`);
|
||||
|
||||
try {
|
||||
} catch (_error: unknown) {
|
||||
await docker.createService(settings);
|
||||
console.log(`Service created successfully: ${appName}`);
|
||||
} catch (createError: unknown) {
|
||||
const createErrorMessage =
|
||||
createError instanceof Error ? createError.message : "Unknown error";
|
||||
console.error(`Failed to create service: ${createErrorMessage}`);
|
||||
throw createError;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -85,19 +85,7 @@ export const buildNixpacks = async (
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
// Only try to remove the container if it might exist
|
||||
try {
|
||||
await spawnAsync("docker", ["rm", buildContainerId], writeToStream);
|
||||
} catch (rmError) {
|
||||
// Ignore errors from container removal
|
||||
const errorMessage =
|
||||
rmError instanceof Error
|
||||
? rmError.message
|
||||
: "Unknown container cleanup error";
|
||||
|
||||
// Just log it but don't let it cause another error
|
||||
writeToStream(`Container cleanup attempt: ${errorMessage}\n`);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user