mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 06:07:57 +00:00
Fix /v1/device endpoint returning null for commit after an update
Change-type: patch Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
parent
cf85ae524b
commit
380d40f9f8
@ -111,6 +111,8 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
@services.start(step.target)
|
||||
.then (container) =>
|
||||
@_containerStarted[container.id] = true
|
||||
updateCommit: (step) =>
|
||||
@config.set({ currentCommit: step.target })
|
||||
handover: (step, { force = false, skipLock = false } = {}) =>
|
||||
@_lockingIfNecessary step.current.appId, { force, skipLock: skipLock or step.options?.skipLock }, =>
|
||||
@services.handover(step.current, step.target)
|
||||
@ -172,8 +174,9 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
Promise.join(
|
||||
@services.getStatus()
|
||||
@images.getStatus()
|
||||
@config.get('currentCommit')
|
||||
@db.models('app').select([ 'appId', 'releaseId', 'commit' ])
|
||||
(services, images, targetApps) ->
|
||||
(services, images, currentCommit, targetApps) ->
|
||||
apps = {}
|
||||
dependent = {}
|
||||
releaseId = null
|
||||
@ -216,15 +219,14 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
console.log('Ignoring legacy dependent image', image)
|
||||
|
||||
obj = { local: apps, dependent }
|
||||
if releaseId and targetApps[0]?.releaseId == releaseId
|
||||
obj.commit = targetApps[0].commit
|
||||
obj.commit = currentCommit
|
||||
return obj
|
||||
)
|
||||
|
||||
getDependentState: =>
|
||||
@proxyvisor.getCurrentStates()
|
||||
|
||||
_buildApps: (services, networks, volumes) ->
|
||||
_buildApps: (services, networks, volumes, currentCommit) ->
|
||||
apps = {}
|
||||
|
||||
# We iterate over the current running services and add them to the current state
|
||||
@ -244,6 +246,11 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
apps[appId] ?= { appId, services: [], volumes: {}, networks: {} }
|
||||
apps[appId].volumes[volume.name] = volume.config
|
||||
|
||||
# multi-app warning!
|
||||
# This is just wrong on every level
|
||||
for app in apps
|
||||
app.commit = currentCommit
|
||||
|
||||
return apps
|
||||
|
||||
getCurrentForComparison: =>
|
||||
@ -251,6 +258,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
@services.getAll()
|
||||
@networks.getAll()
|
||||
@volumes.getAll()
|
||||
@config.get('currentCommit')
|
||||
@_buildApps
|
||||
)
|
||||
|
||||
@ -259,6 +267,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
@services.getAllByAppId(appId)
|
||||
@networks.getAllByAppId(appId)
|
||||
@volumes.getAllByAppId(appId)
|
||||
@configget('currentCommit')
|
||||
@_buildApps
|
||||
).get(appId)
|
||||
|
||||
@ -582,6 +591,13 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
for pair in volumePairs
|
||||
pairSteps = @_nextStepsForVolume(pair, currentApp, removePairs.concat(updatePairs))
|
||||
steps = steps.concat(pairSteps)
|
||||
|
||||
if _.isEmpty(steps) and currentApp.commit != targetApp.commit
|
||||
steps.push({
|
||||
action: 'updateCommit'
|
||||
target: targetApp.commit
|
||||
})
|
||||
|
||||
return _.map(steps, (step) -> _.assign({}, step, { appId }))
|
||||
|
||||
normaliseAppForDB: (app) =>
|
||||
|
@ -194,6 +194,7 @@ class Config extends EventEmitter {
|
||||
nativeLogger: { source: 'db', mutable: true, default: 'true' },
|
||||
// a JSON value, which is either null, or { app: number, commit: string }
|
||||
pinDevice: { source: 'db', mutable: true, default: 'null' },
|
||||
currentCommit: { source: 'db', mutable: true },
|
||||
};
|
||||
|
||||
public constructor({ db, configPath }: ConfigOpts) {
|
||||
|
Loading…
Reference in New Issue
Block a user