130 lines
9.7 KiB
JavaScript
130 lines
9.7 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':
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2RfZG9ja2VyL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSx5Q0FBd0M7QUFJeEMseUNBQXdDO0FBWXRDLDBCQUFPO0FBVlQsVUFBVTtBQUNWLHFFQUFxRDtBQVFuRCxxQkFSTyxtQ0FBVSxDQVFQO0FBUFosNkVBQTZEO0FBQzdELCtFQUErRDtBQUUvRCxZQUFZO0FBQ1osSUFBSSxvQkFBb0IsR0FBRyxJQUFJLDZDQUFlLEVBQUUsQ0FBQTtBQVNoRDs7O0dBR0c7QUFDUSxRQUFBLFNBQVMsR0FBRyxDQUFPLE9BQU87SUFDbkMsa0JBQVUsR0FBRyxPQUFPLENBQUE7SUFDcEIsRUFBRSxDQUFDLENBQ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