mediacentral-publish
Version:
A publish tool for publishing cloud-ux projects
55 lines (47 loc) • 2.7 kB
JavaScript
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const { execSync } = require('child_process');
const { mkdirSync, readFileSync, writeFileSync } = require('fs-extra');
const { join } = require('path');
const ejs = require('ejs');
const logger = require.main.require('log4js').getLogger(`mediacentral-publish ${__filename}`);
/**
* @param {String} temp_dir_path must be absolute
* @param {String} project_path
* @param {String} project_name
* @returns {void} void
*/
function copyDockerTemplate(temp_dir_path, project_path, project_name) {
logger.trace('Copy Docker Temple\nTemporary path: ', temp_dir_path, '\n project path: ', project_path, '\nProject name: ', project_name);
mkdirSync(join(temp_dir_path, 'docker'));
mkdirSync(join(temp_dir_path, 'docker', 'build_img'));
// Dist
let image_dockerfile = ejs.render(readFileSync(join(__dirname, 'build_img', 'Dockerfile'), 'utf8'), { projectName: project_name });
// Image
writeFileSync(join(temp_dir_path, 'docker', 'build_img', 'Dockerfile'), image_dockerfile);
}
/**
* @param {String} path must be absolute
* @param {String} dir must be absolute
* @param {String} appName
* @param {String} version
* @param {String} organization
* @param {String} https_proxy
* @returns {{file: String}} file is path to outputed saved docker image.
*/
module.exports = (() => {
var _ref = _asyncToGenerator(function* (path, dir, appName, version, organization, https_proxy) {
logger.trace(`Building Docker with temporary path: `, path, `\nProject Path: `, dir, '\nName of Application: ', appName, `\nApplication version: `, version, `\n Organization: `, organization);
let registry = "local";
let image = `${registry}/${organization}/${appName}:${version}`;
copyDockerTemplate(path, dir, appName);
const command = `docker build -t "${image}" -f "${join(path, 'docker', 'build_img', 'Dockerfile')}" ${https_proxy ? `--build-arg HTTP_PROXY=${https_proxy}` : ''} "${dir}"`;
logger.trace(command);
execSync(command);
return {
file: image
};
});
return function (_x, _x2, _x3, _x4, _x5, _x6) {
return _ref.apply(this, arguments);
};
})();