fix(core): update

This commit is contained in:
Philipp Kunz 2019-06-19 10:41:58 +02:00
parent ca62326b46
commit 0a49ff9b03
2 changed files with 47 additions and 18 deletions

View File

@ -10,6 +10,9 @@ import { Dockerfile } from './mod.classes.dockerfile';
import { DockerRegistry } from './mod.classes.dockerregistry'; import { DockerRegistry } from './mod.classes.dockerregistry';
import { RegistryStorage } from './mod.classes.registrystorage'; import { RegistryStorage } from './mod.classes.registrystorage';
// config
import { configObject } from '../npmci.config';
// instances // instances
const npmciRegistryStorage = new RegistryStorage(); const npmciRegistryStorage = new RegistryStorage();
@ -98,27 +101,44 @@ export let prepare = async () => {
return; return;
}; };
export let push = async argvArg => { /**
* pushes an image towards a registry
* @param argvArg
*/
export const push = async argvArg => {
await prepare(); 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; let suffix = null;
if (argvArg._.length >= 4) { if (argvArg._.length >= 4) {
suffix = argvArg._[3]; suffix = argvArg._[3];
} }
// lets push to the registries
for (const dockerRegistryUrl of dockerRegistryUrls) {
const dockerfileArray = await helpers const dockerfileArray = await helpers
.readDockerfiles() .readDockerfiles()
.then(helpers.sortDockerfiles) .then(helpers.sortDockerfiles)
.then(helpers.mapDockerfiles); .then(helpers.mapDockerfiles);
const localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg); const dockerRegistryToPushTo = npmciRegistryStorage.getRegistryByUrl(dockerRegistryUrl);
if (!localDockerRegistry) { if (!dockerRegistryToPushTo) {
logger.log( logger.log(
'error', 'error',
`Cannot push to registry ${registryUrlArg}, because it was not found in the authenticated registry list.` `Cannot push to registry ${dockerRegistryUrl}, because it was not found in the authenticated registry list.`
); );
process.exit(1); process.exit(1);
} }
for (const dockerfile of dockerfileArray) { for (const dockerfile of dockerfileArray) {
await dockerfile.push(localDockerRegistry, suffix); await dockerfile.push(dockerRegistryToPushTo, suffix);
}
} }
}; };

View File

@ -5,13 +5,21 @@ import { repo } from './npmci.env';
import { KeyValueStore } from '@pushrocks/npmextra'; import { KeyValueStore } from '@pushrocks/npmextra';
/**
* the main config interface for npmci
*/
export interface INpmciOptions { export interface INpmciOptions {
projectInfo: plugins.projectinfo.ProjectInfo; projectInfo: plugins.projectinfo.ProjectInfo;
// npm
npmGlobalTools: string[]; npmGlobalTools: string[];
npmAccessLevel?: 'private' | 'public'; npmAccessLevel?: 'private' | 'public';
npmRegistryUrl: string; npmRegistryUrl: string;
dockerRegistryRepoMap: any;
dockerBuildargEnvMap: any; // docker
dockerRegistries: string[];
dockerRegistryRepoMap: { [key: string]: string };
dockerBuildargEnvMap: { [key: string]: string };
} }
// instantiate a kvStorage for the current directory // instantiate a kvStorage for the current directory
@ -22,6 +30,7 @@ const npmciNpmextra = new plugins.npmextra.Npmextra(paths.cwd);
const defaultConfig: INpmciOptions = { const defaultConfig: INpmciOptions = {
projectInfo: new plugins.projectinfo.ProjectInfo(paths.cwd), projectInfo: new plugins.projectinfo.ProjectInfo(paths.cwd),
npmGlobalTools: [], npmGlobalTools: [],
dockerRegistries: [],
dockerRegistryRepoMap: {}, dockerRegistryRepoMap: {},
npmAccessLevel: 'private', npmAccessLevel: 'private',
npmRegistryUrl: 'registry.npmjs.org', npmRegistryUrl: 'registry.npmjs.org',