compose: Use the hostname on the host as default hostname for services with host network mode

Otherwise if the hostname on the supervisor container differs from the hostname on the host, the current and target
services will never match.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2018-03-14 16:10:19 -03:00
parent 557b6a8d07
commit 08a98f47e4
2 changed files with 8 additions and 4 deletions

View File

@ -799,11 +799,13 @@ module.exports = class ApplicationManager extends EventEmitter
firmware: pathExistsOnHost('/lib/firmware')
modules: pathExistsOnHost('/lib/modules')
})
(opts, supervisorApiHost, hostPathExists) =>
fs.readFileAsync(path.join(constants.rootMountPoint, '/etc/hostname')).then(String)
(opts, supervisorApiHost, hostPathExists, hostnameOnHost) =>
configOpts = {
appName: app.name
supervisorApiHost
hostPathExists
hostnameOnHost
}
_.assign(configOpts, opts)
volumes = JSON.parse(app.volumes)

View File

@ -257,6 +257,9 @@ module.exports = class Service
return "#{@appId}_#{k}"
return k
if @networkMode == 'host' and @hostname == ''
@hostname = opts.hostnameOnHost
@networks[@networkMode] ?= {}
@restartPolicy = createRestartPolicy(serviceProperties.restart)
@ -459,9 +462,8 @@ module.exports = class Service
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
(networkMode == 'host' and hostname == os.hostname())
hostname = ''
if hostname.length is 12 and container.Id.startsWith(hostname)
hostname = ''
service = {
appId: appId