mirror of
https://github.com/LukeHagar/dokploy.git
synced 2025-12-10 12:27:49 +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:
@@ -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 {
|
||||
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;
|
||||
}
|
||||
} catch (_error: unknown) {
|
||||
await docker.createService(settings);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user