mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-22 06:57:49 +00:00
Bind mount kmod if the container is debian or raspbian
Use docker-toolbelt module. The bind mount is read-only.
This commit is contained in:
parent
8cc68e2245
commit
5f926faa70
@ -1,3 +1,5 @@
|
||||
* Bind mount kmod if the container is debian or raspbian [Pablo]
|
||||
|
||||
# v1.12.1
|
||||
|
||||
* Fix preloaded apps by passing appId to extendEnvVars
|
||||
|
@ -15,6 +15,7 @@
|
||||
"coffee-script": "~1.9.1",
|
||||
"docker-delta": "0.0.11",
|
||||
"docker-progress": "^2.1.0",
|
||||
"docker-toolbelt": "^1.0.0",
|
||||
"dockerode": "~2.2.9",
|
||||
"event-stream": "^3.0.20",
|
||||
"express": "^4.0.0",
|
||||
|
@ -165,6 +165,13 @@ fetch = (app) ->
|
||||
logSystemEvent(logTypes.downloadAppError, app, err)
|
||||
throw err
|
||||
|
||||
shouldMountKmod = (image) ->
|
||||
docker.imageRootDir(image)
|
||||
.then (rootDir) ->
|
||||
utils.getOSVersion(rootDir + '/etc/os-release')
|
||||
.then (version) ->
|
||||
return version? and (version.match(/^Debian/i) or version.match(/^Raspbian/i))
|
||||
|
||||
application.start = start = (app) ->
|
||||
volumes =
|
||||
'/data': {}
|
||||
@ -238,13 +245,16 @@ application.start = start = (app) ->
|
||||
portList.forEach (port) ->
|
||||
ports[port + '/tcp'] = [ HostPort: port ]
|
||||
restartPolicy = createRestartPolicy({ name: env['RESIN_APP_RESTART_POLICY'], maximumRetryCount: env['RESIN_APP_RESTART_RETRIES'] })
|
||||
container.startAsync(
|
||||
Privileged: true
|
||||
NetworkMode: 'host'
|
||||
PortBindings: ports
|
||||
Binds: binds
|
||||
RestartPolicy: restartPolicy
|
||||
)
|
||||
shouldMountKmod(app.imageId)
|
||||
.then (shouldMount) ->
|
||||
binds.push('/bin/kmod:/bin/kmod:ro') if shouldMount
|
||||
container.startAsync(
|
||||
Privileged: true
|
||||
NetworkMode: 'host'
|
||||
PortBindings: ports
|
||||
Binds: binds
|
||||
RestartPolicy: restartPolicy
|
||||
)
|
||||
.catch (err) ->
|
||||
statusCode = '' + err.statusCode
|
||||
# 304 means the container was already started, precisely what we want :)
|
||||
|
@ -9,6 +9,7 @@ configPath = '/boot/config.json'
|
||||
request = Promise.promisifyAll(require('request'))
|
||||
execAsync = Promise.promisify(require('child_process').exec)
|
||||
fs = Promise.promisifyAll(require('fs'))
|
||||
|
||||
exports.getID = do ->
|
||||
deviceIdPromise = null
|
||||
return ->
|
||||
@ -219,15 +220,4 @@ do ->
|
||||
return
|
||||
|
||||
exports.getOSVersion = ->
|
||||
fs.readFileAsync(config.hostOsVersionPath)
|
||||
.then (releaseData) ->
|
||||
lines = (new String(releaseData)).split('\n')
|
||||
releaseItems = {}
|
||||
for line in lines
|
||||
[ key, val ] = line.split('=')
|
||||
releaseItems[_.trim(key)] = _.trim(val)
|
||||
# Remove enclosing quotes: http://stackoverflow.com/a/19156197/2549019
|
||||
return releaseItems['PRETTY_NAME'].replace(/^"(.+(?="$))"$/, '$1')
|
||||
.catch (err) ->
|
||||
console.log('Could not get OS Version: ', err, err.stack)
|
||||
return undefined
|
||||
return utils.getOSVersion(config.hostOsVersionPath)
|
||||
|
@ -1,4 +1,4 @@
|
||||
Docker = require 'dockerode'
|
||||
Docker = require 'docker-toolbelt'
|
||||
{ getRegistryAndName, DockerProgress } = require 'docker-progress'
|
||||
Promise = require 'bluebird'
|
||||
progress = require 'request-progress'
|
||||
@ -9,10 +9,7 @@ knex = require './db'
|
||||
{ request } = require './request'
|
||||
Lock = require 'rwlock'
|
||||
|
||||
docker = Promise.promisifyAll(new Docker(socketPath: config.dockerSocket))
|
||||
# Hack dockerode to promisify internal classes' prototypes
|
||||
Promise.promisifyAll(docker.getImage().constructor.prototype)
|
||||
Promise.promisifyAll(docker.getContainer().constructor.prototype)
|
||||
docker = new Docker(socketPath: config.dockerSocket)
|
||||
|
||||
exports.docker = docker
|
||||
dockerProgress = new DockerProgress(socketPath: config.dockerSocket)
|
||||
|
@ -191,3 +191,16 @@ exports.getKnexApp = (appId, columns) ->
|
||||
throw new AppNotFoundError('App not found')
|
||||
return app
|
||||
|
||||
exports.getOSVersion = (path) ->
|
||||
fs.readFileAsync(path)
|
||||
.then (releaseData) ->
|
||||
lines = releaseData.toString().split('\n')
|
||||
releaseItems = {}
|
||||
for line in lines
|
||||
[ key, val ] = line.split('=')
|
||||
releaseItems[_.trim(key)] = _.trim(val)
|
||||
# Remove enclosing quotes: http://stackoverflow.com/a/19156197/2549019
|
||||
return releaseItems['PRETTY_NAME'].replace(/^"(.+(?="$))"$/, '$1')
|
||||
.catch (err) ->
|
||||
console.log('Could not get OS Version: ', err, err.stack)
|
||||
return undefined
|
||||
|
Loading…
Reference in New Issue
Block a user