From 6193ebe1df01b3f479e1661cfc6bb1c33b8be567 Mon Sep 17 00:00:00 2001 From: Kostas Lekkas Date: Sat, 28 May 2016 22:12:08 +0300 Subject: [PATCH] Log useful supervisor info to stdout/stderr --- CHANGELOG.md | 2 ++ entry.alpine.sh | 4 +++- entry.sh | 4 +++- src/api.coffee | 7 +------ src/config.coffee | 4 ++++ src/utils.coffee | 10 ++++++++++ 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02a2254e..cfe5b930 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Log useful supervisor info to stdout/stderr [Kostas] + # v1.10.0 * Fix progress bars on docker version 1.10 [Aleksis] diff --git a/entry.alpine.sh b/entry.alpine.sh index a8da303b..421dd863 100755 --- a/entry.alpine.sh +++ b/entry.alpine.sh @@ -28,4 +28,6 @@ export DBUS_SYSTEM_BUS_ADDRESS="unix:path=/mnt/root/run/dbus/system_bus_socket" supervisorctl -c /etc/supervisor/supervisord.conf start resin-supervisor supervisorctl -c /etc/supervisor/supervisord.conf start go-supervisor -tail -f /var/log/supervisor/supervisord.log +tail -F \ + /var/log/supervisor/supervisord.log \ + /var/log/resin_supervisor_stdout.log diff --git a/entry.sh b/entry.sh index 810ce256..ea9f73bf 100755 --- a/entry.sh +++ b/entry.sh @@ -30,4 +30,6 @@ export DBUS_SYSTEM_BUS_ADDRESS="unix:path=/mnt/root/run/dbus/system_bus_socket" supervisorctl start resin-supervisor supervisorctl start go-supervisor -tail -f /var/log/supervisor/supervisord.log +tail -F \ + /var/log/supervisor/supervisord.log \ + /var/log/resin_supervisor_stdout.log diff --git a/src/api.coffee b/src/api.coffee index 53b188c0..2092e9a7 100644 --- a/src/api.coffee +++ b/src/api.coffee @@ -11,11 +11,6 @@ device = require './device' dockerUtils = require './docker-utils' _ = require 'lodash' -privateAppEnvVars = [ - 'RESIN_SUPERVISOR_API_KEY' - 'RESIN_API_KEY' -] - module.exports = (application) -> api = express() unparsedRouter = express.Router() @@ -151,7 +146,7 @@ module.exports = (application) -> if !app? throw new Error('App not found') # Don't return keys on the endpoint - app.env = _.omit(JSON.parse(app.env), privateAppEnvVars) + app.env = _.omit(JSON.parse(app.env), config.privateAppEnvVars) # Don't return data that will be of no use to the user res.json(app) .catch (err) -> diff --git a/src/config.coffee b/src/config.coffee index 560a8fff..963ec5dc 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -44,3 +44,7 @@ module.exports = config = hostOsVersionPath: checkString(process.env.HOST_OS_VERSION_PATH) ? '/mnt/root/etc/os-release' dockerRoot: dockerRoot btrfsRoot: checkString(process.env.BTRFS_ROOT) ? "#{dockerRoot}/btrfs/subvolumes" + privateAppEnvVars: [ + 'RESIN_SUPERVISOR_API_KEY' + 'RESIN_API_KEY' + ] diff --git a/src/utils.coffee b/src/utils.coffee index 98c15e20..cb8715c9 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -36,6 +36,16 @@ exports.mixpanelTrack = (event, properties = {}) -> message: properties.error.message stack: properties.error.stack + # Don't log private env vars (e.g. api keys) + if properties?.app?.env? + try + { env } = properties.app + env = JSON.parse(env) if _.isString(env) + safeEnv = _.omit(env, config.privateAppEnvVars) + properties.app.env = JSON.stringify(safeEnv) + catch + properties.app.env = 'Fully hidden due to error in selective hiding' + console.log('Event:', event, JSON.stringify(properties)) # Mutation is bad, and it should feel bad properties = _.assign(_.cloneDeep(properties), mixpanelProperties)