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;
|
2017-08-28 00:24:06 +00:00
|
|
|
case 'login':
|
2017-09-12 19:02:41 +00:00
|
|
|
case 'prepare':
|
2017-08-28 00:24:06 +00:00
|
|
|
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:
|
2017-08-28 00:24:06 +00:00
|
|
|
plugins.beautylog.error(`>>npmci docker ...<< action >>${action}<< not supported`);
|
2017-08-27 13:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2017-08-28 00:24:06 +00:00
|
|
|
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* () {
|
2017-08-28 00:24:06 +00:00
|
|
|
yield exports.prepare();
|
2017-08-27 23:03:59 +00:00
|
|
|
plugins.beautylog.log('now building Dockerfiles...');
|
|
|
|
yield helpers.readDockerfiles()
|
|
|
|
.then(helpers.sortDockerfiles)
|
|
|
|
.then(helpers.mapDockerfiles)
|
|
|
|
.then(helpers.buildDockerfiles);
|
|
|
|
});
|
2017-08-28 00:24:06 +00:00
|
|
|
/**
|
|
|
|
* 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* () {
|
2017-08-28 00:24:06 +00:00
|
|
|
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 dockerfileArray = yield helpers.readDockerfiles()
|
|
|
|
.then(helpers.sortDockerfiles)
|
|
|
|
.then(helpers.mapDockerfiles);
|
|
|
|
let localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg);
|
2017-08-28 00:24:06 +00:00
|
|
|
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* () {
|
2017-08-28 00:24:06 +00:00
|
|
|
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);
|
|
|
|
let dockerfileArray = yield helpers.readDockerfiles()
|
|
|
|
.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* () {
|
2017-08-28 00:24:06 +00:00
|
|
|
yield exports.prepare();
|
2017-08-27 23:03:59 +00:00
|
|
|
return yield helpers.readDockerfiles()
|
|
|
|
.then(helpers.testDockerfiles);
|
2017-08-27 13:24:17 +00:00
|
|
|
});
|
2017-10-09 16:10:01 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2RfZG9ja2VyL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBd0M7QUFJeEMseUNBQXdDO0FBWXRDLDBCQUFPO0FBVlQsVUFBV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