Skip to content

Commit

Permalink
updated central-common + skip failing registry in stack
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Mar 30, 2022
1 parent 9db5100 commit f0827da
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 43 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
],
"license": "MIT",
"dependencies": {
"@personalhealthtrain/central-common": "^1.3.15",
"@personalhealthtrain/central-common": "^1.3.24",
"@trapi/client": "^2.0.5",
"@typescript-error/core": "^1.1.3",
"@authelion/common": "^0.0.3",
"chalk": "^4.1.2",
"docker-scan": "^1.0.4",
Expand Down
58 changes: 31 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,38 +208,42 @@ for (let i = 0; i < sum; i++) {
password: registries[i].password,
};

for (let j = 0; j < images.length; j++) {
const repository = `${registries[i].host}/${images[j]}:latest`;
const image = docker.getImage(repository);

const stream = await image.push({
authconfig: authConfig,
});

spinner.start(`Push: ${repository}`);

pushPromises.push(new Promise((resolve, reject) => {
docker.modem.followProgress(
stream,
(err: Error, res: any[]) => {
if (err) {
return reject(err);
}
try {
for (let j = 0; j < images.length; j++) {
const repository = `${registries[i].host}/${images[j]}:latest`;
const image = docker.getImage(repository);

const stream = await image.push({
authconfig: authConfig,
});

spinner.start(`Push: ${repository}`);

pushPromises.push(new Promise((resolve, reject) => {
docker.modem.followProgress(
stream,
(err: Error, res: any[]) => {
if (err) {
return reject(err);
}

const raw = res.pop();
const raw = res.pop();

if (Object.prototype.toString.call(raw) === '[object Object]') {
if (typeof raw?.errorDetail?.message === 'string') {
return reject(new Error(raw.errorDetail.message));
if (Object.prototype.toString.call(raw) === '[object Object]') {
if (typeof raw?.errorDetail?.message === 'string') {
return reject(new Error(raw.errorDetail.message));
}
}
}

spinner.info(`Pushed: ${repository}`);
spinner.info(`Pushed: ${repository}`);

return resolve(res);
},
);
}));
return resolve(res);
},
);
}));
}
} catch (e) {
spinner.fail(`Push to registry ${registries[i].host} failed`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/ui.ts → src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { ScanResult } from 'docker-scan';
import {
MasterImageAPI,
MasterImageCommand,
parseHarborConnectionString,
} from '@personalhealthtrain/central-common';
import { TokenAPI } from '@authelion/common';
import { Ora } from 'ora';
import { requireFromEnv } from './env';
import { parseConnectionString } from './connection-string';

export async function syncScanResultToCentralAPI(context: {
scan: ScanResult,
Expand All @@ -23,7 +23,7 @@ export async function syncScanResultToCentralAPI(context: {
context.spinner.start('Try to push meta information to central-api');

try {
const connection = parseHarborConnectionString(requireFromEnv('CENTRAL_API_CONNECTION_STRING'));
const connection = parseConnectionString(requireFromEnv('CENTRAL_API_CONNECTION_STRING'));

setConfig({
driver: {
Expand Down
32 changes: 32 additions & 0 deletions src/utils/connection-string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import { BaseError } from '@typescript-error/core';

export function parseConnectionString(connectionString: string): {
host: string,
user: string,
password: string
} {
const parts: string[] = connectionString.split('@');
if (parts.length !== 2) {
throw new BaseError('Connection string must be in the following format: user:password@host');
}

const host: string = parts[1];

const authParts: string[] = parts[0].split(':');
if (authParts.length !== 2) {
throw new BaseError('Connection string must be in the following format: user:password@host');
}

return {
host,
user: authParts[0],
password: authParts[1],
};
}
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
* view the LICENSE file that was distributed with this source code.
*/

export * from './ui';
export * from './api';
export * from './connection-string';
export * from './env';

0 comments on commit f0827da

Please sign in to comment.