Allow purging and deleting a container from the DB with a purge option

This commit is contained in:
Pablo Carranza Velez 2016-07-22 17:23:13 +00:00
parent 0b4f50d207
commit 4db78b9743
2 changed files with 13 additions and 1 deletions

View File

@ -9,6 +9,7 @@ knex = require './db'
{ request } = require './request'
Lock = require 'rwlock'
utils = require './utils'
rimraf = Promise.promisify(require('rimraf'))
docker = new Docker(socketPath: config.dockerSocket)
@ -327,6 +328,14 @@ do ->
container.inspectAsync()
.then (cont) ->
throw new Error('Cannot remove supervisor container') if cont.Name == '/resin_supervisor' or _.any(cont.Names, (n) -> n == '/resin_supervisor')
if options.purge
knex('container').select().where({ containerId })
.then (contFromDB) ->
# This will also be affected by #115. Should fix when we fix that.
rimraf(utils.getDataPath("containers/#{contFromDB.id}"))
.then ->
knex('container').where({ containerId }).del()
.then ->
container.removeAsync(options)
exports.deleteContainer = (req, res) ->
deleteContainer(req.params.id, sanitizeQuery(req.query))

View File

@ -213,9 +213,12 @@ exports.defaultVolumes = {
'/host/run/dbus': {}
}
exports.getDataPath = (identifier) ->
return config.dataPath + '/' + identifier
exports.defaultBinds = (dataPath) ->
return [
config.dataPath + '/' + dataPath + ':/data'
exports.getDataPath(dataPath) + ':/data'
'/lib/modules:/lib/modules'
'/lib/firmware:/lib/firmware'
'/run/dbus:/host_run/dbus'