Mount a /data directory for containers, to allow persistent storage.

This commit is contained in:
Pagan Gazzard 2014-08-19 18:21:44 +01:00 committed by Pablo Carranza Vélez
parent a9fe6f3414
commit 3c5e856ef2
2 changed files with 16 additions and 6 deletions

View File

@ -117,6 +117,7 @@ exports.start = start = (app) ->
Cmd: ['/bin/bash', '-c', '/start']
Tty: true
Volumes:
'/data': {}
'/lib/modules': {}
Env: _.map env, (v, k) -> k + '=' + v
ExposedPorts: ports
@ -139,6 +140,7 @@ exports.start = start = (app) ->
Privileged: true
PortBindings: ports
Binds: [
'/resin-data/' + app.id + ':/data'
'/lib/modules:/lib/modules'
'/var/run/docker.sock:/run/docker.sock'
]
@ -199,6 +201,7 @@ exports.update = update = ->
for envVar in app.environment_variable
env[envVar.name] = envVar.value
return {
appId: '' + app.id
commit: app.commit
imageId: "#{process.env.REGISTRY_ENDPOINT}/#{path.basename(app.git_repository, '.git')}/#{app.commit}"
env: JSON.stringify(env) # The env has to be stored as a JSON string for knex
@ -210,7 +213,7 @@ exports.update = update = ->
console.log("Local apps")
apps = _.indexBy(apps, 'imageId')
localApps = _.mapValues(apps, (app) -> _.pick(app, ['commit', 'imageId', 'env']))
localApps = _.mapValues(apps, (app) -> _.pick(app, ['appId', 'commit', 'imageId', 'env']))
localImages = _.keys(localApps)
console.log(localImages)

View File

@ -7,6 +7,13 @@ knex = Knex.initialize(
filename: '/data/database.sqlite'
)
addColumn = (table, column, type) ->
knex.schema.hasColumn(table, column)
.then (exists) ->
if not exists
knex.schema.table table, (t) ->
t[type](column)
knex.init = Promise.all([
knex.schema.hasTable('config')
.then (exists) ->
@ -24,14 +31,14 @@ knex.init = Promise.all([
t.string('containerId')
t.string('commit')
t.string('imageId')
t.string('appId')
t.boolean('privileged')
t.json('env')
else
knex.schema.hasColumn('app', 'commit')
.then (exists) ->
if not exists
knex.schema.table 'app', (t) ->
t.string('commit')
Promise.all [
addColumn('app', 'commit', 'string')
addColumn('app', 'appId', 'string')
]
])