131 lines
9.8 KiB
JavaScript
131 lines
9.8 KiB
JavaScript
"use strict";
|
|
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());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const plugins = require("./mod.plugins");
|
|
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();
|
|
/**
|
|
* 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':
|
|
case 'prepare':
|
|
yield exports.login();
|
|
break;
|
|
case 'test':
|
|
yield exports.test();
|
|
break;
|
|
case 'push':
|
|
yield exports.push(argvArg);
|
|
break;
|
|
case 'pull':
|
|
yield exports.pull(argvArg);
|
|
break;
|
|
default:
|
|
plugins.beautylog.error(`>>npmci docker ...<< action >>${action}<< not supported`);
|
|
}
|
|
}
|
|
else {
|
|
plugins.beautylog.log(`>>npmci docker ...<< cli arguments invalid... Please read the documentation.`);
|
|
}
|
|
});
|
|
/**
|
|
* builds a cwd of Dockerfiles by triggering a promisechain
|
|
*/
|
|
exports.build = () => __awaiter(this, void 0, void 0, function* () {
|
|
yield exports.prepare();
|
|
plugins.beautylog.log('now building Dockerfiles...');
|
|
yield helpers.readDockerfiles()
|
|
.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();
|
|
});
|
|
/**
|
|
* 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!');
|
|
process.exit(1);
|
|
}
|
|
npmciRegistryStorage.addRegistry(new mod_classes_dockerregistry_1.DockerRegistry({
|
|
registryUrl: 'registry.gitlab.com',
|
|
username: 'gitlab-ci-token',
|
|
password: process.env.CI_BUILD_TOKEN
|
|
}));
|
|
// handle registries
|
|
yield plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_LOGIN_DOCKER*', (envString) => __awaiter(this, void 0, void 0, function* () {
|
|
npmciRegistryStorage.addRegistry(mod_classes_dockerregistry_1.DockerRegistry.fromEnvString(envString));
|
|
}));
|
|
return;
|
|
});
|
|
exports.push = (argvArg) => __awaiter(this, void 0, void 0, function* () {
|
|
yield exports.prepare();
|
|
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);
|
|
if (!localDockerRegistry) {
|
|
plugins.beautylog.error(`Cannot push to registry ${registryUrlArg}, because it was not found in the authenticated registry list.`);
|
|
process.exit(1);
|
|
}
|
|
for (let dockerfile of dockerfileArray) {
|
|
yield dockerfile.push(localDockerRegistry, suffix);
|
|
}
|
|
});
|
|
exports.pull = (argvArg) => __awaiter(this, void 0, void 0, function* () {
|
|
yield exports.prepare();
|
|
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) {
|
|
yield dockerfile.pull(localDockerRegistry, suffix);
|
|
}
|
|
});
|
|
exports.test = () => __awaiter(this, void 0, void 0, function* () {
|
|
yield exports.prepare();
|
|
return yield helpers.readDockerfiles()
|
|
.then(helpers.testDockerfiles);
|
|
});
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2RfZG9ja2VyL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBd0M7QUFJeEMseUNBQXdDO0FBWXRDLDBCQUFPO0FBVlQsVUFBVTtBQUNWLHFFQUFxRDtBQVFuRCxxQkFSTyxtQ0FBVSxDQVFQO0FBUFosNkVBQTZEO0FBQzdELCtFQUErRDtBQUUvRCxZQUFZO0FBQ1osSUFBSSxvQkFBb0IsR0FBRyxJQUFJLDZDQUFlLEVBQUUsQ0FBQTtBQVNoRDs7O0dBR0c7QUFDUSxRQUFBLFNBQVMsR0FBRyxDQUFPLE9BQU8sRUFBRSxFQUFFO0lBQ3ZDLGtCQUFVLEdBQUcsT0FBTyxD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