mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-21 11:35:18 +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'
|
||||
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))
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user