npmci/dist/mod_docker/index.js

133 lines
9.9 KiB
JavaScript
Raw Normal View History

2017-05-18 20:40:09 +00:00
"use strict";
2017-08-27 13:24:17 +00:00
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
2017-05-18 20:40:09 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2017-08-27 13:24:17 +00:00
const plugins = require("./mod.plugins");
2017-08-27 23:03:59 +00:00
const helpers = require("./mod.helpers");
exports.helpers = helpers;
// classes
const mod_classes_dockerfile_1 = require("./mod.classes.dockerfile");
exports.Dockerfile = mod_classes_dockerfile_1.Dockerfile;
const mod_classes_dockerregistry_1 = require("./mod.classes.dockerregistry");
const mod_classes_registrystorage_1 = require("./mod.classes.registrystorage");
// instances
let npmciRegistryStorage = new mod_classes_registrystorage_1.RegistryStorage();
2017-08-27 13:24:17 +00:00
/**
* handle cli input
* @param argvArg
*/
exports.handleCli = (argvArg) => __awaiter(this, void 0, void 0, function* () {
exports.modArgvArg = argvArg;
if (argvArg._.length >= 2) {
let action = argvArg._[1];
switch (action) {
case 'build':
yield exports.build();
break;
case 'login':
2017-09-12 19:02:41 +00:00
case 'prepare':
yield exports.login();
2017-08-27 13:24:17 +00:00
break;
case 'test':
yield exports.test();
break;
2017-08-27 23:03:59 +00:00
case 'push':
yield exports.push(argvArg);
break;
case 'pull':
yield exports.pull(argvArg);
break;
2017-08-27 13:24:17 +00:00
default:
plugins.beautylog.error(`>>npmci docker ...<< action >>${action}<< not supported`);
2017-08-27 13:24:17 +00:00
}
}
else {
plugins.beautylog.log(`>>npmci docker ...<< cli arguments invalid... Please read the documentation.`);
2017-08-27 13:24:17 +00:00
}
});
2017-08-27 23:03:59 +00:00
/**
* builds a cwd of Dockerfiles by triggering a promisechain
*/
exports.build = () => __awaiter(this, void 0, void 0, function* () {
yield exports.prepare();
2017-08-27 23:03:59 +00:00
plugins.beautylog.log('now building Dockerfiles...');
2018-04-04 20:25:13 +00:00
yield helpers
.readDockerfiles()
2017-08-27 23:03:59 +00:00
.then(helpers.sortDockerfiles)
.then(helpers.mapDockerfiles)
.then(helpers.buildDockerfiles);
});
/**
* login to the DockerRegistries
*/
exports.login = () => __awaiter(this, void 0, void 0, function* () {
yield exports.prepare();
yield npmciRegistryStorage.loginAll();
});
2017-08-27 13:24:17 +00:00
/**
* logs in docker
*/
exports.prepare = () => __awaiter(this, void 0, void 0, function* () {
// Always login to GitLab Registry
if (!process.env.CI_BUILD_TOKEN || process.env.CI_BUILD_TOKEN === '') {
plugins.beautylog.error('No registry token specified by gitlab!');
2017-08-27 23:35:21 +00:00
process.exit(1);
2017-08-27 13:24:17 +00:00
}
2017-08-27 23:03:59 +00:00
npmciRegistryStorage.addRegistry(new mod_classes_dockerregistry_1.DockerRegistry({
registryUrl: 'registry.gitlab.com',
username: 'gitlab-ci-token',
password: process.env.CI_BUILD_TOKEN
}));
// handle registries
2017-08-27 23:35:21 +00:00
yield plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_LOGIN_DOCKER*', (envString) => __awaiter(this, void 0, void 0, function* () {
2017-08-27 23:03:59 +00:00
npmciRegistryStorage.addRegistry(mod_classes_dockerregistry_1.DockerRegistry.fromEnvString(envString));
}));
2017-08-27 13:24:17 +00:00
return;
});
2017-08-27 23:03:59 +00:00
exports.push = (argvArg) => __awaiter(this, void 0, void 0, function* () {
yield exports.prepare();
2017-08-27 23:03:59 +00:00
let registryUrlArg = argvArg._[2];
let suffix = null;
if (argvArg._.length >= 4) {
suffix = argvArg._[3];
}
2018-04-04 20:25:13 +00:00
let dockerfileArray = yield helpers
.readDockerfiles()
2017-08-27 23:03:59 +00:00
.then(helpers.sortDockerfiles)
.then(helpers.mapDockerfiles);
let localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg);
if (!localDockerRegistry) {
plugins.beautylog.error(`Cannot push to registry ${registryUrlArg}, because it was not found in the authenticated registry list.`);
process.exit(1);
}
2017-08-27 23:03:59 +00:00
for (let dockerfile of dockerfileArray) {
2017-08-28 00:36:23 +00:00
yield dockerfile.push(localDockerRegistry, suffix);
2017-08-27 13:24:17 +00:00
}
});
2017-08-27 23:03:59 +00:00
exports.pull = (argvArg) => __awaiter(this, void 0, void 0, function* () {
yield exports.prepare();
2017-08-27 23:03:59 +00:00
let registryUrlArg = argvArg._[2];
let suffix = null;
if (argvArg._.length >= 4) {
suffix = argvArg._[3];
}
let localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg);
2018-04-04 20:25:13 +00:00
let dockerfileArray = yield helpers
.readDockerfiles()
2017-08-27 23:03:59 +00:00
.then(helpers.sortDockerfiles)
.then(helpers.mapDockerfiles);
for (let dockerfile of dockerfileArray) {
2017-08-28 00:36:23 +00:00
yield dockerfile.pull(localDockerRegistry, suffix);
2017-08-27 13:24:17 +00:00
}
});
2017-08-27 23:03:59 +00:00
exports.test = () => __awaiter(this, void 0, void 0, function* () {
yield exports.prepare();
2018-04-04 20:25:13 +00:00
return yield helpers.readDockerfiles().then(helpers.testDockerfiles);
2017-08-27 13:24:17 +00:00
});
2018-04-04 20:25:13 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2RfZG9ja2VyL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBeUM7QUFJekMseUNBQXlDO0FBVXBCLDBCQUFPO0FBUjVCLFVBQVU7QUFDVixxRUFBc0Q7QUFPN0MscUJBUEEsbUNBQVUsQ0FPQT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