Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| adfdf68c38 | |||
| d4a4d69941 | |||
| c1fed2c758 | |||
| 9918d81f59 | |||
| 59d8338f6e | |||
| a4f8bd3320 | |||
| 7c2fdb7224 | |||
| 37384aeb57 | |||
| 60efda263f | |||
| 19831037ec | |||
| a1d52af813 | |||
| 0a49ff9b03 |
@@ -1,5 +1,5 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@@ -50,22 +50,10 @@ testLTS:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
|
|||||||
1432
package-lock.json
generated
1432
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@shipzone/npmci",
|
"name": "@shipzone/npmci",
|
||||||
"version": "3.1.29",
|
"version": "3.1.35",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "node and docker in gitlab ci on steroids",
|
"description": "node and docker in gitlab ci on steroids",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
"@pushrocks/smartcli": "^3.0.7",
|
"@pushrocks/smartcli": "^3.0.7",
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartdelay": "^2.0.3",
|
||||||
"@pushrocks/smartfile": "^7.0.2",
|
"@pushrocks/smartfile": "^7.0.2",
|
||||||
|
"@pushrocks/smartgit": "^1.0.9",
|
||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@pushrocks/smartlog": "^2.0.19",
|
||||||
"@pushrocks/smartlog-destination-local": "^8.0.2",
|
"@pushrocks/smartlog-destination-local": "^8.0.2",
|
||||||
"@pushrocks/smartparam": "^1.0.4",
|
"@pushrocks/smartparam": "^1.0.4",
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
@@ -21,7 +24,7 @@ export let modArgvArg; // will be set through the build command
|
|||||||
* handle cli input
|
* handle cli input
|
||||||
* @param argvArg
|
* @param argvArg
|
||||||
*/
|
*/
|
||||||
export let handleCli = async argvArg => {
|
export const handleCli = async argvArg => {
|
||||||
modArgvArg = argvArg;
|
modArgvArg = argvArg;
|
||||||
if (argvArg._.length >= 2) {
|
if (argvArg._.length >= 2) {
|
||||||
const action: string = argvArg._[1];
|
const action: string = argvArg._[1];
|
||||||
@@ -56,7 +59,7 @@ export let handleCli = async argvArg => {
|
|||||||
/**
|
/**
|
||||||
* builds a cwd of Dockerfiles by triggering a promisechain
|
* builds a cwd of Dockerfiles by triggering a promisechain
|
||||||
*/
|
*/
|
||||||
export let build = async () => {
|
export const build = async () => {
|
||||||
await prepare();
|
await prepare();
|
||||||
logger.log('info', 'now building Dockerfiles...');
|
logger.log('info', 'now building Dockerfiles...');
|
||||||
await helpers
|
await helpers
|
||||||
@@ -69,7 +72,7 @@ export let build = async () => {
|
|||||||
/**
|
/**
|
||||||
* login to the DockerRegistries
|
* login to the DockerRegistries
|
||||||
*/
|
*/
|
||||||
export let login = async () => {
|
export const login = async () => {
|
||||||
await prepare();
|
await prepare();
|
||||||
await npmciRegistryStorage.loginAll();
|
await npmciRegistryStorage.loginAll();
|
||||||
};
|
};
|
||||||
@@ -77,7 +80,7 @@ export let login = async () => {
|
|||||||
/**
|
/**
|
||||||
* logs in docker
|
* logs in docker
|
||||||
*/
|
*/
|
||||||
export let prepare = async () => {
|
export const prepare = async () => {
|
||||||
// Always login to GitLab Registry
|
// Always login to GitLab Registry
|
||||||
if (!process.env.CI_BUILD_TOKEN || process.env.CI_BUILD_TOKEN === '') {
|
if (!process.env.CI_BUILD_TOKEN || process.env.CI_BUILD_TOKEN === '') {
|
||||||
logger.log('error', 'No registry token specified by gitlab!');
|
logger.log('error', 'No registry token specified by gitlab!');
|
||||||
@@ -98,31 +101,54 @@ 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.length === 0) {
|
||||||
|
logger.log(
|
||||||
|
'warn',
|
||||||
|
`There are no docker registries listed in npmextra.json! This is strange!`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export let pull = async argvArg => {
|
export const pull = async argvArg => {
|
||||||
await prepare();
|
await prepare();
|
||||||
const registryUrlArg = argvArg._[2];
|
const registryUrlArg = argvArg._[2];
|
||||||
let suffix = null;
|
let suffix = null;
|
||||||
@@ -139,7 +165,10 @@ export let pull = async argvArg => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export let test = async () => {
|
/**
|
||||||
|
* tests docker files
|
||||||
|
*/
|
||||||
|
export const test = async () => {
|
||||||
await prepare();
|
await prepare();
|
||||||
return await helpers.readDockerfiles().then(helpers.testDockerfiles);
|
return await helpers.readDockerfiles().then(helpers.testDockerfiles);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ export let mirror = async () => {
|
|||||||
if (githubToken) {
|
if (githubToken) {
|
||||||
logger.log('info', 'found github token.');
|
logger.log('info', 'found github token.');
|
||||||
logger.log('info', 'attempting the mirror the repository to GitHub');
|
logger.log('info', 'attempting the mirror the repository to GitHub');
|
||||||
|
|
||||||
|
plugins.smartgit.GitRepo
|
||||||
|
|
||||||
// add the mirror
|
// add the mirror
|
||||||
await bash(
|
await bash(
|
||||||
`git remote add mirror https://${githubToken}@github.com/${githubUser}/${githubRepo}.git`
|
`git remote add mirror https://${githubToken}@github.com/${githubUser}/${githubRepo}.git`
|
||||||
|
|||||||
@@ -1 +1,7 @@
|
|||||||
export * from '../npmci.plugins';
|
export * from '../npmci.plugins';
|
||||||
|
|
||||||
|
import * as smartgit from '@pushrocks/smartgit';
|
||||||
|
|
||||||
|
export {
|
||||||
|
smartgit
|
||||||
|
};
|
||||||
|
|||||||
@@ -66,18 +66,25 @@ const prepare = async () => {
|
|||||||
* publish a package to npm
|
* publish a package to npm
|
||||||
*/
|
*/
|
||||||
const publish = async () => {
|
const publish = async () => {
|
||||||
|
const buildPublishCommand = async () => {
|
||||||
let npmAccessCliString = ``;
|
let npmAccessCliString = ``;
|
||||||
let npmRegistryCliString = ``;
|
let npmRegistryCliString = ``;
|
||||||
|
let publishVerdaccioAsWell = false;
|
||||||
const config = await configModule.getConfig();
|
const config = await configModule.getConfig();
|
||||||
|
const availableRegistries: string[] = [];
|
||||||
|
await plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TOKEN_NPM*', npmEnvArg => {
|
||||||
|
availableRegistries.push(npmEnvArg.split('|')[0]);
|
||||||
|
});
|
||||||
|
|
||||||
// -> configure package access level
|
// -> configure package access level
|
||||||
if (
|
if (
|
||||||
config.npmAccessLevel &&
|
config.npmAccessLevel
|
||||||
(config.npmAccessLevel === 'public' || config.npmAccessLevel === 'private')
|
|
||||||
) {
|
) {
|
||||||
npmAccessCliString = `--access=${config.npmAccessLevel}`;
|
npmAccessCliString = `--access=${config.npmAccessLevel}`;
|
||||||
|
if (config.npmAccessLevel === 'public') {
|
||||||
|
publishVerdaccioAsWell = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -> configure registry url
|
// -> configure registry url
|
||||||
if (config.npmRegistryUrl) {
|
if (config.npmRegistryUrl) {
|
||||||
npmRegistryCliString = `--registry=https://${config.npmRegistryUrl}`;
|
npmRegistryCliString = `--registry=https://${config.npmRegistryUrl}`;
|
||||||
@@ -86,6 +93,19 @@ const publish = async () => {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let publishCommand = `npm publish ${npmAccessCliString} ${npmRegistryCliString} `;
|
||||||
|
|
||||||
|
// publishEverywhere
|
||||||
|
if (publishVerdaccioAsWell) {
|
||||||
|
const verdaccioRegistry = availableRegistries.find(registryString => registryString.startsWith('verdaccio'));
|
||||||
|
if (verdaccioRegistry) {
|
||||||
|
logger.log('info', `package is public and verdaccio registry is specified. Also publishing to Verdaccio!`);
|
||||||
|
publishCommand = `${publishCommand} && npm publish ${npmAccessCliString} --registry=https://${verdaccioRegistry}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return publishCommand;
|
||||||
|
};
|
||||||
|
|
||||||
// -> preparing
|
// -> preparing
|
||||||
logger.log('info', `now preparing environment:`);
|
logger.log('info', `now preparing environment:`);
|
||||||
prepare();
|
prepare();
|
||||||
@@ -105,7 +125,7 @@ const publish = async () => {
|
|||||||
|
|
||||||
// -> publish it
|
// -> publish it
|
||||||
logger.log('info', `now invoking npm to publish the package!`);
|
logger.log('info', `now invoking npm to publish the package!`);
|
||||||
await bash(`npm publish ${npmAccessCliString} ${npmRegistryCliString}`);
|
await bash(await buildPublishCommand());
|
||||||
logger.log('success', `Package was successfully published!`);
|
logger.log('success', `Package was successfully published!`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
Reference in New Issue
Block a user