get full container id from /proc/1/cgroup

This commit is contained in:
Aleksis Brezas 2014-09-05 14:48:35 +00:00 committed by Pablo Carranza Vélez
parent 69e2af5aa1
commit 839b6ec7ca

View File

@ -3,6 +3,7 @@ Docker = require 'dockerode'
Promise = require 'bluebird'
_ = require 'lodash'
es = require 'event-stream'
fs = Promise.promisifyAll(require('fs'))
docker = Promise.promisifyAll(new Docker(socketPath: config.dockerSocket))
# Hack dockerode to promisify internal classes' prototypes
@ -12,6 +13,17 @@ Promise.promisifyAll(docker.getContainer().__proto__)
localImage = config.localImage
remoteImage = config.remoteImage
getContainerId = ->
fs.readFileAsync( '/proc/1/cgroup' )
.then (data) ->
data.toString().match( /:cpu:\/docker\/(.*)$/m )[ 1 ]
.catch (err) ->
return process.env.HOSTNAME
getCurrentContainer = ->
getContainerId().then (containerId) ->
docker.getContainer(containerId).inspectAsync()
startNewSupervisor = (currentSupervisor) ->
console.log('Creating supervisor container:', localImage)
docker.createContainerAsync(
@ -53,8 +65,7 @@ startNewSupervisor = (currentSupervisor) ->
console.log('Exiting to let the new supervisor take over')
process.exit()
# Docker sets the HOSTNAME as the container's short id.
currentSupervisor = docker.getContainer(process.env.HOSTNAME).inspectAsync().tap (currentSupervisor) ->
currentSupervisor = getCurrentContainer().tap (currentSupervisor) ->
# The volume keys are the important bit.
expectedVolumes = _.sortBy(_.keys(config.supervisorContainer.Volumes))
actualVolumes = _.sortBy(_.keys(currentSupervisor.Volumes))