We have to manually stringify/parse the JSON column for knex - fixes containers restarting every 6 minutes.

This commit is contained in:
Page 2014-06-06 12:07:29 +01:00 committed by Pablo Carranza Vélez
parent e9cbeea11e
commit f47e7fbf2b

View File

@ -64,9 +64,11 @@ exports.start = start = (app) ->
.then -> .then ->
console.log("Creating container:", app.imageId) console.log("Creating container:", app.imageId)
ports = {} ports = {}
if app.env.PORT? # Parse the env vars before trying to access them, that's because they have to be stringified for knex..
maybePort = parseInt(app.env.PORT, 10) env = JSON.parse(app.env)
if parseFloat(app.env.PORT) is maybePort and maybePort > 0 and maybePort < 65535 if env.PORT?
maybePort = parseInt(env.PORT, 10)
if parseFloat(env.PORT) is maybePort and maybePort > 0 and maybePort < 65535
port = maybePort port = maybePort
if port? if port?
ports[port + '/tcp'] = {} ports[port + '/tcp'] = {}
@ -75,7 +77,7 @@ exports.start = start = (app) ->
Cmd: ['/bin/bash', '-c', '/start'] Cmd: ['/bin/bash', '-c', '/start']
Volumes: Volumes:
'/dev': {} '/dev': {}
Env: _.map app.env, (v, k) -> k + '=' + v Env: _.map env, (v, k) -> k + '=' + v
ExposedPorts: ports ExposedPorts: ports
) )
.then (container) -> .then (container) ->
@ -136,7 +138,7 @@ exports.update = ->
env[envVar.name] = envVar.value env[envVar.name] = envVar.value
return { return {
imageId: "#{process.env.REGISTRY_ENDPOINT}/#{path.basename(app.git_repository, '.git')}/#{app.commit}" imageId: "#{process.env.REGISTRY_ENDPOINT}/#{path.basename(app.git_repository, '.git')}/#{app.commit}"
env: env env: JSON.stringify(env) # The env has to be stored as a JSON string for knex
} }
remoteApps = _.indexBy(remoteApps, 'imageId') remoteApps = _.indexBy(remoteApps, 'imageId')