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:
Mauricio Siu
2025-03-23 04:09:06 -06:00
parent 4b3e0805a4
commit 707463f973
2 changed files with 3 additions and 35 deletions

View File

@@ -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);
}
};