"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9tb2RfZG9ja2VyL2luZGV4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