From bd889e06a190c9a0d629f7b77abe3dfa27d919ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Carranza=20V=C3=A9lez?= Date: Fri, 18 Sep 2015 17:51:36 +0000 Subject: [PATCH] Bind mount /boot in RPi --- CHANGELOG.md | 1 + src/application.coffee | 41 +++++++++++++++++++++++++---------------- src/device.coffee | 12 ++++++++++++ 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de4ba0b7..e27be806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Bind mount /boot in Raspberry Pis [Pablo] * Implement and use golang endpoint for getting IPs of the device, also fixes duplicate IP reporting in the JS implementation [Praneeth] * Refactor bootstrapping to run in background [Pablo] * Run preloaded app images [Pablo] diff --git a/src/application.coffee b/src/application.coffee index 99547bce..8439e480 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -136,7 +136,29 @@ fetch = (app) -> throw err application.start = start = (app) -> - Promise.try -> + volumes = + '/data': {} + '/lib/modules': {} + '/lib/firmware': {} + '/run/dbus': {} + binds = [ + '/resin-data/' + app.appId + ':/data' + '/lib/modules:/lib/modules' + '/lib/firmware:/lib/firmware' + '/run/dbus:/run/dbus' + '/run/dbus:/host_run/dbus' + '/var/run/docker.sock:/run/docker.sock' + '/var/run/docker.sock:/host_run/docker.sock' + '/etc/resolv.conf:/etc/resolv.conf:rw' + ] + device.getDeviceType() + .then (deviceType) -> + if deviceType.match(/^raspberry-pi/)? + volumes['/boot'] = {} + binds.push('/boot:/boot') + .catch (err) -> + console.log('Could not determine device type: ', err) + .then -> # Parse the env vars before trying to access them, that's because they have to be stringified for knex.. JSON.parse(app.env) .then (env) -> @@ -174,11 +196,7 @@ application.start = start = (app) -> Image: app.imageId Cmd: cmd Tty: true - Volumes: - '/data': {} - '/lib/modules': {} - '/lib/firmware': {} - '/run/dbus': {} + Volumes: volumes Env: _.map env, (v, k) -> k + '=' + v ExposedPorts: ports ) @@ -205,16 +223,7 @@ application.start = start = (app) -> Privileged: true NetworkMode: 'host' PortBindings: ports - Binds: [ - '/resin-data/' + app.appId + ':/data' - '/lib/modules:/lib/modules' - '/lib/firmware:/lib/firmware' - '/run/dbus:/run/dbus' - '/run/dbus:/host_run/dbus' - '/var/run/docker.sock:/run/docker.sock' - '/var/run/docker.sock:/host_run/docker.sock' - '/etc/resolv.conf:/etc/resolv.conf:rw' - ] + Binds: binds ) .catch (err) -> statusCode = '' + err.statusCode diff --git a/src/device.coffee b/src/device.coffee index c37d8758..b6ede22a 100644 --- a/src/device.coffee +++ b/src/device.coffee @@ -4,6 +4,7 @@ knex = require './db' utils = require './utils' { resinApi } = require './request' device = exports +configPath = '/boot/config.json' exports.getID = do -> deviceIdPromise = null @@ -31,6 +32,17 @@ exports.getID = do -> throw new Error('Could not find this device?!') return devices[0].id +exports.getDeviceType = do -> + deviceTypePromise = null + return -> + deviceTypePromise ?= Promise.rejected() + deviceTypePromise = deviceTypePromise.catch -> + fs.readFileAsync(configPath, 'utf8') + .then(JSON.parse) + .then (configFromFile) -> + if !configFromFile.deviceType? + throw new Error('Device type not specified in config file') + return configFromFile.deviceType # Calling this function updates the local device state, which is then used to synchronise # the remote device state, repeating any failed updates until successfully synchronised.