mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-18 17:00:25 +00:00
Send logs through pubnub
This commit is contained in:
parent
9325b258ae
commit
5caace400f
@ -18,7 +18,8 @@
|
||||
"JSONStream": "~0.7.1",
|
||||
"event-stream": "~3.0.20",
|
||||
"sqlite3": "~2.1.19",
|
||||
"resin-platform-api": "git+ssh://git@bitbucket.org:rulemotion/resin-platform-api.git#v0.2.3"
|
||||
"resin-platform-api": "git+ssh://git@bitbucket.org:rulemotion/resin-platform-api.git#v0.2.3",
|
||||
"pubnub": "~3.6.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": "0.10.22"
|
||||
|
@ -4,6 +4,7 @@ url = require 'url'
|
||||
knex = require './db'
|
||||
path = require 'path'
|
||||
Docker = require 'dockerode'
|
||||
PUBNUB = require 'pubnub'
|
||||
Promise = require 'bluebird'
|
||||
JSONStream = require 'JSONStream'
|
||||
PlatformAPI = require 'resin-platform-api/request'
|
||||
@ -17,6 +18,20 @@ docker = Promise.promisifyAll(new Docker(socketPath: DOCKER_SOCKET))
|
||||
Promise.promisifyAll(docker.getImage().__proto__)
|
||||
Promise.promisifyAll(docker.getContainer().__proto__)
|
||||
|
||||
pubnub = PUBNUB.init(
|
||||
subscribe_key: 'sub-c-bananas'
|
||||
publish_key: 'pub-c-bananas'
|
||||
)
|
||||
|
||||
publish = null
|
||||
|
||||
knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
|
||||
uuid = uuid.value
|
||||
channel = "device-#{uuid}-logs"
|
||||
|
||||
publish = (message) ->
|
||||
pubnub.publish({channel, message})
|
||||
|
||||
exports.kill = kill = (app) ->
|
||||
docker.listContainersAsync(all: 1)
|
||||
.then (containers) ->
|
||||
@ -59,6 +74,7 @@ exports.start = start = (app) ->
|
||||
docker.createContainerAsync(
|
||||
Image: app.imageId
|
||||
Cmd: ['/bin/bash', '-c', '/start']
|
||||
Tty: true
|
||||
Volumes:
|
||||
'/dev': {}
|
||||
Env: _.map env, (v, k) -> k + '=' + v
|
||||
@ -77,6 +93,15 @@ exports.start = start = (app) ->
|
||||
'/var/run/docker.sock:/run/docker.sock'
|
||||
]
|
||||
)
|
||||
.then ->
|
||||
container.attach {stream: true, stdout: true, stderr: true, tty: true}, (err, stream) ->
|
||||
es.pipeline(
|
||||
stream
|
||||
es.split()
|
||||
# Remove color escape sequences
|
||||
es.mapSync((s) -> s.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, ''))
|
||||
es.mapSync(publish)
|
||||
)
|
||||
.tap ->
|
||||
console.log('Started container:', app.imageId)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user