adm-build
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -10,3 +10,3 @@ #!/usr/bin/env node | ||
var argv = process.argv; | ||
var argv = process.argv.slice(2); | ||
var $0 = process.env.CMD ? process.env.CMD : path.basename(argv[1]); | ||
@@ -16,3 +16,4 @@ var app = $0.split(' ')[0]; | ||
yargs(argv.slice(2)) | ||
var build = require('..'); | ||
yargs(argv) | ||
.usage('Usage: ' + $0 + ' <target> [options]') | ||
@@ -23,28 +24,3 @@ .version(pkg.version) | ||
.alias('h', 'help') | ||
.options({ | ||
'a': { | ||
alias: 'arch', | ||
choices: ['all', 'armhf', 'amd64', 'none'], | ||
default: 'armhf', | ||
describe: 'Set target arch' | ||
}, | ||
'f': { | ||
alias: 'format', | ||
choices: ['all', 'deb', 'snappy', 'none'], | ||
default: 'deb', | ||
describe: 'Specify the package format' | ||
}, | ||
't': { | ||
alias: 'type', | ||
choices: ['auto', 'driver', 'app', 'core'], | ||
default: 'auto', | ||
describe: 'Specify the package type for dobox' | ||
}, | ||
'r': { | ||
alias: 'root', | ||
type: 'string', | ||
default: '/opt/dolink', | ||
describe: 'Set the installation root path' | ||
} | ||
}); | ||
.options(build.options || {}); | ||
@@ -57,5 +33,5 @@ var options = yargs.argv; | ||
require('..')(options); | ||
build(options); | ||
@@ -9,6 +9,6 @@ 'use strict'; | ||
[ | ||
'PATH=' + options.contHome + '/node/bin:$PATH', | ||
'npm install --production --unsafe-perm;' | ||
'PATH=' + options.contHome + '/node/bin:' + options.contToolsPath + ':$PATH', | ||
'npm rebuild;' | ||
].join(' ') | ||
]); | ||
}; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
'PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig', | ||
'PATH=' + options.contHome + '/node/bin:$PATH', | ||
'PATH=' + options.contHome + '/node/bin:' + options.contToolsPath + ':$PATH', | ||
'CC=arm-linux-gnueabihf-gcc', | ||
@@ -20,5 +20,5 @@ 'CXX=arm-linux-gnueabihf-g++', | ||
'npm_config_nodedir=' + options.contHome + '/node-src', | ||
'npm install --production --unsafe-perm --arch=arm --target_arch=arm;' | ||
'npm rebuild --production --unsafe-perm --arch=arm --target_arch=arm;' | ||
].join(' ') | ||
]); | ||
}; |
@@ -8,9 +8,23 @@ 'use strict'; | ||
var ncp = require('ncp'); | ||
var docker = require('./docker'); | ||
var ig = ignore().addIgnoreFile( | ||
ignore.select([path.resolve(__dirname, 'ignore')]) | ||
); | ||
function createIgnore(ignores) { | ||
var ig = ignore(); | ||
function copy(source, target) { | ||
if (ignores) { | ||
ig.addPattern(ignores); | ||
} | ||
ig.addIgnoreFile(ignore.select([path.resolve(__dirname, 'ignore')])); | ||
return ig; | ||
} | ||
exports.copy = copy; | ||
function copy(source, target, options) { | ||
options = options || {}; | ||
var ig = createIgnore(options.ignores || options.ignore); | ||
return new Promise(function (resolve, reject) { | ||
@@ -24,8 +38,9 @@ ncp(source, target, {filter: ig.createFilter()}, function (err) { | ||
exports.build = function (options, arch, cmd) { | ||
exports.build = build; | ||
function build(options, arch, cmd) { | ||
var hostBuildPath = path.join(options.hostBuildRoot, arch); | ||
var contBuildPath = path.join(options.contBuildRoot, arch); | ||
return P.resolve() | ||
.then(function () { | ||
// log.debug('copy', 'Copying %s -> %s', options.hostRoot, hostBuildPath); | ||
if (fs.existsSync(hostBuildPath)) { | ||
@@ -35,9 +50,14 @@ fs.removeSync(hostBuildPath); | ||
fs.ensureDirSync(hostBuildPath); | ||
// copy host root sources to build path ignore .build | ||
return copy(options.hostRoot, hostBuildPath); | ||
// copy staging files to host building path | ||
return copy(options.staging, hostBuildPath); | ||
}) | ||
.then(function () { | ||
cmd = ['/bin/bash', '-c', '\'', 'BUILD_DIR="' + contBuildPath + '";'].concat(cmd).concat(['\'']); | ||
cmd = [ | ||
'/bin/bash', '-c', '\'', | ||
'BUILD_DIR="' + contBuildPath + '";', | ||
'TOOLS_DIR="' + options.contToolsPath + '";' | ||
].concat(cmd).concat(['\'']); | ||
return docker.runNativeDockerCrossCommand(options.mountArgs, cmd); | ||
}); | ||
}; | ||
} | ||
112
lib/index.js
@@ -7,3 +7,2 @@ 'use strict'; | ||
var fs = require('fs-extra'); | ||
var sh = require('shelljs'); | ||
var ncp = require('ncp'); | ||
@@ -14,2 +13,4 @@ var async = require('async'); | ||
var tmp = require('tmp'); | ||
var sh = require('shelljs'); | ||
var common = require('./common'); | ||
@@ -20,3 +21,2 @@ var utils = require('./utils'); | ||
build.describe = ['build <target> [options]', 'Build the project']; | ||
build.options = { | ||
@@ -43,5 +43,16 @@ 'a': { | ||
alias: 'root', | ||
type: 'string', | ||
default: '/opt/dolink', | ||
describe: 'Set the installation root path' | ||
}, | ||
'm': { | ||
alias: 'maintainer', | ||
default: 'djhaskin987@djhaskin987-S301LA', | ||
describe: 'The maintainer of this package.' | ||
}, | ||
'url': { | ||
default: 'http://example.com/no-uri-given', | ||
describe: 'Add a url for this package.' | ||
}, | ||
'pack': { | ||
default: true, | ||
describe: 'Pack module' | ||
} | ||
@@ -53,7 +64,6 @@ }; | ||
var cwd = options._[0]; | ||
cwd = path.resolve(process.cwd(), cwd); | ||
var target = options._[0]; | ||
target = path.resolve(process.cwd(), target); | ||
var pkg = require('./pkg')(target); | ||
var pkg = require('./pkg')(cwd); | ||
return docker.verifyDockerImages().then(function () { | ||
@@ -70,3 +80,3 @@ | ||
utils.infoprop('Target arch: ', archs); | ||
utils.infoprop('Target arch :', archs); | ||
@@ -80,21 +90,35 @@ if (options.format === 'all') { | ||
} | ||
utils.infoprop('Build type: ', formats); | ||
utils.infoprop('Build type :', formats); | ||
utils.infoprop('Package Type: ', options.type); | ||
utils.infoprop('Package name: ', pkg.name); | ||
utils.infoprop('Package title: ', pkg.title); | ||
utils.infoprop('Version: ', pkg.version); | ||
utils.infoprop('Package Type :', options.type); | ||
utils.infoprop('Package name :', pkg.name); | ||
utils.infoprop('Package title :', pkg.title); | ||
utils.infoprop('Version :', pkg.version); | ||
var contHome = '/home/builder'; | ||
var hostRoot = cwd; | ||
var contRoot = path.join(contHome, pkg.name); | ||
var hostAppRoot = target; | ||
var contAppRoot = path.join(contHome, pkg.name); | ||
var buildOptions = { | ||
mountArgs: ['-v', hostRoot + ':' + contRoot], | ||
var hostToolsPath = path.join(__dirname, 'tools'); | ||
var contToolsPath = path.join(contHome, 'tools'); | ||
var mountArgs = [ | ||
// '-v', hostToolsPath + ':' + contToolsPath, | ||
'-v', hostAppRoot + ':' + contAppRoot | ||
]; | ||
var stagingobj = tmp.dirSync({unsafeCleanup: true}); | ||
var staging = stagingobj.name; | ||
var context = { | ||
mountArgs: mountArgs, | ||
contHome: contHome, | ||
hostRoot: hostRoot, | ||
contRoot: contRoot, | ||
hostBuildRoot: path.join(hostRoot, '.build'), | ||
contBuildRoot: path.join(contRoot, '.build') | ||
staging: staging, // staging path | ||
hostAppRoot: hostAppRoot, | ||
contAppRoot: contAppRoot, | ||
hostToolsPath: hostToolsPath, | ||
contToolsPath: contToolsPath, | ||
hostBuildRoot: path.join(hostAppRoot, '.build'), | ||
contBuildRoot: path.join(contAppRoot, '.build') | ||
}; | ||
@@ -104,14 +128,27 @@ | ||
promise = promise.then(function () { | ||
log.debug('build', 'Copying application files to staging path %s', staging); | ||
// npm install in production | ||
return common.copy(hostAppRoot, staging, {ignore: 'node_modules'}); | ||
}); | ||
promise = promise.then(function () { | ||
log.debug('build', 'Fetching production dependencies for staging'); | ||
// only install dependencies without running scripts. | ||
sh.exec('npm install --production --unsafe-perm --ignore-scripts', {async: false, cwd: staging}); | ||
}); | ||
var builders = needs(__dirname, 'builders'); | ||
promise = promise.then(function () { | ||
log.debug('build', 'Building application for architectures %j', archs); | ||
return P.each(archs, function (arch) { | ||
if (!builders[arch]) throw new Error('Unknown architecture: ' + arch); | ||
log.info('build', 'Building for architecture ' + arch); | ||
return builders[arch](buildOptions, log); | ||
return builders[arch](context, log); | ||
}); | ||
}); | ||
var context = _.assign({}, buildOptions, { | ||
hostDistRoot: path.join(hostRoot, '.dist'), | ||
contDistRoot: path.join(contRoot, '.dist'), | ||
_.assign(context, { | ||
hostDistRoot: path.join(hostAppRoot, '.dist'), | ||
contDistRoot: path.join(contAppRoot, '.dist'), | ||
options: options, | ||
@@ -122,15 +159,18 @@ pkg: pkg, | ||
var packagers = needs(__dirname, 'packagers'); | ||
promise = promise.then(function () { | ||
return P.each(formats, function (format) { | ||
if (!packagers[format]) throw new Error('Unknown package format: ' + format); | ||
log.info('pack', 'Packing to ' + format); | ||
return P.each(archs, function (arch) { | ||
return packagers[format](context, arch, log); | ||
if (options.pack) { | ||
var packagers = needs(__dirname, 'packagers'); | ||
promise = promise.then(function () { | ||
return P.each(formats, function (format) { | ||
if (!packagers[format]) throw new Error('Unknown package format: ' + format); | ||
log.info('pack', 'Packing to ' + format); | ||
return P.each(archs, function (arch) { | ||
return packagers[format](context, arch, log); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
return promise.then(function () { | ||
log.info('build', 'Built successful'); | ||
stagingobj.removeCallback(); | ||
log.info('build', 'Built successful!'); | ||
}); | ||
@@ -142,3 +182,1 @@ }); | ||
module.exports = build; | ||
@@ -11,3 +11,3 @@ 'use strict'; | ||
var DIR_MODE = parseInt('755', 8); | ||
var DEFAULT_ROOT = process.env.ADM_PATH || '/opt'; | ||
@@ -26,7 +26,7 @@ module.exports = function (ctx, arch, log) { | ||
var customPackConf = path.join(ctx.hostRoot, 'ddupack', 'conf'); | ||
var customPackRoot = path.join(ctx.hostRoot, 'ddupack', 'root'); | ||
var customPackConf = path.join(ctx.hostAppRoot, 'admpack', 'conf'); | ||
var customPackRoot = path.join(ctx.hostAppRoot, 'admpack', 'root'); | ||
if (fs.existsSync(customPackRoot)) { | ||
// copy [PROJ]/ddupack/root -> [PROJ]/.dist/debian-[arch] | ||
// copy [PROJ]/admpack/root -> [PROJ]/.dist/debian-[arch] | ||
log.debug('pack-deb', 'Copying custom root files from "%s" to "%s"', customPackRoot, hostDist); | ||
@@ -56,4 +56,7 @@ fs.copySync(customPackRoot, hostDist); | ||
var root = options.root || DEFAULT_ROOT; | ||
console.log('install root', root); | ||
// Copy built files to dist path | ||
var targetPath = path.join(hostDist, options.root, packageDir, pkg.name); | ||
var targetPath = path.join(hostDist, root, packageDir, pkg.name); | ||
fs.ensureDirSync(targetPath); | ||
@@ -64,3 +67,3 @@ fs.copySync(hostBuildPath, targetPath); | ||
var tplctx = { | ||
basePath: options.root, // installation path | ||
basePath: root, // installation path | ||
packageDir: packageDir, // package dir | ||
@@ -92,3 +95,3 @@ name: pkg.name // module name | ||
var packageFileName = util.format('%s_%s_%s.deb', pkg.name, pkg.version, arch); | ||
var packageFilePath = path.join(ctx.hostRoot, packageFileName); | ||
var packageFilePath = path.join(ctx.hostAppRoot, packageFileName); | ||
@@ -101,4 +104,4 @@ var cmd = [ | ||
'--category', 'web', | ||
'-m', utils.quote('Dolink CLI Builder <builder@dolink.co>'), | ||
'--url', utils.quote('http://dolink.co/'), | ||
'-m', utils.quote(options.maintainer), | ||
'--url', utils.quote(options.url), | ||
'-n', utils.quote(pkg.name), | ||
@@ -116,3 +119,3 @@ '-v', utils.quote(pkg.version), | ||
log.info('pack-deb', 'Packing %s for architecture %s in formatting %s to %s', pkg.name, arch, 'deb', packageFilePath); | ||
log.info('deb', 'Packing %s for architecture %s in formatting %s to %s', pkg.name, arch, 'deb', packageFilePath); | ||
return docker.runNativeDockerCommand(ctx.mountArgs, cmd).then(function () { | ||
@@ -119,0 +122,0 @@ // fs.removeSync(hostDist); |
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
@@ -7,4 +8,8 @@ var util = require('util'); | ||
module.exports = function (location) { | ||
var pkgdir = path.resolve(location, 'package.json'); | ||
if (!fs.existsSync(pkgdir)) { | ||
throw new Error(util.format('Could not find package.json in "%s"', location)); | ||
} | ||
try { | ||
var pkg = require(path.resolve(location, 'package.json')); | ||
var pkg = require(pkgdir); | ||
pkg.location = path.resolve(location); | ||
@@ -11,0 +16,0 @@ pkg.title = pkg.title || pkg.name; |
{ | ||
"name": "adm-build", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Build nodejs application to arm or amd64 package", | ||
@@ -5,0 +5,0 @@ "homepage": "", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
24793
497
9