mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-07 20:00:25 +00:00
Fetch the image using dockerode.
This commit is contained in:
parent
7daebaf85e
commit
4d5c18ec6f
@ -1,12 +1,10 @@
|
|||||||
_ = require 'lodash'
|
_ = require 'lodash'
|
||||||
es = require 'event-stream'
|
es = require 'event-stream'
|
||||||
url = require 'url'
|
url = require 'url'
|
||||||
http = require 'http'
|
|
||||||
knex = require './db'
|
knex = require './db'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
Docker = require 'dockerode'
|
Docker = require 'dockerode'
|
||||||
Promise = require 'bluebird'
|
Promise = require 'bluebird'
|
||||||
request = Promise.promisify require 'request'
|
|
||||||
JSONStream = require 'JSONStream'
|
JSONStream = require 'JSONStream'
|
||||||
PlatformAPI = require 'resin-platform-api/request'
|
PlatformAPI = require 'resin-platform-api/request'
|
||||||
|
|
||||||
@ -37,30 +35,20 @@ exports.start = start = (app) ->
|
|||||||
docker.getImage(app.imageId).inspectAsync()
|
docker.getImage(app.imageId).inspectAsync()
|
||||||
.catch (error) ->
|
.catch (error) ->
|
||||||
console.log("Pulling image:", app.imageId)
|
console.log("Pulling image:", app.imageId)
|
||||||
deferred = Promise.defer()
|
docker.createImageAsync(fromImage: app.imageId)
|
||||||
options =
|
.then (stream) ->
|
||||||
method: 'POST'
|
deferred = Promise.defer()
|
||||||
path: "/v1.8/images/create?fromImage=#{app.imageId}"
|
|
||||||
socketPath: DOCKER_SOCKET
|
|
||||||
|
|
||||||
req = http.request options, (res) ->
|
if stream.headers['content-type'] is 'application/json'
|
||||||
if res.headers['content-type'] is 'application/json'
|
stream.pipe(JSONStream.parse('error'))
|
||||||
res.pipe(JSONStream.parse('error'))
|
|
||||||
.pipe es.mapSync (error) ->
|
.pipe es.mapSync (error) ->
|
||||||
deferred.reject(error)
|
deferred.reject(error)
|
||||||
else
|
else
|
||||||
res.pipe es.wait (error, text) -> deferred.reject(text)
|
stream.pipe es.wait (error, text) -> deferred.reject(text)
|
||||||
|
|
||||||
res.on 'end', ->
|
stream.on 'end', -> deferred.resolve()
|
||||||
if res.statusCode is 200
|
|
||||||
deferred.resolve()
|
|
||||||
else
|
|
||||||
deferred.reject(res.statusCode)
|
|
||||||
|
|
||||||
req.end()
|
return deferred.promise
|
||||||
req.on 'error', (error) -> deferred.reject(error)
|
|
||||||
|
|
||||||
return deferred.promise
|
|
||||||
.then ->
|
.then ->
|
||||||
console.log("Creating container:", app.imageId)
|
console.log("Creating container:", app.imageId)
|
||||||
ports = {}
|
ports = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user