Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix container update process in mqdockerup #425

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions src/services/DockerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,34 @@ export default class DockerService {
);
containerConfig.HostConfig.Binds = binds;

// Restart the container with the new image
await container.stop();
await container.remove();
const newContainer = await DockerService.docker.createContainer(containerConfig);
await newContainer.start();

// Remove old image
DockerService.docker
.getImage(oldImageId)
.remove({ force: true }, (err, data) => {
if (err) {
logger.error("Error removing old image: " + err);
} else {
logger.info("Old image removed successfully");
}
});

// Publish final 100% progress
await HomeassistantService.publishUpdateProgressMessage(info, mqttClient, 100, false);
this.updatingContainers = this.updatingContainers.filter((id) => id !== containerId);

return newContainer;
try {
// Restart the container with the new image
await container.stop();
await container.remove();
const newContainer = await DockerService.docker.createContainer(containerConfig);
await newContainer.start();

// Remove old image
DockerService.docker
.getImage(oldImageId)
.remove({ force: true }, (err, data) => {
if (err) {
logger.error("Error removing old image: " + err);
} else {
logger.info("Old image removed successfully");
}
});

// Publish final 100% progress
await HomeassistantService.publishUpdateProgressMessage(info, mqttClient, 100, false);
this.updatingContainers = this.updatingContainers.filter((id) => id !== containerId);

return newContainer;
} catch (error) {
logger.error("Error restarting container with new image");
logger.error(error);
throw error;
}
},
(event) => {
logger.debug(`Status: ${event.status}`);
Expand Down