From 4db78b9743ba7b1026d6f2aadb5a8aba08acdcf4 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Fri, 22 Jul 2016 17:23:13 +0000 Subject: [PATCH] Allow purging and deleting a container from the DB with a purge option --- src/docker-utils.coffee | 9 +++++++++ src/utils.coffee | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/docker-utils.coffee b/src/docker-utils.coffee index 6385d2ac..daf3d598 100644 --- a/src/docker-utils.coffee +++ b/src/docker-utils.coffee @@ -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)) diff --git a/src/utils.coffee b/src/utils.coffee index 5b1bb41c..8ba09d05 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -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'