Skip to content

Commit 0c7cb17

Browse files
authored
Fix container update process in mqdockerup (#425)
2 parents 49f5038 + 70ac499 commit 0c7cb17

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

src/services/DockerService.ts

+28-22
Original file line numberDiff line numberDiff line change
@@ -194,28 +194,34 @@ export default class DockerService {
194194
);
195195
containerConfig.HostConfig.Binds = binds;
196196

197-
// Restart the container with the new image
198-
await container.stop();
199-
await container.remove();
200-
const newContainer = await DockerService.docker.createContainer(containerConfig);
201-
await newContainer.start();
202-
203-
// Remove old image
204-
DockerService.docker
205-
.getImage(oldImageId)
206-
.remove({ force: true }, (err, data) => {
207-
if (err) {
208-
logger.error("Error removing old image: " + err);
209-
} else {
210-
logger.info("Old image removed successfully");
211-
}
212-
});
213-
214-
// Publish final 100% progress
215-
await HomeassistantService.publishUpdateProgressMessage(info, mqttClient, 100, false);
216-
this.updatingContainers = this.updatingContainers.filter((id) => id !== containerId);
217-
218-
return newContainer;
197+
try {
198+
// Restart the container with the new image
199+
await container.stop();
200+
await container.remove();
201+
const newContainer = await DockerService.docker.createContainer(containerConfig);
202+
await newContainer.start();
203+
204+
// Remove old image
205+
DockerService.docker
206+
.getImage(oldImageId)
207+
.remove({ force: true }, (err, data) => {
208+
if (err) {
209+
logger.error("Error removing old image: " + err);
210+
} else {
211+
logger.info("Old image removed successfully");
212+
}
213+
});
214+
215+
// Publish final 100% progress
216+
await HomeassistantService.publishUpdateProgressMessage(info, mqttClient, 100, false);
217+
this.updatingContainers = this.updatingContainers.filter((id) => id !== containerId);
218+
219+
return newContainer;
220+
} catch (error) {
221+
logger.error("Error restarting container with new image");
222+
logger.error(error);
223+
throw error;
224+
}
219225
},
220226
(event) => {
221227
logger.debug(`Status: ${event.status}`);

0 commit comments

Comments
 (0)