mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-05-06 19:08:13 +00:00
Allow purging and deleting a container from the DB with a purge option
This commit is contained in:
parent
0b4f50d207
commit
4db78b9743
@ -9,6 +9,7 @@ knex = require './db'
|
|||||||
{ request } = require './request'
|
{ request } = require './request'
|
||||||
Lock = require 'rwlock'
|
Lock = require 'rwlock'
|
||||||
utils = require './utils'
|
utils = require './utils'
|
||||||
|
rimraf = Promise.promisify(require('rimraf'))
|
||||||
|
|
||||||
docker = new Docker(socketPath: config.dockerSocket)
|
docker = new Docker(socketPath: config.dockerSocket)
|
||||||
|
|
||||||
@ -327,6 +328,14 @@ do ->
|
|||||||
container.inspectAsync()
|
container.inspectAsync()
|
||||||
.then (cont) ->
|
.then (cont) ->
|
||||||
throw new Error('Cannot remove supervisor container') if cont.Name == '/resin_supervisor' or _.any(cont.Names, (n) -> n == '/resin_supervisor')
|
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)
|
container.removeAsync(options)
|
||||||
exports.deleteContainer = (req, res) ->
|
exports.deleteContainer = (req, res) ->
|
||||||
deleteContainer(req.params.id, sanitizeQuery(req.query))
|
deleteContainer(req.params.id, sanitizeQuery(req.query))
|
||||||
|
@ -213,9 +213,12 @@ exports.defaultVolumes = {
|
|||||||
'/host/run/dbus': {}
|
'/host/run/dbus': {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.getDataPath = (identifier) ->
|
||||||
|
return config.dataPath + '/' + identifier
|
||||||
|
|
||||||
exports.defaultBinds = (dataPath) ->
|
exports.defaultBinds = (dataPath) ->
|
||||||
return [
|
return [
|
||||||
config.dataPath + '/' + dataPath + ':/data'
|
exports.getDataPath(dataPath) + ':/data'
|
||||||
'/lib/modules:/lib/modules'
|
'/lib/modules:/lib/modules'
|
||||||
'/lib/firmware:/lib/firmware'
|
'/lib/firmware:/lib/firmware'
|
||||||
'/run/dbus:/host_run/dbus'
|
'/run/dbus:/host_run/dbus'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user