2017-03-29 11:03:40 +00:00
|
|
|
# Functions to help actions which rely on using docker
|
|
|
|
|
2017-05-04 12:00:48 +00:00
|
|
|
QEMU_VERSION = 'v2.5.50-resin-execve'
|
|
|
|
QEMU_BIN_NAME = 'qemu-execve'
|
|
|
|
|
2017-03-29 11:03:40 +00:00
|
|
|
# Use this function to seed an action's list of capitano options
|
|
|
|
# with the docker options. Using this interface means that
|
|
|
|
# all functions using docker will expose the same interface
|
|
|
|
#
|
|
|
|
# NOTE: Care MUST be taken when using the function, so as to
|
|
|
|
# not redefine/override options already provided.
|
2017-08-04 12:53:31 +00:00
|
|
|
exports.appendConnectionOptions = appendConnectionOptions = (opts) ->
|
2017-03-29 11:03:40 +00:00
|
|
|
opts.concat [
|
|
|
|
{
|
|
|
|
signature: 'docker'
|
|
|
|
parameter: 'docker'
|
|
|
|
description: 'Path to a local docker socket'
|
|
|
|
alias: 'P'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
signature: 'dockerHost'
|
|
|
|
parameter: 'dockerHost'
|
|
|
|
description: 'The address of the host containing the docker daemon'
|
|
|
|
alias: 'h'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
signature: 'dockerPort'
|
|
|
|
parameter: 'dockerPort'
|
|
|
|
description: 'The port on which the host docker daemon is listening'
|
|
|
|
alias: 'p'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
signature: 'ca'
|
|
|
|
parameter: 'ca'
|
|
|
|
description: 'Docker host TLS certificate authority file'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
signature: 'cert'
|
|
|
|
parameter: 'cert'
|
|
|
|
description: 'Docker host TLS certificate file'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
signature: 'key'
|
|
|
|
parameter: 'key'
|
|
|
|
description: 'Docker host TLS key file'
|
2017-04-24 19:05:18 +00:00
|
|
|
},
|
2017-08-04 12:53:31 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# Use this function to seed an action's list of capitano options
|
|
|
|
# with the docker options. Using this interface means that
|
|
|
|
# all functions using docker will expose the same interface
|
|
|
|
#
|
|
|
|
# NOTE: Care MUST be taken when using the function, so as to
|
|
|
|
# not redefine/override options already provided.
|
|
|
|
exports.appendOptions = (opts) ->
|
|
|
|
appendConnectionOptions(opts).concat [
|
2017-04-24 19:05:18 +00:00
|
|
|
{
|
|
|
|
signature: 'tag'
|
|
|
|
parameter: 'tag'
|
|
|
|
description: 'The alias to the generated image'
|
|
|
|
alias: 't'
|
|
|
|
},
|
2017-05-10 19:02:52 +00:00
|
|
|
{
|
2017-05-11 11:20:24 +00:00
|
|
|
signature: 'buildArg'
|
2017-05-10 19:02:52 +00:00
|
|
|
parameter: 'arg'
|
2017-05-11 11:20:24 +00:00
|
|
|
description: 'Set a build-time variable (eg. "-B \'ARG=value\'"). Can be specified multiple times.'
|
|
|
|
alias: 'B'
|
2017-05-10 19:02:52 +00:00
|
|
|
},
|
2017-04-24 19:05:18 +00:00
|
|
|
{
|
|
|
|
signature: 'nocache'
|
|
|
|
description: "Don't use docker layer caching when building"
|
|
|
|
boolean: true
|
|
|
|
},
|
2017-05-04 12:00:48 +00:00
|
|
|
{
|
|
|
|
signature: 'emulated'
|
|
|
|
description: 'Run an emulated build using Qemu'
|
|
|
|
boolean: true
|
|
|
|
alias: 'e'
|
2017-06-23 15:20:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
signature: 'squash'
|
|
|
|
description: 'Squash newly built layers into a single new layer'
|
|
|
|
boolean: true
|
2017-05-04 12:00:48 +00:00
|
|
|
}
|
2017-03-29 11:03:40 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
exports.generateConnectOpts = generateConnectOpts = (opts) ->
|
2017-06-20 10:48:15 +00:00
|
|
|
Promise = require('bluebird')
|
2017-08-23 12:14:46 +00:00
|
|
|
buildDockerodeOpts = require('dockerode-options')
|
2017-06-20 10:48:15 +00:00
|
|
|
fs = require('mz/fs')
|
|
|
|
_ = require('lodash')
|
|
|
|
|
|
|
|
Promise.try ->
|
|
|
|
connectOpts = {}
|
|
|
|
# Firsly need to decide between a local docker socket
|
|
|
|
# and a host available over a host:port combo
|
|
|
|
if opts.docker? and not opts.dockerHost?
|
|
|
|
# good, local docker socket
|
|
|
|
connectOpts.socketPath = opts.docker
|
|
|
|
else if opts.dockerHost? and not opts.docker?
|
|
|
|
# Good a host is provided, and local socket isn't
|
|
|
|
connectOpts.host = opts.dockerHost
|
|
|
|
connectOpts.port = opts.dockerPort || 2376
|
|
|
|
else if opts.docker? and opts.dockerHost?
|
|
|
|
# Both provided, no obvious way to continue
|
|
|
|
throw new Error("Both a local docker socket and docker host have been provided. Don't know how to continue.")
|
2017-08-23 12:14:46 +00:00
|
|
|
else if process.env.DOCKER_HOST
|
|
|
|
# If no explicit options are provided, use the env
|
|
|
|
connectOpts = buildDockerodeOpts(process.env.DOCKER_HOST)
|
2017-06-20 10:48:15 +00:00
|
|
|
else
|
2017-08-23 12:14:46 +00:00
|
|
|
# No options anywhere, assume default docker local socket
|
2017-06-20 10:48:15 +00:00
|
|
|
connectOpts.socketPath = '/var/run/docker.sock'
|
|
|
|
|
|
|
|
# Now need to check if the user wants to connect over TLS
|
|
|
|
# to the host
|
|
|
|
|
|
|
|
# If any are set...
|
|
|
|
if (opts.ca? or opts.cert? or opts.key?)
|
|
|
|
# but not all
|
|
|
|
if not (opts.ca? and opts.cert? and opts.key?)
|
|
|
|
throw new Error('You must provide a CA, certificate and key in order to use TLS')
|
|
|
|
|
|
|
|
certBodies = {
|
|
|
|
ca: fs.readFile(opts.ca, 'utf-8')
|
|
|
|
cert: fs.readFile(opts.cert, 'utf-8')
|
|
|
|
key: fs.readFile(opts.key, 'utf-8')
|
|
|
|
}
|
|
|
|
return Promise.props(certBodies)
|
|
|
|
.then (toMerge) ->
|
|
|
|
_.merge(connectOpts, toMerge)
|
|
|
|
|
|
|
|
return connectOpts
|
2017-03-29 11:03:40 +00:00
|
|
|
|
|
|
|
exports.tarDirectory = tarDirectory = (dir) ->
|
|
|
|
Promise = require('bluebird')
|
|
|
|
tar = require('tar-stream')
|
|
|
|
klaw = require('klaw')
|
|
|
|
path = require('path')
|
|
|
|
fs = require('mz/fs')
|
|
|
|
streamToPromise = require('stream-to-promise')
|
|
|
|
|
|
|
|
getFiles = ->
|
|
|
|
streamToPromise(klaw(dir))
|
|
|
|
.filter((item) -> not item.stats.isDirectory())
|
|
|
|
.map((item) -> item.path)
|
|
|
|
|
|
|
|
pack = tar.pack()
|
|
|
|
getFiles(dir)
|
|
|
|
.map (file) ->
|
|
|
|
relPath = path.relative(path.resolve(dir), file)
|
|
|
|
Promise.join relPath, fs.stat(file), fs.readFile(file),
|
|
|
|
(filename, stats, data) ->
|
2017-12-11 22:21:21 +00:00
|
|
|
pack.entry({ name: filename, size: stats.size, mode: stats.mode }, data)
|
2017-03-29 11:03:40 +00:00
|
|
|
.then ->
|
|
|
|
pack.finalize()
|
|
|
|
return pack
|
|
|
|
|
2017-05-02 12:27:18 +00:00
|
|
|
cacheHighlightStream = ->
|
|
|
|
colors = require('colors/safe')
|
|
|
|
es = require('event-stream')
|
|
|
|
{ EOL } = require('os')
|
|
|
|
|
|
|
|
extractArrowMessage = (message) ->
|
|
|
|
arrowTest = /^\s*-+>\s*(.+)/i
|
|
|
|
if (match = arrowTest.exec(message))
|
|
|
|
match[1]
|
|
|
|
else
|
|
|
|
undefined
|
|
|
|
|
|
|
|
es.mapSync (data) ->
|
|
|
|
msg = extractArrowMessage(data)
|
|
|
|
if msg? and msg.toLowerCase() == 'using cache'
|
|
|
|
data = colors.bgGreen.black(msg)
|
|
|
|
return data + EOL
|
|
|
|
|
2017-05-10 19:02:52 +00:00
|
|
|
parseBuildArgs = (args, onError) ->
|
|
|
|
_ = require('lodash')
|
|
|
|
if not _.isArray(args)
|
|
|
|
args = [ args ]
|
2017-05-11 11:20:24 +00:00
|
|
|
buildArgs = {}
|
2017-05-10 19:02:52 +00:00
|
|
|
args.forEach (str) ->
|
|
|
|
pair = /^([^\s]+?)=(.*)$/.exec(str)
|
|
|
|
if pair?
|
2017-05-11 11:20:24 +00:00
|
|
|
buildArgs[pair[1]] = pair[2]
|
2017-05-10 19:02:52 +00:00
|
|
|
else
|
|
|
|
onError(str)
|
2017-05-11 11:20:24 +00:00
|
|
|
return buildArgs
|
2017-05-10 19:02:52 +00:00
|
|
|
|
2017-03-29 11:03:40 +00:00
|
|
|
# Pass in the command line parameters and options and also
|
|
|
|
# a function which will return the information about the bundle
|
2017-06-28 16:30:37 +00:00
|
|
|
exports.runBuild = (params, options, getBundleInfo, logger) ->
|
2017-03-29 11:03:40 +00:00
|
|
|
Promise = require('bluebird')
|
|
|
|
dockerBuild = require('resin-docker-build')
|
|
|
|
resolver = require('resin-bundle-resolve')
|
2017-04-24 10:06:53 +00:00
|
|
|
es = require('event-stream')
|
2017-04-28 12:44:40 +00:00
|
|
|
doodles = require('resin-doodles')
|
2017-05-04 12:00:48 +00:00
|
|
|
transpose = require('docker-qemu-transpose')
|
|
|
|
path = require('path')
|
2017-04-24 10:06:53 +00:00
|
|
|
|
2017-03-29 11:03:40 +00:00
|
|
|
# The default build context is the current directory
|
2017-04-24 14:55:54 +00:00
|
|
|
params.source ?= '.'
|
2017-04-24 10:06:53 +00:00
|
|
|
logs = ''
|
2017-05-04 12:00:48 +00:00
|
|
|
# Only used in emulated builds
|
|
|
|
qemuPath = ''
|
|
|
|
|
|
|
|
Promise.try ->
|
|
|
|
return if not (options.emulated and platformNeedsQemu())
|
2017-03-29 11:03:40 +00:00
|
|
|
|
2017-05-04 12:00:48 +00:00
|
|
|
hasQemu()
|
|
|
|
.then (present) ->
|
|
|
|
if !present
|
2017-06-28 16:30:37 +00:00
|
|
|
logger.logInfo('Installing qemu for ARM emulation...')
|
2017-05-04 12:00:48 +00:00
|
|
|
installQemu()
|
|
|
|
.then ->
|
|
|
|
# Copy the qemu binary into the build context
|
|
|
|
copyQemu(params.source)
|
|
|
|
.then (binPath) ->
|
2017-06-14 18:50:24 +00:00
|
|
|
qemuPath = path.relative(params.source, binPath)
|
2017-05-04 12:00:48 +00:00
|
|
|
.then ->
|
|
|
|
# Tar up the directory, ready for the build stream
|
|
|
|
tarDirectory(params.source)
|
2017-03-29 11:03:40 +00:00
|
|
|
.then (tarStream) ->
|
|
|
|
new Promise (resolve, reject) ->
|
|
|
|
hooks =
|
|
|
|
buildSuccess: (image) ->
|
2017-04-28 12:44:40 +00:00
|
|
|
# Show charlie. In the interest of cloud parity,
|
|
|
|
# use console.log, not the standard logging streams
|
2017-05-02 12:27:18 +00:00
|
|
|
doodle = doodles.getDoodle()
|
2017-04-28 12:44:40 +00:00
|
|
|
console.log()
|
2017-05-02 12:27:18 +00:00
|
|
|
console.log(doodle)
|
2017-04-28 12:44:40 +00:00
|
|
|
console.log()
|
|
|
|
|
2017-05-02 12:27:18 +00:00
|
|
|
resolve({ image, log: logs + '\n' + doodle + '\n' } )
|
2017-04-28 12:44:40 +00:00
|
|
|
|
2017-03-29 11:03:40 +00:00
|
|
|
buildFailure: reject
|
|
|
|
buildStream: (stream) ->
|
2017-05-04 12:00:48 +00:00
|
|
|
if options.emulated
|
2017-06-28 16:30:37 +00:00
|
|
|
logger.logInfo('Running emulated build')
|
2017-05-04 12:00:48 +00:00
|
|
|
|
2017-03-29 11:03:40 +00:00
|
|
|
getBundleInfo(options)
|
|
|
|
.then (info) ->
|
|
|
|
if !info?
|
2017-06-28 16:30:37 +00:00
|
|
|
logger.logWarn '''
|
2017-03-29 11:03:40 +00:00
|
|
|
Warning: No architecture/device type or application information provided.
|
|
|
|
Dockerfile/project pre-processing will not be performed.
|
|
|
|
'''
|
2017-05-04 12:00:48 +00:00
|
|
|
return tarStream
|
2017-03-29 11:03:40 +00:00
|
|
|
else
|
|
|
|
[arch, deviceType] = info
|
|
|
|
# Perform type resolution on the project
|
|
|
|
bundle = new resolver.Bundle(tarStream, deviceType, arch)
|
|
|
|
resolver.resolveBundle(bundle, resolver.getDefaultResolvers())
|
|
|
|
.then (resolved) ->
|
2017-06-28 16:30:37 +00:00
|
|
|
logger.logInfo("Building #{resolved.projectType} project")
|
2017-05-04 12:00:48 +00:00
|
|
|
|
|
|
|
return resolved.tarStream
|
|
|
|
.then (buildStream) ->
|
|
|
|
# if we need emulation
|
|
|
|
if options.emulated and platformNeedsQemu()
|
|
|
|
return transpose.transposeTarStream buildStream,
|
2018-01-07 01:57:50 +00:00
|
|
|
hostQemuPath: toPosixPath(qemuPath)
|
2017-06-15 14:36:44 +00:00
|
|
|
containerQemuPath: "/tmp/#{QEMU_BIN_NAME}"
|
2017-05-04 12:00:48 +00:00
|
|
|
else
|
|
|
|
return buildStream
|
|
|
|
.then (buildStream) ->
|
|
|
|
# Send the resolved tar stream to the docker daemon
|
|
|
|
buildStream.pipe(stream)
|
2017-03-29 11:03:40 +00:00
|
|
|
.catch(reject)
|
|
|
|
|
2017-04-24 10:06:53 +00:00
|
|
|
# And print the output
|
2017-05-04 12:00:48 +00:00
|
|
|
logThroughStream = es.through (data) ->
|
2017-04-24 10:06:53 +00:00
|
|
|
logs += data.toString()
|
|
|
|
this.emit('data', data)
|
|
|
|
|
2017-05-04 12:00:48 +00:00
|
|
|
if options.emulated and platformNeedsQemu()
|
|
|
|
buildThroughStream = transpose.getBuildThroughStream
|
2018-01-07 01:57:50 +00:00
|
|
|
hostQemuPath: toPosixPath(qemuPath)
|
2017-06-15 14:36:44 +00:00
|
|
|
containerQemuPath: "/tmp/#{QEMU_BIN_NAME}"
|
2017-05-04 12:00:48 +00:00
|
|
|
|
|
|
|
newStream = stream.pipe(buildThroughStream)
|
|
|
|
else
|
|
|
|
newStream = stream
|
|
|
|
|
|
|
|
newStream
|
|
|
|
.pipe(logThroughStream)
|
2017-05-02 12:27:18 +00:00
|
|
|
.pipe(cacheHighlightStream())
|
2017-06-28 16:30:37 +00:00
|
|
|
.pipe(logger.streams.build)
|
2017-03-29 11:03:40 +00:00
|
|
|
|
|
|
|
# Create a builder
|
2017-06-20 10:48:15 +00:00
|
|
|
generateConnectOpts(options)
|
2017-08-10 19:40:05 +00:00
|
|
|
.tap (connectOpts) ->
|
|
|
|
ensureDockerSeemsAccessible(connectOpts)
|
2017-06-20 10:48:15 +00:00
|
|
|
.then (connectOpts) ->
|
|
|
|
# Allow degugging output, hidden behind an env var
|
2017-06-28 16:30:37 +00:00
|
|
|
logger.logDebug('Connecting with the following options:')
|
|
|
|
logger.logDebug(JSON.stringify(connectOpts, null, ' '))
|
2017-03-29 11:03:40 +00:00
|
|
|
|
2017-06-20 10:48:15 +00:00
|
|
|
builder = new dockerBuild.Builder(connectOpts)
|
|
|
|
opts = {}
|
2017-03-29 11:03:40 +00:00
|
|
|
|
2017-06-20 10:48:15 +00:00
|
|
|
if options.tag?
|
|
|
|
opts['t'] = options.tag
|
|
|
|
if options.nocache?
|
|
|
|
opts['nocache'] = true
|
|
|
|
if options.buildArg?
|
|
|
|
opts['buildargs'] = parseBuildArgs options.buildArg, (arg) ->
|
2017-06-28 16:30:37 +00:00
|
|
|
logger.logWarn("Could not parse variable: '#{arg}'")
|
2017-06-23 15:20:16 +00:00
|
|
|
if options.squash?
|
|
|
|
opts['squash'] = true
|
2017-03-29 11:03:40 +00:00
|
|
|
|
2017-06-20 10:48:15 +00:00
|
|
|
builder.createBuildStream(opts, hooks, reject)
|
2017-03-29 11:03:40 +00:00
|
|
|
|
2017-06-13 17:28:37 +00:00
|
|
|
# Given an image id or tag, export the image to a tar archive,
|
|
|
|
# gzip the result, and buffer it to disk.
|
2017-06-13 17:28:37 +00:00
|
|
|
exports.bufferImage = (docker, imageId, bufferFile) ->
|
|
|
|
Promise = require('bluebird')
|
2017-06-13 17:28:37 +00:00
|
|
|
streamUtils = require('./streams')
|
2017-03-29 11:03:40 +00:00
|
|
|
|
|
|
|
image = docker.getImage(imageId)
|
2017-06-13 17:28:37 +00:00
|
|
|
imageMetadata = image.inspectAsync()
|
|
|
|
|
2017-06-15 10:34:26 +00:00
|
|
|
Promise.join image.get(), imageMetadata.get('Size'), (imageStream, imageSize) ->
|
2017-06-13 17:28:37 +00:00
|
|
|
streamUtils.buffer(imageStream, bufferFile)
|
|
|
|
.tap (bufferedStream) ->
|
|
|
|
bufferedStream.length = imageSize
|
2017-03-29 11:03:40 +00:00
|
|
|
|
|
|
|
exports.getDocker = (options) ->
|
2017-06-20 10:48:15 +00:00
|
|
|
generateConnectOpts(options)
|
2017-08-10 19:40:05 +00:00
|
|
|
.tap (connectOpts) ->
|
|
|
|
ensureDockerSeemsAccessible(connectOpts)
|
2017-12-06 21:16:41 +00:00
|
|
|
.then(createClient)
|
|
|
|
|
|
|
|
exports.createClient = createClient = do ->
|
|
|
|
# docker-toolbelt v3 is not backwards compatible as it removes all *Async
|
|
|
|
# methods that are in wide use in the CLI. The workaround for now is to
|
|
|
|
# manually promisify the client and replace all `new Docker()` calls with
|
|
|
|
# this shared function that returns a promisified client.
|
|
|
|
#
|
|
|
|
# **New code must not use the *Async methods.**
|
|
|
|
#
|
|
|
|
Docker = require('docker-toolbelt')
|
|
|
|
Promise = require('bluebird')
|
|
|
|
Promise.promisifyAll Docker.prototype, {
|
|
|
|
filter: (name) -> name == 'run'
|
|
|
|
multiArgs: true
|
|
|
|
}
|
|
|
|
Promise.promisifyAll(Docker.prototype)
|
|
|
|
Promise.promisifyAll(new Docker({}).getImage().constructor.prototype)
|
|
|
|
Promise.promisifyAll(new Docker({}).getContainer().constructor.prototype)
|
|
|
|
|
|
|
|
return (opts) ->
|
|
|
|
return new Docker(opts)
|
2017-03-29 11:03:40 +00:00
|
|
|
|
2017-08-10 19:40:05 +00:00
|
|
|
ensureDockerSeemsAccessible = (options) ->
|
|
|
|
fs = require('mz/fs')
|
|
|
|
|
|
|
|
if options.socketPath?
|
|
|
|
# If we're trying to use a socket, check it exists and we have access to it
|
2017-11-11 11:29:49 +00:00
|
|
|
fs.access(options.socketPath, (fs.constants || fs).R_OK | (fs.constants || fs).W_OK)
|
2017-08-10 19:40:05 +00:00
|
|
|
.return(true)
|
|
|
|
.catch (err) ->
|
|
|
|
throw new Error(
|
|
|
|
"Docker seems to be unavailable (using socket #{options.socketPath}). Is it
|
|
|
|
installed, and do you have permission to talk to it?"
|
|
|
|
)
|
|
|
|
else
|
|
|
|
# Otherwise, we think we're probably ok
|
|
|
|
Promise.resolve(true)
|
|
|
|
|
2017-05-04 12:00:48 +00:00
|
|
|
hasQemu = ->
|
|
|
|
fs = require('mz/fs')
|
|
|
|
|
|
|
|
getQemuPath()
|
|
|
|
.then(fs.stat)
|
|
|
|
.return(true)
|
|
|
|
.catchReturn(false)
|
|
|
|
|
|
|
|
getQemuPath = ->
|
|
|
|
resin = require('resin-sdk-preconfigured')
|
|
|
|
path = require('path')
|
|
|
|
fs = require('mz/fs')
|
|
|
|
|
|
|
|
resin.settings.get('binDirectory')
|
|
|
|
.then (binDir) ->
|
|
|
|
# The directory might not be created already,
|
|
|
|
# if not, create it
|
|
|
|
fs.access(binDir)
|
|
|
|
.catch code: 'ENOENT', ->
|
|
|
|
fs.mkdir(binDir)
|
|
|
|
.then ->
|
|
|
|
path.join(binDir, QEMU_BIN_NAME)
|
|
|
|
|
|
|
|
platformNeedsQemu = ->
|
|
|
|
os = require('os')
|
|
|
|
os.platform() == 'linux'
|
|
|
|
|
|
|
|
installQemu = ->
|
|
|
|
request = require('request')
|
|
|
|
fs = require('fs')
|
|
|
|
zlib = require('zlib')
|
|
|
|
|
|
|
|
getQemuPath()
|
|
|
|
.then (qemuPath) ->
|
|
|
|
new Promise (resolve, reject) ->
|
|
|
|
installStream = fs.createWriteStream(qemuPath)
|
|
|
|
qemuUrl = "https://github.com/resin-io/qemu/releases/download/#{QEMU_VERSION}/#{QEMU_BIN_NAME}.gz"
|
|
|
|
request(qemuUrl)
|
|
|
|
.pipe(zlib.createGunzip())
|
|
|
|
.pipe(installStream)
|
|
|
|
.on('error', reject)
|
|
|
|
.on('finish', resolve)
|
|
|
|
|
|
|
|
copyQemu = (context) ->
|
|
|
|
path = require('path')
|
|
|
|
fs = require('mz/fs')
|
|
|
|
# Create a hidden directory in the build context, containing qemu
|
|
|
|
binDir = path.join(context, '.resin')
|
|
|
|
binPath = path.join(binDir, QEMU_BIN_NAME)
|
|
|
|
|
|
|
|
fs.access(binDir)
|
|
|
|
.catch code: 'ENOENT', ->
|
|
|
|
fs.mkdir(binDir)
|
|
|
|
.then ->
|
|
|
|
getQemuPath()
|
|
|
|
.then (qemu) ->
|
|
|
|
new Promise (resolve, reject) ->
|
|
|
|
read = fs.createReadStream(qemu)
|
|
|
|
write = fs.createWriteStream(binPath)
|
|
|
|
read
|
|
|
|
.pipe(write)
|
|
|
|
.on('error', reject)
|
|
|
|
.on('finish', resolve)
|
|
|
|
.then ->
|
|
|
|
fs.chmod(binPath, '755')
|
|
|
|
.return(binPath)
|
2018-01-07 01:57:50 +00:00
|
|
|
|
|
|
|
toPosixPath = (systemPath) ->
|
|
|
|
path = require('path')
|
|
|
|
systemPath.replace(new RegExp('\\' + path.sep, 'g'), '/')
|