From 67486146c499439acdbb2a3638b15e35b6e8e71e Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 23 Oct 2018 08:17:35 -0700 Subject: [PATCH 1/2] entry.sh: Use symbolic link to link to legacy lock path The lack of `-s` was a typo. Change-type: patch Signed-off-by: Pablo Carranza Velez --- entry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry.sh b/entry.sh index 4c6cb22c..bea077a1 100755 --- a/entry.sh +++ b/entry.sh @@ -12,7 +12,7 @@ rm -f /var/run/avahi-daemon/pid # already be using to take an update lock, so we symlink it to the new # location so that the supervisor can see it [ -d /mnt/root/tmp/resin-supervisor ] && - ( [ -d /mnt/root/tmp/balena-supervisor ] || ln ./resin-supervisor /mnt/root/tmp/balena-supervisor ) + ( [ -d /mnt/root/tmp/balena-supervisor ] || ln -s ./resin-supervisor /mnt/root/tmp/balena-supervisor ) # Otherwise, if the lockfiles directory doesn't exist [ -d /mnt/root/tmp/balena-supervisor ] || From 1c5891ec09d2921d7213bc6ccf7e9eb198efe0c4 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 23 Oct 2018 15:08:51 -0700 Subject: [PATCH 2/2] ApplicationManager: when comparing images to save metadata, take docker image ids into account Otherwise we may skip saving a target image to the db when updating from legacy supervisors, which in turn prevents from deleting the legacy image entry (with imageId = 1), leaving the supervisor in a state where it can't report its current state to the API. While we're at it, we also remove an unused variable in _getStatus. Change-type: patch Signed-off-by: Pablo Carranza Velez --- src/application-manager.coffee | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/application-manager.coffee b/src/application-manager.coffee index dda00e96..a399bbc9 100644 --- a/src/application-manager.coffee +++ b/src/application-manager.coffee @@ -200,8 +200,7 @@ module.exports = class ApplicationManager extends EventEmitter @services.getStatus() @images.getStatus(localMode) @config.get('currentCommit') - @db.models('app').select([ 'appId', 'releaseId', 'commit' ]) - (services, images, currentCommit, targetApps) -> + (services, images, currentCommit) -> apps = {} dependent = {} releaseId = null @@ -808,10 +807,15 @@ module.exports = class ApplicationManager extends EventEmitter _.map app.services, (service) -> img = _.find(available, { dockerImageId: service.config.image, imageId: service.imageId }) ? _.find(available, { dockerImageId: service.config.image }) return _.omit(img, [ 'dockerImageId', 'id' ]) + allImageDockerIdsForTargetApp = (app) -> + _(app.services).map((svc) -> [ svc.imageName, svc.config.image ]) + .filter((img) -> img[1]?) + .value() availableWithoutIds = _.map(available, (image) -> _.omit(image, [ 'dockerImageId', 'id' ])) currentImages = _.flatMap(current.local.apps, allImagesForCurrentApp) targetImages = _.flatMap(target.local.apps, allImagesForTargetApp) + targetImageDockerIds = _.fromPairs(_.flatMap(target.local.apps, allImageDockerIdsForTargetApp)) availableAndUnused = _.filter availableWithoutIds, (image) -> !_.some currentImages.concat(targetImages), (imageInUse) -> _.isEqual(image, imageInUse) @@ -823,8 +827,16 @@ module.exports = class ApplicationManager extends EventEmitter imagesToSave = [] if !localMode imagesToSave = _.filter targetImages, (targetImage) => - _.some(available, (availableImage) => @images.isSameImage(availableImage, targetImage)) and - !_.some availableWithoutIds, (img) -> _.isEqual(img, targetImage) + isActuallyAvailable = _.some( + available, (availableImage) => + if @images.isSameImage(availableImage, targetImage) + return true + if availableImage.dockerImageId == targetImageDockerIds[targetImage.name] + return true + return false + ) + isNotSaved = !_.some availableWithoutIds, (img) -> _.isEqual(img, targetImage) + return isActuallyAvailable and isNotSaved deltaSources = _.map imagesToDownload, (image) => return @bestDeltaSource(image, available)