From 0a49ff9b035058da5090dafb7eab9abc127a9a0e Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 19 Jun 2019 10:41:58 +0200 Subject: [PATCH] fix(core): update --- ts/mod_docker/index.ts | 52 +++++++++++++++++++++++++++++------------- ts/npmci.config.ts | 13 +++++++++-- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/ts/mod_docker/index.ts b/ts/mod_docker/index.ts index e7df977..42890b1 100644 --- a/ts/mod_docker/index.ts +++ b/ts/mod_docker/index.ts @@ -10,6 +10,9 @@ import { Dockerfile } from './mod.classes.dockerfile'; import { DockerRegistry } from './mod.classes.dockerregistry'; import { RegistryStorage } from './mod.classes.registrystorage'; +// config +import { configObject } from '../npmci.config'; + // instances const npmciRegistryStorage = new RegistryStorage(); @@ -98,27 +101,44 @@ export let prepare = async () => { return; }; -export let push = async argvArg => { +/** + * pushes an image towards a registry + * @param argvArg + */ +export const push = async argvArg => { await prepare(); - const registryUrlArg = argvArg._[2]; + let dockerRegistryUrls: string[] = []; + + // lets parse the input of cli and npmextra + if (argvArg._.length >= 3 && argvArg._[2] !== 'npmextra') { + dockerRegistryUrls.push(argvArg._[2]); + } else if (configObject.dockerRegistries) { + dockerRegistryUrls = dockerRegistryUrls.concat(configObject.dockerRegistries); + } + + // lets determine the suffix let suffix = null; if (argvArg._.length >= 4) { suffix = argvArg._[3]; } - const dockerfileArray = await helpers - .readDockerfiles() - .then(helpers.sortDockerfiles) - .then(helpers.mapDockerfiles); - const localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg); - if (!localDockerRegistry) { - logger.log( - 'error', - `Cannot push to registry ${registryUrlArg}, because it was not found in the authenticated registry list.` - ); - process.exit(1); - } - for (const dockerfile of dockerfileArray) { - await dockerfile.push(localDockerRegistry, suffix); + + // lets push to the registries + for (const dockerRegistryUrl of dockerRegistryUrls) { + const dockerfileArray = await helpers + .readDockerfiles() + .then(helpers.sortDockerfiles) + .then(helpers.mapDockerfiles); + const dockerRegistryToPushTo = npmciRegistryStorage.getRegistryByUrl(dockerRegistryUrl); + if (!dockerRegistryToPushTo) { + logger.log( + 'error', + `Cannot push to registry ${dockerRegistryUrl}, because it was not found in the authenticated registry list.` + ); + process.exit(1); + } + for (const dockerfile of dockerfileArray) { + await dockerfile.push(dockerRegistryToPushTo, suffix); + } } }; diff --git a/ts/npmci.config.ts b/ts/npmci.config.ts index 8da2b9c..e4a057e 100644 --- a/ts/npmci.config.ts +++ b/ts/npmci.config.ts @@ -5,13 +5,21 @@ import { repo } from './npmci.env'; import { KeyValueStore } from '@pushrocks/npmextra'; +/** + * the main config interface for npmci + */ export interface INpmciOptions { projectInfo: plugins.projectinfo.ProjectInfo; + + // npm npmGlobalTools: string[]; npmAccessLevel?: 'private' | 'public'; npmRegistryUrl: string; - dockerRegistryRepoMap: any; - dockerBuildargEnvMap: any; + + // docker + dockerRegistries: string[]; + dockerRegistryRepoMap: { [key: string]: string }; + dockerBuildargEnvMap: { [key: string]: string }; } // instantiate a kvStorage for the current directory @@ -22,6 +30,7 @@ const npmciNpmextra = new plugins.npmextra.Npmextra(paths.cwd); const defaultConfig: INpmciOptions = { projectInfo: new plugins.projectinfo.ProjectInfo(paths.cwd), npmGlobalTools: [], + dockerRegistries: [], dockerRegistryRepoMap: {}, npmAccessLevel: 'private', npmRegistryUrl: 'registry.npmjs.org',