mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-01 19:46:44 +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)
|
@services.start(step.target)
|
||||||
.then (container) =>
|
.then (container) =>
|
||||||
@_containerStarted[container.id] = true
|
@_containerStarted[container.id] = true
|
||||||
|
updateCommit: (step) =>
|
||||||
|
@config.set({ currentCommit: step.target })
|
||||||
handover: (step, { force = false, skipLock = false } = {}) =>
|
handover: (step, { force = false, skipLock = false } = {}) =>
|
||||||
@_lockingIfNecessary step.current.appId, { force, skipLock: skipLock or step.options?.skipLock }, =>
|
@_lockingIfNecessary step.current.appId, { force, skipLock: skipLock or step.options?.skipLock }, =>
|
||||||
@services.handover(step.current, step.target)
|
@services.handover(step.current, step.target)
|
||||||
@ -172,8 +174,9 @@ module.exports = class ApplicationManager extends EventEmitter
|
|||||||
Promise.join(
|
Promise.join(
|
||||||
@services.getStatus()
|
@services.getStatus()
|
||||||
@images.getStatus()
|
@images.getStatus()
|
||||||
|
@config.get('currentCommit')
|
||||||
@db.models('app').select([ 'appId', 'releaseId', 'commit' ])
|
@db.models('app').select([ 'appId', 'releaseId', 'commit' ])
|
||||||
(services, images, targetApps) ->
|
(services, images, currentCommit, targetApps) ->
|
||||||
apps = {}
|
apps = {}
|
||||||
dependent = {}
|
dependent = {}
|
||||||
releaseId = null
|
releaseId = null
|
||||||
@ -216,15 +219,14 @@ module.exports = class ApplicationManager extends EventEmitter
|
|||||||
console.log('Ignoring legacy dependent image', image)
|
console.log('Ignoring legacy dependent image', image)
|
||||||
|
|
||||||
obj = { local: apps, dependent }
|
obj = { local: apps, dependent }
|
||||||
if releaseId and targetApps[0]?.releaseId == releaseId
|
obj.commit = currentCommit
|
||||||
obj.commit = targetApps[0].commit
|
|
||||||
return obj
|
return obj
|
||||||
)
|
)
|
||||||
|
|
||||||
getDependentState: =>
|
getDependentState: =>
|
||||||
@proxyvisor.getCurrentStates()
|
@proxyvisor.getCurrentStates()
|
||||||
|
|
||||||
_buildApps: (services, networks, volumes) ->
|
_buildApps: (services, networks, volumes, currentCommit) ->
|
||||||
apps = {}
|
apps = {}
|
||||||
|
|
||||||
# We iterate over the current running services and add them to the current state
|
# 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] ?= { appId, services: [], volumes: {}, networks: {} }
|
||||||
apps[appId].volumes[volume.name] = volume.config
|
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
|
return apps
|
||||||
|
|
||||||
getCurrentForComparison: =>
|
getCurrentForComparison: =>
|
||||||
@ -251,6 +258,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
|||||||
@services.getAll()
|
@services.getAll()
|
||||||
@networks.getAll()
|
@networks.getAll()
|
||||||
@volumes.getAll()
|
@volumes.getAll()
|
||||||
|
@config.get('currentCommit')
|
||||||
@_buildApps
|
@_buildApps
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -259,6 +267,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
|||||||
@services.getAllByAppId(appId)
|
@services.getAllByAppId(appId)
|
||||||
@networks.getAllByAppId(appId)
|
@networks.getAllByAppId(appId)
|
||||||
@volumes.getAllByAppId(appId)
|
@volumes.getAllByAppId(appId)
|
||||||
|
@configget('currentCommit')
|
||||||
@_buildApps
|
@_buildApps
|
||||||
).get(appId)
|
).get(appId)
|
||||||
|
|
||||||
@ -582,6 +591,13 @@ module.exports = class ApplicationManager extends EventEmitter
|
|||||||
for pair in volumePairs
|
for pair in volumePairs
|
||||||
pairSteps = @_nextStepsForVolume(pair, currentApp, removePairs.concat(updatePairs))
|
pairSteps = @_nextStepsForVolume(pair, currentApp, removePairs.concat(updatePairs))
|
||||||
steps = steps.concat(pairSteps)
|
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 }))
|
return _.map(steps, (step) -> _.assign({}, step, { appId }))
|
||||||
|
|
||||||
normaliseAppForDB: (app) =>
|
normaliseAppForDB: (app) =>
|
||||||
|
@ -194,6 +194,7 @@ class Config extends EventEmitter {
|
|||||||
nativeLogger: { source: 'db', mutable: true, default: 'true' },
|
nativeLogger: { source: 'db', mutable: true, default: 'true' },
|
||||||
// a JSON value, which is either null, or { app: number, commit: string }
|
// a JSON value, which is either null, or { app: number, commit: string }
|
||||||
pinDevice: { source: 'db', mutable: true, default: 'null' },
|
pinDevice: { source: 'db', mutable: true, default: 'null' },
|
||||||
|
currentCommit: { source: 'db', mutable: true },
|
||||||
};
|
};
|
||||||
|
|
||||||
public constructor({ db, configPath }: ConfigOpts) {
|
public constructor({ db, configPath }: ConfigOpts) {
|
||||||
|
Loading…
Reference in New Issue
Block a user