mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-21 16:49:46 +00:00
Merge pull request #261 from resin-io/260-delete-then-download
Implement delete-then-download update strategy
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
* Implement delete-then-download update strategy [Pablo]
|
||||||
* Bump node-docker-delta to 0.0.12 [Pablo, Kostas]
|
* Bump node-docker-delta to 0.0.12 [Pablo, Kostas]
|
||||||
|
|
||||||
# v2.2.1
|
# v2.2.1
|
||||||
|
@ -17,6 +17,8 @@ fs = Promise.promisifyAll(require('fs'))
|
|||||||
JSONStream = require 'JSONStream'
|
JSONStream = require 'JSONStream'
|
||||||
|
|
||||||
class UpdatesLockedError extends TypedError
|
class UpdatesLockedError extends TypedError
|
||||||
|
ImageNotFoundError = (err) ->
|
||||||
|
return "#{err.statusCode}" is '404'
|
||||||
|
|
||||||
{ docker } = dockerUtils
|
{ docker } = dockerUtils
|
||||||
|
|
||||||
@ -51,6 +53,19 @@ logTypes =
|
|||||||
eventName: 'Application install error'
|
eventName: 'Application install error'
|
||||||
humanName: 'Failed to install application'
|
humanName: 'Failed to install application'
|
||||||
|
|
||||||
|
deleteImageForApp:
|
||||||
|
eventName: 'Application image removal'
|
||||||
|
humanName: 'Deleting image for application'
|
||||||
|
deleteImageForAppSuccess:
|
||||||
|
eventName: 'Application image removed'
|
||||||
|
humanName: 'Deleted image for application'
|
||||||
|
deleteImageForAppError:
|
||||||
|
eventName: 'Application image removal error'
|
||||||
|
humanName: 'Failed to delete image for application'
|
||||||
|
imageAlreadyDeleted:
|
||||||
|
eventName: 'Image already deleted'
|
||||||
|
humanName: 'Image already deleted for application'
|
||||||
|
|
||||||
startApp:
|
startApp:
|
||||||
eventName: 'Application start'
|
eventName: 'Application start'
|
||||||
humanName: 'Starting application'
|
humanName: 'Starting application'
|
||||||
@ -136,6 +151,17 @@ application.kill = kill = (app, updateDB = true, removeContainer = true) ->
|
|||||||
logSystemEvent(logTypes.stopAppError, app, err)
|
logSystemEvent(logTypes.stopAppError, app, err)
|
||||||
throw err
|
throw err
|
||||||
|
|
||||||
|
application.deleteImage = deleteImage = (app) ->
|
||||||
|
logSystemEvent(logTypes.deleteImageForApp, app)
|
||||||
|
docker.getImage(app.imageId).removeAsync(force: true)
|
||||||
|
.then ->
|
||||||
|
logSystemEvent(logTypes.deleteImageForAppSuccess, app)
|
||||||
|
.catch ImageNotFoundError, (err) ->
|
||||||
|
logSystemEvent(logTypes.imageAlreadyDeleted, app)
|
||||||
|
.catch (err) ->
|
||||||
|
logSystemEvent(logTypes.deleteImageForAppError, app, err)
|
||||||
|
throw err
|
||||||
|
|
||||||
isValidPort = (port) ->
|
isValidPort = (port) ->
|
||||||
maybePort = parseInt(port, 10)
|
maybePort = parseInt(port, 10)
|
||||||
return parseFloat(port) is maybePort and maybePort > 0 and maybePort < 65535
|
return parseFloat(port) is maybePort and maybePort > 0 and maybePort < 65535
|
||||||
@ -452,6 +478,19 @@ updateStrategies =
|
|||||||
.catch (err) ->
|
.catch (err) ->
|
||||||
logSystemEvent(logTypes.updateAppError, app, err) unless err instanceof UpdatesLockedError
|
logSystemEvent(logTypes.updateAppError, app, err) unless err instanceof UpdatesLockedError
|
||||||
throw err
|
throw err
|
||||||
|
'delete-then-download': ({ localApp, app, needsDownload, force }) ->
|
||||||
|
Promise.using lockUpdates(localApp, force), ->
|
||||||
|
logSystemEvent(logTypes.updateApp, app) if localApp.imageId == app.imageId
|
||||||
|
utils.getKnexApp(localApp.appId)
|
||||||
|
.tap(kill)
|
||||||
|
.then(deleteImage)
|
||||||
|
.then ->
|
||||||
|
fetch(app) if needsDownload
|
||||||
|
.then ->
|
||||||
|
start(app)
|
||||||
|
.catch (err) ->
|
||||||
|
logSystemEvent(logTypes.updateAppError, app, err) unless err instanceof UpdatesLockedError
|
||||||
|
throw err
|
||||||
'hand-over': ({ localApp, app, needsDownload, force, timeout }) ->
|
'hand-over': ({ localApp, app, needsDownload, force, timeout }) ->
|
||||||
Promise.using lockUpdates(localApp, force), ->
|
Promise.using lockUpdates(localApp, force), ->
|
||||||
utils.getKnexApp(localApp.appId)
|
utils.getKnexApp(localApp.appId)
|
||||||
|
Reference in New Issue
Block a user