Add support for service hostname

Plus several small bug fixes:

* Allow target states with apps with no release

* Fix lock override and a TypeError in compareServicesForUpdate

* Lowercase service names when doing migrations and legacy preload

* Fix deltas from scratch

Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2018-01-18 19:49:48 -03:00
parent 839ebf8688
commit f653fa4961
6 changed files with 18 additions and 7 deletions

View File

@ -383,7 +383,7 @@ module.exports = class ApplicationManager extends EventEmitter
removePairs = [] removePairs = []
installPairs = [] installPairs = []
updatePairs = [] updatePairs = []
if currentServices.length == 1 and targetServices.length == 1 and if currentServices?.length == 1 and targetServices?.length == 1 and
targetServices[0].serviceName == currentServices[0].serviceName and targetServices[0].serviceName == currentServices[0].serviceName and
checkTruthy(currentServices[0].labels['io.resin.legacy-container']) checkTruthy(currentServices[0].labels['io.resin.legacy-container'])
# This is a legacy preloaded app or container, so we didn't have things like serviceId. # This is a legacy preloaded app or container, so we didn't have things like serviceId.
@ -880,7 +880,7 @@ module.exports = class ApplicationManager extends EventEmitter
return Promise.resolve() return Promise.resolve()
@config.get('lockOverride') @config.get('lockOverride')
.then (lockOverride) -> .then (lockOverride) ->
return lockOverride or force return checkTruthy(lockOverride) or force
.then (force) -> .then (force) ->
updateLock.lock(appId, { force }, fn) updateLock.lock(appId, { force }, fn)

View File

@ -54,7 +54,7 @@ module.exports = class Images extends EventEmitter
if validation.checkTruthy(opts.delta) if validation.checkTruthy(opts.delta)
@logger.logSystemEvent(logTypes.downloadImageDelta, { image }) @logger.logSystemEvent(logTypes.downloadImageDelta, { image })
Promise.try => Promise.try =>
if opts.deltaSource if opts.deltaSource and opts.deltaSource != 'resin/scratch'
@inspectByName(opts.deltaSource) @inspectByName(opts.deltaSource)
.then (srcImage) -> .then (srcImage) ->
opts.deltaSourceId = srcImage.Id opts.deltaSourceId = srcImage.Id

View File

@ -1,5 +1,6 @@
_ = require 'lodash' _ = require 'lodash'
path = require 'path' path = require 'path'
os = require 'os'
{ checkTruthy, checkInt } = require '../lib/validation' { checkTruthy, checkInt } = require '../lib/validation'
updateLock = require '../lib/update-lock' updateLock = require '../lib/update-lock'
constants = require '../lib/constants' constants = require '../lib/constants'
@ -138,7 +139,6 @@ module.exports = class Service
@exposedPorts @exposedPorts
@portBindings @portBindings
@networks @networks
@memLimit @memLimit
@memReservation @memReservation
@shmSize @shmSize
@ -162,6 +162,7 @@ module.exports = class Service
@healthcheck @healthcheck
@readOnly @readOnly
@sysctls @sysctls
@hostname
} = _.mapKeys(serviceProperties, (v, k) -> _.camelCase(k)) } = _.mapKeys(serviceProperties, (v, k) -> _.camelCase(k))
@networks ?= {} @networks ?= {}
@ -205,6 +206,8 @@ module.exports = class Service
@sysctls ?= {} @sysctls ?= {}
@hostname ?= ''
# If the service has no containerId, it is a target service and has to be normalised and extended # If the service has no containerId, it is a target service and has to be normalised and extended
if !@containerId? if !@containerId?
@networkMode ?= 'default' @networkMode ?= 'default'
@ -405,6 +408,12 @@ module.exports = class Service
nameComponents = container.Name.match(/.*_(\d+)_(\d+)$/) nameComponents = container.Name.match(/.*_(\d+)_(\d+)$/)
imageId = checkInt(nameComponents?[1]) imageId = checkInt(nameComponents?[1])
releaseId = checkInt(nameComponents?[2]) releaseId = checkInt(nameComponents?[2])
hostname = container.Config.Hostname
# A hostname equal to the first part of the container ID actually
# means no hostname was specified
if hostname == container.Id.substr(0, 12) or
(container.HostConfig.NetworkMode == 'host' and hostname == os.hostname())
hostname = ''
service = { service = {
appId: appId appId: appId
serviceId: serviceId serviceId: serviceId
@ -453,6 +462,7 @@ module.exports = class Service
init: container.HostConfig.Init init: container.HostConfig.Init
readOnly: container.HostConfig.ReadonlyRootfs readOnly: container.HostConfig.ReadonlyRootfs
sysctls: container.HostConfig.Sysctls sysctls: container.HostConfig.Sysctls
hostname: hostname
} }
# I've seen docker use either 'no' or '' for no restart policy, so we normalise to 'no'. # I've seen docker use either 'no' or '' for no restart policy, so we normalise to 'no'.
if service.restartPolicy.Name == '' if service.restartPolicy.Name == ''
@ -582,6 +592,7 @@ module.exports = class Service
'init' 'init'
'readOnly' 'readOnly'
'sysctls' 'sysctls'
'hostname'
] ]
arraysToCompare = [ arraysToCompare = [
'volumes' 'volumes'

View File

@ -72,7 +72,7 @@ singleToMulticontainerApp = (app) ->
{ {
serviceId: 1 serviceId: 1
appId: appId appId: appId
serviceName: app.name serviceName: app.name.toLowerCase()
imageId: 1 imageId: 1
commit: app.commit commit: app.commit
releaseId: 1 releaseId: 1

View File

@ -61,7 +61,7 @@ exports.isValidAppsObject = (obj) ->
return false if !_.isObject(obj) return false if !_.isObject(obj)
return false if !_.every obj, (val, appId) -> return false if !_.every obj, (val, appId) ->
return false if !isValidShortText(appId) or !checkInt(appId)? return false if !isValidShortText(appId) or !checkInt(appId)?
return false if !isValidShortText(val.name) or !checkInt(val.releaseId)? return false if !isValidShortText(val.name) or (val.releaseId? and !checkInt(val.releaseId)?)
return false if !_.isObject(val.services) return false if !_.isObject(val.services)
return false if !_.every(val.services, isValidService) return false if !_.every(val.services, isValidService)
return true return true

View File

@ -49,7 +49,7 @@ var singleToMulticontainerApp = function (app, appId) {
{ {
serviceId: 1, serviceId: 1,
appId: appId, appId: appId,
serviceName: app.name, serviceName: app.name.toLowerCase(),
imageId: 1, imageId: 1,
commit: app.commit, commit: app.commit,
releaseId: 1, releaseId: 1,