update to deno
This commit is contained in:
@@ -17,7 +17,7 @@ export class CloudlyConnector {
|
||||
optionsArg: plugins.tsclass.container.IContainer,
|
||||
testCloudlyUrlArg?: string
|
||||
) {
|
||||
const cloudlyUrl = testCloudlyUrlArg || this.szciRef.npmciConfig.getConfig().urlCloudly;
|
||||
const cloudlyUrl = testCloudlyUrlArg || this.szciRef.szciConfig.getConfig().urlCloudly;
|
||||
if (!cloudlyUrl) {
|
||||
logger.log(
|
||||
'warn',
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Szci } from './szci.classes.szci.ts';
|
||||
import { Dockerfile } from './manager.docker/mod.classes.dockerfile.ts';
|
||||
|
||||
export const szciInstance = new Npmci();
|
||||
export const szciInstance = new Szci();
|
||||
|
||||
export { Dockerfile, Npmci };
|
||||
export { Dockerfile, Szci };
|
||||
|
||||
export const runCli = async () => {
|
||||
await szciInstance.start();
|
||||
|
||||
@@ -23,12 +23,12 @@ export class SzciCloudronManager {
|
||||
await this.deploy();
|
||||
break;
|
||||
default:
|
||||
logger.log('error', `>>npmci cloudron ...<< action >>${action}<< not supported`);
|
||||
logger.log('error', `>>szci cloudron ...<< action >>${action}<< not supported`);
|
||||
}
|
||||
} else {
|
||||
logger.log(
|
||||
'info',
|
||||
`>>npmci cloudron ...<< cli arguments invalid... Please read the documentation.`
|
||||
`>>szci cloudron ...<< cli arguments invalid... Please read the documentation.`
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -44,14 +44,18 @@ export class SzciCloudronManager {
|
||||
logger.log('ok', 'cloudron cli installed');
|
||||
|
||||
// lets set the version in the CloudronManifest file
|
||||
await this.prepareCloudronManifest(this.szciRef.npmciConfig.getConfig().projectInfo.npm.version);
|
||||
await this.prepareCloudronManifest(this.szciRef.szciConfig.getConfig().projectInfo.npm.version);
|
||||
logger.log('ok', 'CloudronManifest prepared');
|
||||
|
||||
// lets figure out the docker image tag
|
||||
const dockerImageTag = await this.szciRef.npmciConfig.kvStorage.readKey('latestPushedDockerTag');
|
||||
const appName = this.szciRef.npmciConfig.getConfig().cloudronAppName;
|
||||
const dockerImageTag = await this.szciRef.szciConfig.kvStorage.readKey('latestPushedDockerTag');
|
||||
const appName = this.szciRef.szciConfig.getConfig().cloudronAppName;
|
||||
|
||||
const cloudronEnvVar = Deno.env.get("NPMCI_LOGIN_CLOUDRON");
|
||||
const cloudronEnvVar = Deno.env.get("SZCI_LOGIN_CLOUDRON");
|
||||
if (!cloudronEnvVar) {
|
||||
logger.log('error', 'SZCI_LOGIN_CLOUDRON environment variable is not set');
|
||||
Deno.exit(1);
|
||||
}
|
||||
const cloudronServer = cloudronEnvVar.split('|')[0];
|
||||
const cloudronToken = cloudronEnvVar.split('|')[1];
|
||||
await bash(`cloudron update --server ${cloudronServer} --token ${cloudronToken} --image ${dockerImageTag} --app ${appName}`);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { RegistryStorage } from './mod.classes.registrystorage.ts';
|
||||
|
||||
export class SzciDockerManager {
|
||||
public szciRef: Szci;
|
||||
public npmciRegistryStorage = new RegistryStorage();
|
||||
public szciRegistryStorage = new RegistryStorage();
|
||||
|
||||
constructor(szciArg: Szci) {
|
||||
this.szciRef = szciArg;
|
||||
@@ -42,12 +42,12 @@ export class SzciDockerManager {
|
||||
await this.pull(argvArg);
|
||||
break;
|
||||
default:
|
||||
logger.log('error', `>>npmci docker ...<< action >>${action}<< not supported`);
|
||||
logger.log('error', `>>szci docker ...<< action >>${action}<< not supported`);
|
||||
}
|
||||
} else {
|
||||
logger.log(
|
||||
'info',
|
||||
`>>npmci docker ...<< cli arguments invalid... Please read the documentation.`
|
||||
`>>szci docker ...<< cli arguments invalid... Please read the documentation.`
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -69,7 +69,7 @@ export class SzciDockerManager {
|
||||
*/
|
||||
public login = async () => {
|
||||
await this.prepare();
|
||||
await this.npmciRegistryStorage.loginAll();
|
||||
await this.szciRegistryStorage.loginAll();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -83,11 +83,11 @@ export class SzciDockerManager {
|
||||
logger.log('error', 'Running in Gitlab CI, but no registry token specified by gitlab!');
|
||||
Deno.exit(1);
|
||||
}
|
||||
this.npmciRegistryStorage.addRegistry(
|
||||
this.szciRegistryStorage.addRegistry(
|
||||
new DockerRegistry({
|
||||
registryUrl: 'registry.gitlab.com',
|
||||
username: 'gitlab-ci-token',
|
||||
password: Deno.env.get("CI_JOB_TOKEN"),
|
||||
password: Deno.env.get("CI_JOB_TOKEN")!,
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -95,9 +95,9 @@ export class SzciDockerManager {
|
||||
// handle registries
|
||||
await plugins.smartobject.forEachMinimatch(
|
||||
Deno.env.toObject(),
|
||||
'NPMCI_LOGIN_DOCKER*',
|
||||
'SZCI_LOGIN_DOCKER*',
|
||||
async (envString: string) => {
|
||||
this.npmciRegistryStorage.addRegistry(DockerRegistry.fromEnvString(envString));
|
||||
this.szciRegistryStorage.addRegistry(DockerRegistry.fromEnvString(envString));
|
||||
}
|
||||
);
|
||||
return;
|
||||
@@ -115,14 +115,14 @@ export class SzciDockerManager {
|
||||
if (argvArg._.length >= 3 && argvArg._[2] !== 'npmextra') {
|
||||
dockerRegistryUrls.push(argvArg._[2]);
|
||||
} else {
|
||||
if (this.szciRef.npmciConfig.getConfig().dockerRegistries.length === 0) {
|
||||
if (this.szciRef.szciConfig.getConfig().dockerRegistries.length === 0) {
|
||||
logger.log(
|
||||
'warn',
|
||||
`There are no docker registries listed in npmextra.json! This is strange!`
|
||||
);
|
||||
}
|
||||
dockerRegistryUrls = dockerRegistryUrls.concat(
|
||||
this.szciRef.npmciConfig.getConfig().dockerRegistries
|
||||
this.szciRef.szciConfig.getConfig().dockerRegistries
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ export class SzciDockerManager {
|
||||
const dockerfileArray = await Dockerfile.readDockerfiles(this)
|
||||
.then(Dockerfile.sortDockerfiles)
|
||||
.then(Dockerfile.mapDockerfiles);
|
||||
const dockerRegistryToPushTo = await this.npmciRegistryStorage.getRegistryByUrl(
|
||||
const dockerRegistryToPushTo = await this.szciRegistryStorage.getRegistryByUrl(
|
||||
dockerRegistryUrl
|
||||
);
|
||||
if (!dockerRegistryToPushTo) {
|
||||
@@ -163,7 +163,7 @@ export class SzciDockerManager {
|
||||
if (argvArg._.length >= 4) {
|
||||
suffix = argvArg._[3];
|
||||
}
|
||||
const localDockerRegistry = await this.npmciRegistryStorage.getRegistryByUrl(registryUrlArg);
|
||||
const localDockerRegistry = await this.szciRegistryStorage.getRegistryByUrl(registryUrlArg);
|
||||
const dockerfileArray = await Dockerfile.readDockerfiles(this)
|
||||
.then(Dockerfile.sortDockerfiles)
|
||||
.then(Dockerfile.mapDockerfiles);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { SzciDockerManager } from './index.ts';
|
||||
import { Szci } from '../szci.classes.szci.ts';
|
||||
|
||||
/**
|
||||
* class Dockerfile represents a Dockerfile on disk in npmci
|
||||
* class Dockerfile represents a Dockerfile on disk in szci
|
||||
*/
|
||||
export class Dockerfile {
|
||||
// STATIC
|
||||
@@ -20,7 +20,7 @@ export class Dockerfile {
|
||||
* @returns Promise<Dockerfile[]>
|
||||
*/
|
||||
public static async readDockerfiles(
|
||||
npmciDockerManagerRefArg: SzciDockerManager
|
||||
szciDockerManagerRefArg: SzciDockerManager
|
||||
): Promise<Dockerfile[]> {
|
||||
const fileTree = await plugins.smartfile.fs.listFileTree(paths.cwd, 'Dockerfile*');
|
||||
|
||||
@@ -29,7 +29,7 @@ export class Dockerfile {
|
||||
logger.log('info', `found ${fileTree.length} Dockerfiles:`);
|
||||
console.log(fileTree);
|
||||
for (const dockerfilePath of fileTree) {
|
||||
const myDockerfile = new Dockerfile(npmciDockerManagerRefArg, {
|
||||
const myDockerfile = new Dockerfile(szciDockerManagerRefArg, {
|
||||
filePath: dockerfilePath,
|
||||
read: true,
|
||||
});
|
||||
@@ -61,7 +61,7 @@ export class Dockerfile {
|
||||
|
||||
// Check if the baseImage is among the local Dockerfiles
|
||||
if (tagToDockerfile.has(baseImage)) {
|
||||
const baseDockerfile = tagToDockerfile.get(baseImage);
|
||||
const baseDockerfile = tagToDockerfile.get(baseImage)!;
|
||||
dependencies.push(baseDockerfile);
|
||||
dockerfile.localBaseImageDependent = true;
|
||||
dockerfile.localBaseDockerfile = baseDockerfile;
|
||||
@@ -96,7 +96,7 @@ export class Dockerfile {
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
logger.log('error', error.message);
|
||||
logger.log('error', (error as Error).message);
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ export class Dockerfile {
|
||||
}
|
||||
versionString = versionString.replace(
|
||||
'##version##',
|
||||
dockerfileInstanceArg.npmciDockerManagerRef.szciRef.npmciConfig.getConfig().projectInfo.npm
|
||||
dockerfileInstanceArg.szciDockerManagerRef.szciRef.szciConfig.getConfig().projectInfo.npm
|
||||
.version
|
||||
);
|
||||
return versionString;
|
||||
@@ -236,7 +236,7 @@ export class Dockerfile {
|
||||
* returns the docker tag
|
||||
*/
|
||||
public static getDockerTagString(
|
||||
npmciDockerManagerRef: SzciDockerManager,
|
||||
szciDockerManagerRef: SzciDockerManager,
|
||||
registryArg: string,
|
||||
repoArg: string,
|
||||
versionArg: string,
|
||||
@@ -244,7 +244,7 @@ export class Dockerfile {
|
||||
): string {
|
||||
// determine wether the repo should be mapped accordingly to the registry
|
||||
const mappedRepo =
|
||||
npmciDockerManagerRef.szciRef.npmciConfig.getConfig().dockerRegistryRepoMap[registryArg];
|
||||
szciDockerManagerRef.szciRef.szciConfig.getConfig().dockerRegistryRepoMap[registryArg];
|
||||
const repo = (() => {
|
||||
if (mappedRepo) {
|
||||
return mappedRepo;
|
||||
@@ -264,15 +264,15 @@ export class Dockerfile {
|
||||
}
|
||||
|
||||
public static async getDockerBuildArgs(
|
||||
npmciDockerManagerRef: SzciDockerManager
|
||||
szciDockerManagerRef: SzciDockerManager
|
||||
): Promise<string> {
|
||||
logger.log('info', 'checking for env vars to be supplied to the docker build');
|
||||
let buildArgsString: string = '';
|
||||
for (const dockerArgKey of Object.keys(
|
||||
npmciDockerManagerRef.szciRef.npmciConfig.getConfig().dockerBuildargEnvMap
|
||||
szciDockerManagerRef.szciRef.szciConfig.getConfig().dockerBuildargEnvMap
|
||||
)) {
|
||||
const dockerArgOuterEnvVar =
|
||||
npmciDockerManagerRef.szciRef.npmciConfig.getConfig().dockerBuildargEnvMap[dockerArgKey];
|
||||
szciDockerManagerRef.szciRef.szciConfig.getConfig().dockerBuildargEnvMap[dockerArgKey];
|
||||
logger.log(
|
||||
'note',
|
||||
`docker ARG "${dockerArgKey}" maps to outer env var "${dockerArgOuterEnvVar}"`
|
||||
@@ -284,31 +284,31 @@ export class Dockerfile {
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public npmciDockerManagerRef: SzciDockerManager;
|
||||
public szciDockerManagerRef: SzciDockerManager;
|
||||
|
||||
public filePath: string;
|
||||
public filePath!: string;
|
||||
public repo: string;
|
||||
public version: string;
|
||||
public cleanTag: string;
|
||||
public buildTag: string;
|
||||
public pushTag: string;
|
||||
public pushTag!: string;
|
||||
public containerName: string;
|
||||
public content: string;
|
||||
public content!: string;
|
||||
public baseImage: string;
|
||||
public localBaseImageDependent: boolean;
|
||||
public localBaseDockerfile: Dockerfile;
|
||||
public localBaseDockerfile!: Dockerfile;
|
||||
|
||||
constructor(
|
||||
dockerManagerRefArg: SzciDockerManager,
|
||||
options: { filePath?: string; fileContents?: string | Buffer; read?: boolean }
|
||||
options: { filePath?: string; fileContents?: string | Uint8Array; read?: boolean }
|
||||
) {
|
||||
this.npmciDockerManagerRef = dockerManagerRefArg;
|
||||
this.filePath = options.filePath;
|
||||
this.szciDockerManagerRef = dockerManagerRefArg;
|
||||
this.filePath = options.filePath!;
|
||||
this.repo =
|
||||
this.npmciDockerManagerRef.szciRef.npmciEnv.repo.user +
|
||||
this.szciDockerManagerRef.szciRef.szciEnv.repo.user +
|
||||
'/' +
|
||||
this.npmciDockerManagerRef.szciRef.npmciEnv.repo.repo;
|
||||
this.version = Dockerfile.dockerFileVersion(this, plugins.path.parse(options.filePath).base);
|
||||
this.szciDockerManagerRef.szciRef.szciEnv.repo.repo;
|
||||
this.version = Dockerfile.dockerFileVersion(this, plugins.path.parse(this.filePath).base);
|
||||
this.cleanTag = this.repo + ':' + this.version;
|
||||
this.buildTag = this.cleanTag;
|
||||
|
||||
@@ -325,9 +325,9 @@ export class Dockerfile {
|
||||
*/
|
||||
public async build() {
|
||||
logger.log('info', 'now building Dockerfile for ' + this.cleanTag);
|
||||
const buildArgsString = await Dockerfile.getDockerBuildArgs(this.npmciDockerManagerRef);
|
||||
const buildArgsString = await Dockerfile.getDockerBuildArgs(this.szciDockerManagerRef);
|
||||
const buildCommand = `docker build --label="version=${
|
||||
this.npmciDockerManagerRef.szciRef.npmciConfig.getConfig().projectInfo.npm.version
|
||||
this.szciDockerManagerRef.szciRef.szciConfig.getConfig().projectInfo.npm.version
|
||||
}" -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
|
||||
await bash(buildCommand);
|
||||
return;
|
||||
@@ -336,9 +336,9 @@ export class Dockerfile {
|
||||
/**
|
||||
* pushes the Dockerfile to a registry
|
||||
*/
|
||||
public async push(dockerRegistryArg: DockerRegistry, versionSuffix: string = null) {
|
||||
public async push(dockerRegistryArg: DockerRegistry, versionSuffix?: string) {
|
||||
this.pushTag = Dockerfile.getDockerTagString(
|
||||
this.npmciDockerManagerRef,
|
||||
this.szciDockerManagerRef,
|
||||
dockerRegistryArg.registryUrl,
|
||||
this.repo,
|
||||
this.version,
|
||||
@@ -350,13 +350,13 @@ export class Dockerfile {
|
||||
await bash(`docker inspect --format="{{index .RepoDigests 0}}" ${this.pushTag}`)
|
||||
).split('@')[1];
|
||||
console.log(`The image ${this.pushTag} has digest ${imageDigest}`);
|
||||
await this.npmciDockerManagerRef.szciRef.cloudlyConnector.announceDockerContainer({
|
||||
await this.szciDockerManagerRef.szciRef.cloudlyConnector.announceDockerContainer({
|
||||
registryUrl: this.pushTag,
|
||||
tag: this.buildTag,
|
||||
labels: [],
|
||||
version: this.npmciDockerManagerRef.szciRef.npmciConfig.getConfig().projectInfo.npm.version,
|
||||
version: this.szciDockerManagerRef.szciRef.szciConfig.getConfig().projectInfo.npm.version,
|
||||
});
|
||||
await this.npmciDockerManagerRef.szciRef.npmciConfig.kvStorage.writeKey(
|
||||
await this.szciDockerManagerRef.szciRef.szciConfig.kvStorage.writeKey(
|
||||
'latestPushedDockerTag',
|
||||
this.pushTag
|
||||
);
|
||||
@@ -365,9 +365,9 @@ export class Dockerfile {
|
||||
/**
|
||||
* pulls the Dockerfile from a registry
|
||||
*/
|
||||
public async pull(registryArg: DockerRegistry, versionSuffixArg: string = null) {
|
||||
public async pull(registryArg: DockerRegistry, versionSuffixArg?: string) {
|
||||
const pullTag = Dockerfile.getDockerTagString(
|
||||
this.npmciDockerManagerRef,
|
||||
this.szciDockerManagerRef,
|
||||
registryArg.registryUrl,
|
||||
this.repo,
|
||||
this.version,
|
||||
@@ -386,13 +386,13 @@ export class Dockerfile {
|
||||
if (testFileExists) {
|
||||
// run tests
|
||||
await bash(
|
||||
`docker run --name npmci_test_container --entrypoint="bash" ${this.buildTag} -c "mkdir /npmci_test"`
|
||||
`docker run --name szci_test_container --entrypoint="bash" ${this.buildTag} -c "mkdir /szci_test"`
|
||||
);
|
||||
await bash(`docker cp ${testFile} npmci_test_container:/npmci_test/test.sh`);
|
||||
await bash(`docker commit npmci_test_container npmci_test_image`);
|
||||
await bash(`docker run --entrypoint="bash" npmci_test_image -x /npmci_test/test.sh`);
|
||||
await bash(`docker rm npmci_test_container`);
|
||||
await bash(`docker rmi --force npmci_test_image`);
|
||||
await bash(`docker cp ${testFile} szci_test_container:/szci_test/test.sh`);
|
||||
await bash(`docker commit szci_test_container szci_test_image`);
|
||||
await bash(`docker run --entrypoint="bash" szci_test_image -x /szci_test/test.sh`);
|
||||
await bash(`docker rm szci_test_container`);
|
||||
await bash(`docker rmi --force szci_test_image`);
|
||||
} else {
|
||||
logger.log('warn', 'skipping tests for ' + this.cleanTag + ' because no testfile was found!');
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ export class DockerRegistry {
|
||||
if (dockerRegexResultArray.length !== 3) {
|
||||
logger.log('error', 'malformed docker env var...');
|
||||
Deno.exit(1);
|
||||
return;
|
||||
}
|
||||
const registryUrl = dockerRegexResultArray[0].replace('https://', '').replace('http://', '');
|
||||
const username = dockerRegexResultArray[1];
|
||||
|
||||
@@ -22,20 +22,20 @@ export class SzciGitManager {
|
||||
await this.mirror();
|
||||
break;
|
||||
default:
|
||||
logger.log('error', `npmci git -> action >>${action}<< not supported!`);
|
||||
logger.log('error', `szci git -> action >>${action}<< not supported!`);
|
||||
}
|
||||
} else {
|
||||
logger.log('info', `npmci git -> cli arguments invalid! Please read the documentation.`);
|
||||
logger.log('info', `szci git -> cli arguments invalid! Please read the documentation.`);
|
||||
}
|
||||
};
|
||||
|
||||
public mirror = async () => {
|
||||
const githubToken = Deno.env.get("NPMCI_GIT_GITHUBTOKEN");
|
||||
const githubUser = Deno.env.get("NPMCI_GIT_GITHUBGROUP") || this.szciRef.npmciEnv.repo.user;
|
||||
const githubRepo = Deno.env.get("NPMCI_GIT_GITHUB") || this.szciRef.npmciEnv.repo.repo;
|
||||
const githubToken = Deno.env.get("SZCI_GIT_GITHUBTOKEN");
|
||||
const githubUser = Deno.env.get("SZCI_GIT_GITHUBGROUP") || this.szciRef.szciEnv.repo.user;
|
||||
const githubRepo = Deno.env.get("SZCI_GIT_GITHUB") || this.szciRef.szciEnv.repo.repo;
|
||||
if (
|
||||
this.szciRef.npmciConfig.getConfig().projectInfo.npm.packageJson.private === true ||
|
||||
this.szciRef.npmciConfig.getConfig().npmAccessLevel === 'private'
|
||||
this.szciRef.szciConfig.getConfig().projectInfo.npm.packageJson.private === true ||
|
||||
this.szciRef.szciConfig.getConfig().npmAccessLevel === 'private'
|
||||
) {
|
||||
logger.log(
|
||||
'warn',
|
||||
@@ -64,7 +64,7 @@ export class SzciGitManager {
|
||||
// remove old mirrors
|
||||
await bashNoError('git remote rm mirror');
|
||||
} else {
|
||||
logger.log('error', `cannot find NPMCI_GIT_GITHUBTOKEN env var!`);
|
||||
logger.log('error', `cannot find SZCI_GIT_GITHUBTOKEN env var!`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,13 +24,13 @@ export class SzciNodeJsManager {
|
||||
await this.install(argvArg._[2]);
|
||||
break;
|
||||
default:
|
||||
logger.log('error', `>>npmci node ...<< action >>${action}<< not supported`);
|
||||
logger.log('error', `>>szci node ...<< action >>${action}<< not supported`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
} else {
|
||||
logger.log(
|
||||
'error',
|
||||
`>>npmci node ...<< cli arguments invalid... Please read the documentation.`
|
||||
`>>szci node ...<< cli arguments invalid... Please read the documentation.`
|
||||
);
|
||||
Deno.exit(1);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export class SzciNodeJsManager {
|
||||
await bash('npm -v');
|
||||
|
||||
// lets look for further config
|
||||
const config = await this.szciRef.npmciConfig.getConfig();
|
||||
const config = await this.szciRef.szciConfig.getConfig();
|
||||
logger.log('info', 'Now checking for needed global npm tools...');
|
||||
for (const npmTool of config.npmGlobalTools) {
|
||||
logger.log('info', `Checking for global "${npmTool}"`);
|
||||
|
||||
@@ -36,13 +36,13 @@ export class SzciNpmManager {
|
||||
await this.publish();
|
||||
break;
|
||||
default:
|
||||
logger.log('error', `>>npmci npm ...<< action >>${action}<< not supported`);
|
||||
logger.log('error', `>>szci npm ...<< action >>${action}<< not supported`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
} else {
|
||||
logger.log(
|
||||
'info',
|
||||
`>>npmci npm ...<< cli arguments invalid... Please read the documentation.`
|
||||
`>>szci npm ...<< cli arguments invalid... Please read the documentation.`
|
||||
);
|
||||
Deno.exit(1);
|
||||
}
|
||||
@@ -53,11 +53,11 @@ export class SzciNpmManager {
|
||||
*/
|
||||
public async prepare() {
|
||||
logger.log('info', 'running >>npm prepare<<');
|
||||
const config = this.szciRef.npmciConfig.getConfig();
|
||||
const config = this.szciRef.szciConfig.getConfig();
|
||||
let npmrcFileString: string = '';
|
||||
await plugins.smartobject.forEachMinimatch(
|
||||
Deno.env.toObject(),
|
||||
'NPMCI_TOKEN_NPM*',
|
||||
'SZCI_TOKEN_NPM*',
|
||||
(npmEnvArg: string) => {
|
||||
if (!npmEnvArg) {
|
||||
logger.log('note','found empty token...');
|
||||
@@ -103,11 +103,11 @@ export class SzciNpmManager {
|
||||
let npmAccessCliString = ``;
|
||||
let npmRegistryCliString = ``;
|
||||
let publishVerdaccioAsWell = false;
|
||||
const config = this.szciRef.npmciConfig.getConfig();
|
||||
const config = this.szciRef.szciConfig.getConfig();
|
||||
const availableRegistries: string[] = [];
|
||||
await plugins.smartobject.forEachMinimatch(
|
||||
Deno.env.toObject(),
|
||||
'NPMCI_TOKEN_NPM*',
|
||||
'SZCI_TOKEN_NPM*',
|
||||
(npmEnvArg: string) => {
|
||||
availableRegistries.push(npmEnvArg.split('|')[0]);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ export class SzciNpmManager {
|
||||
logger.log('success', `Nice!!! The build for the publication was successfull!`);
|
||||
logger.log('info', `Lets clean up so we don't publish any packages that don't belong to us:`);
|
||||
// -> clean up before we publish stuff
|
||||
await bashNoError(`rm -r ./.npmci_cache`);
|
||||
await bashNoError(`rm -r ./.szci_cache`);
|
||||
await bash(`rm -r ./node_modules`);
|
||||
|
||||
logger.log('success', `Cleaned up!:`);
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as plugins from './mod.plugins.ts';
|
||||
import * as paths from '../szci.paths.ts';
|
||||
|
||||
/**
|
||||
* cleans npmci config files
|
||||
* cleans szci config files
|
||||
*/
|
||||
export let clean = async (): Promise<void> => {
|
||||
plugins.smartfile.fs.removeSync(paths.SzciPackageConfig);
|
||||
|
||||
@@ -5,11 +5,16 @@ import { Szci } from '../szci.classes.szci.ts';
|
||||
|
||||
export const handleCli = async (szciRefArg: Szci, argvArg: any) => {
|
||||
logger.log('info', 'checking execution context');
|
||||
const presentRunnerTags = Deno.env.get("CI_RUNNER_TAGS").split(',').map((stringArg) =>
|
||||
const ciRunnerTags = Deno.env.get("CI_RUNNER_TAGS");
|
||||
if (!ciRunnerTags) {
|
||||
logger.log('error', 'CI_RUNNER_TAGS environment variable is not set');
|
||||
Deno.exit(1);
|
||||
}
|
||||
const presentRunnerTags = ciRunnerTags.split(',').map((stringArg) =>
|
||||
stringArg.trim()
|
||||
);
|
||||
let allDesiredGitlabRunnerTagsPresent = true;
|
||||
for (const desiredRunnerTag of szciRefArg.npmciConfig.getConfig().gitlabRunnerTags) {
|
||||
for (const desiredRunnerTag of szciRefArg.szciConfig.getConfig().gitlabRunnerTags) {
|
||||
if (!presentRunnerTags.includes(desiredRunnerTag)) {
|
||||
allDesiredGitlabRunnerTagsPresent = false;
|
||||
logger.log(
|
||||
|
||||
@@ -14,7 +14,7 @@ export let handleCli = async (argvArg: any) => {
|
||||
Deno.exit(1);
|
||||
}
|
||||
} else {
|
||||
logger.log('error', `>>npmci ssh ...<< please specify an action!`);
|
||||
logger.log('error', `>>szci ssh ...<< please specify an action!`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
};
|
||||
@@ -27,12 +27,12 @@ const notUndefined = (stringArg: string) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
|
||||
* checks for ENV vars in form of SZCI_SSHKEY_* and deploys any found ones
|
||||
*/
|
||||
export let prepare = async () => {
|
||||
sshInstance = new plugins.smartssh.SshInstance(); // init ssh instance
|
||||
plugins.smartobject.forEachMinimatch(Deno.env.toObject(), 'NPMCI_SSHKEY_*', evaluateSshEnv);
|
||||
if (!Deno.env.get("NPMTS_TEST")) {
|
||||
plugins.smartobject.forEachMinimatch(Deno.env.toObject(), 'SZCI_SSHKEY_*', evaluateSshEnv);
|
||||
if (!Deno.env.get("SZCI_TEST")) {
|
||||
sshInstance.writeToDisk();
|
||||
} else {
|
||||
logger.log('info', 'In test mode, so not storing SSH keys to disk!');
|
||||
|
||||
@@ -7,16 +7,20 @@ const triggerValueRegex =
|
||||
|
||||
export let trigger = async () => {
|
||||
logger.log('info', 'now running triggers');
|
||||
await plugins.smartobject.forEachMinimatch(Deno.env.toObject(), 'NPMCI_TRIGGER_*', evaluateTrigger);
|
||||
await plugins.smartobject.forEachMinimatch(Deno.env.toObject(), 'SZCI_TRIGGER_*', evaluateTrigger);
|
||||
};
|
||||
|
||||
const evaluateTrigger = async (triggerEnvVarArg) => {
|
||||
const evaluateTrigger = async (triggerEnvVarArg: string) => {
|
||||
const triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg);
|
||||
if (!triggerRegexResultArray) {
|
||||
logger.log('error', 'malformed trigger env var...');
|
||||
return;
|
||||
}
|
||||
const regexDomain = triggerRegexResultArray[1];
|
||||
const regexProjectId = triggerRegexResultArray[2];
|
||||
const regexProjectTriggerToken = triggerRegexResultArray[3];
|
||||
const regexRefName = triggerRegexResultArray[4];
|
||||
let regexTriggerName;
|
||||
let regexTriggerName: string;
|
||||
if (triggerRegexResultArray.length === 6) {
|
||||
regexTriggerName = triggerRegexResultArray[5];
|
||||
} else {
|
||||
|
||||
@@ -7,9 +7,9 @@ import * as paths from './szci.paths.ts';
|
||||
*/
|
||||
export let nvmAvailable = plugins.smartpromise.defer<boolean>();
|
||||
/**
|
||||
* the smartshell instance for npmci
|
||||
* the smartshell instance for szci
|
||||
*/
|
||||
const npmciSmartshell = new plugins.smartshell.Smartshell({
|
||||
const szciSmartshell = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
sourceFilePaths: [],
|
||||
});
|
||||
@@ -19,16 +19,16 @@ const npmciSmartshell = new plugins.smartshell.Smartshell({
|
||||
*/
|
||||
const checkToolsAvailable = async () => {
|
||||
// check for nvm
|
||||
if (!Deno.env.get('NPMTS_TEST')) {
|
||||
if (!Deno.env.get('SZCI_TEST')) {
|
||||
if (
|
||||
(await npmciSmartshell.execSilent(`bash -c "source /usr/local/nvm/nvm.sh"`)).exitCode === 0
|
||||
(await szciSmartshell.execSilent(`bash -c "source /usr/local/nvm/nvm.sh"`)).exitCode === 0
|
||||
) {
|
||||
npmciSmartshell.shellEnv.addSourceFiles([`/usr/local/nvm/nvm.sh`]);
|
||||
szciSmartshell.shellEnv.addSourceFiles([`/usr/local/nvm/nvm.sh`]);
|
||||
nvmAvailable.resolve(true);
|
||||
} else if (
|
||||
(await npmciSmartshell.execSilent(`bash -c "source ~/.nvm/nvm.sh"`)).exitCode === 0
|
||||
(await szciSmartshell.execSilent(`bash -c "source ~/.nvm/nvm.sh"`)).exitCode === 0
|
||||
) {
|
||||
npmciSmartshell.shellEnv.addSourceFiles([`~/.nvm/nvm.sh`]);
|
||||
szciSmartshell.shellEnv.addSourceFiles([`~/.nvm/nvm.sh`]);
|
||||
nvmAvailable.resolve(true);
|
||||
} else {
|
||||
nvmAvailable.resolve(false);
|
||||
@@ -46,7 +46,7 @@ checkToolsAvailable();
|
||||
*/
|
||||
export let bash = async (commandArg: string, retryArg: number = 2): Promise<string> => {
|
||||
await nvmAvailable.promise; // make sure nvm check has run
|
||||
let execResult: plugins.smartshell.IExecResult;
|
||||
let execResult!: plugins.smartshell.IExecResult;
|
||||
|
||||
// determine if we fail
|
||||
let failOnError: boolean = true;
|
||||
@@ -55,13 +55,13 @@ export let bash = async (commandArg: string, retryArg: number = 2): Promise<stri
|
||||
retryArg = 0;
|
||||
}
|
||||
|
||||
if (!Deno.env.get('NPMTS_TEST')) {
|
||||
// NPMTS_TEST is used during testing
|
||||
if (!Deno.env.get('SZCI_TEST')) {
|
||||
// SZCI_TEST is used during testing
|
||||
for (let i = 0; i <= retryArg; i++) {
|
||||
if (Deno.env.get('DEBUG_NPMCI') === 'true') {
|
||||
if (Deno.env.get('DEBUG_SZCI') === 'true') {
|
||||
console.log(commandArg);
|
||||
}
|
||||
execResult = await npmciSmartshell.exec(commandArg);
|
||||
execResult = await szciSmartshell.exec(commandArg);
|
||||
|
||||
// determine how bash reacts to error and success
|
||||
if (execResult.exitCode !== 0 && i === retryArg) {
|
||||
|
||||
@@ -19,19 +19,19 @@ import { SzciNpmManager } from './manager.npm/index.ts';
|
||||
|
||||
export class Szci {
|
||||
public analytics: plugins.smartanalytics.Analytics;
|
||||
public cloudlyConnector: CloudlyConnector;
|
||||
public cloudlyConnector!: CloudlyConnector;
|
||||
|
||||
public npmciEnv: SzciEnv;
|
||||
public npmciInfo: SzciInfo;
|
||||
public npmciConfig: SzciConfig;
|
||||
public npmciCli: SzciCli;
|
||||
public szciEnv!: SzciEnv;
|
||||
public szciInfo!: SzciInfo;
|
||||
public szciConfig!: SzciConfig;
|
||||
public szciCli!: SzciCli;
|
||||
|
||||
// managers
|
||||
public cloudronManager: SzciCloudronManager;
|
||||
public dockerManager: SzciDockerManager;
|
||||
public gitManager: SzciGitManager;
|
||||
public nodejsManager: SzciNodeJsManager;
|
||||
public npmManager: SzciNpmManager;
|
||||
public cloudronManager!: SzciCloudronManager;
|
||||
public dockerManager!: SzciDockerManager;
|
||||
public gitManager!: SzciGitManager;
|
||||
public nodejsManager!: SzciNodeJsManager;
|
||||
public npmManager!: SzciNpmManager;
|
||||
|
||||
constructor() {
|
||||
this.analytics = new plugins.smartanalytics.Analytics({
|
||||
@@ -43,12 +43,12 @@ export class Szci {
|
||||
|
||||
public async start() {
|
||||
this.cloudlyConnector = new CloudlyConnector(this);
|
||||
this.npmciEnv = new SzciEnv(this);
|
||||
this.npmciInfo = new SzciInfo(this);
|
||||
await this.npmciInfo.printToConsole();
|
||||
this.npmciCli = new SzciCli(this);
|
||||
this.npmciConfig = new SzciConfig(this);
|
||||
await this.npmciConfig.init();
|
||||
this.szciEnv = new SzciEnv(this);
|
||||
this.szciInfo = new SzciInfo(this);
|
||||
await this.szciInfo.printToConsole();
|
||||
this.szciCli = new SzciCli(this);
|
||||
this.szciConfig = new SzciConfig(this);
|
||||
await this.szciConfig.init();
|
||||
|
||||
// managers
|
||||
this.cloudronManager = new SzciCloudronManager(this);
|
||||
@@ -56,6 +56,6 @@ export class Szci {
|
||||
this.gitManager = new SzciGitManager(this);
|
||||
this.nodejsManager = new SzciNodeJsManager(this);
|
||||
this.npmManager = new SzciNpmManager(this);
|
||||
this.npmciCli.startParse();
|
||||
this.szciCli.startParse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ export class SzciCli {
|
||||
constructor(szciArg: Szci) {
|
||||
this.szciRef = szciArg;
|
||||
this.smartcli = new plugins.smartcli.Smartcli();
|
||||
this.smartcli.addVersion(this.szciRef.npmciInfo.version);
|
||||
this.smartcli.addVersion(this.szciRef.szciInfo.version);
|
||||
|
||||
// clean
|
||||
this.smartcli.addCommand('clean').subscribe(
|
||||
async (argv) => {
|
||||
const modClean = await import('./mod_clean/index.js');
|
||||
const modClean = await import('./mod_clean/index.ts');
|
||||
await modClean.clean();
|
||||
},
|
||||
(err) => {
|
||||
@@ -38,7 +38,7 @@ export class SzciCli {
|
||||
// command
|
||||
this.smartcli.addCommand('command').subscribe(
|
||||
async (argv) => {
|
||||
const modCommand = await import('./mod_command/index.js');
|
||||
const modCommand = await import('./mod_command/index.ts');
|
||||
await modCommand.command();
|
||||
},
|
||||
(err) => {
|
||||
@@ -91,20 +91,20 @@ export class SzciCli {
|
||||
);
|
||||
|
||||
this.smartcli.addCommand('precheck').subscribe(async (argvArg) => {
|
||||
const modPrecheck = await import('./mod_precheck/index.js');
|
||||
const modPrecheck = await import('./mod_precheck/index.ts');
|
||||
await modPrecheck.handleCli(this.szciRef, argvArg);
|
||||
});
|
||||
|
||||
// trigger
|
||||
this.smartcli.addCommand('ssh').subscribe(async (argvArg) => {
|
||||
const modSsh = await import('./mod_ssh/index.js');
|
||||
const modSsh = await import('./mod_ssh/index.ts');
|
||||
await modSsh.handleCli(argvArg);
|
||||
});
|
||||
|
||||
// trigger
|
||||
this.smartcli.addCommand('trigger').subscribe(
|
||||
async (argv) => {
|
||||
const modTrigger = await import('./mod_trigger/index.js');
|
||||
const modTrigger = await import('./mod_trigger/index.ts');
|
||||
await modTrigger.trigger();
|
||||
},
|
||||
(err) => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { logger } from './szci.logging.ts';
|
||||
import { Szci } from './szci.classes.szci.ts';
|
||||
|
||||
/**
|
||||
* the main config interface for npmci
|
||||
* the main config interface for szci
|
||||
*/
|
||||
export interface ISzciOptions {
|
||||
projectInfo: plugins.projectinfo.ProjectInfo;
|
||||
@@ -24,35 +24,35 @@ export interface ISzciOptions {
|
||||
gitlabRunnerTags: string[];
|
||||
|
||||
// urls
|
||||
urlCloudly: string;
|
||||
urlCloudly?: string;
|
||||
|
||||
// cloudron
|
||||
cloudronAppName?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* a config class for Npmci
|
||||
* a config class for Szci
|
||||
*/
|
||||
export class SzciConfig {
|
||||
public szciRef: Szci;
|
||||
|
||||
public npmciNpmextra: plugins.npmextra.Npmextra;
|
||||
public kvStorage: plugins.npmextra.KeyValueStore;
|
||||
public npmciQenv: plugins.qenv.Qenv;
|
||||
public szciNpmextra!: plugins.npmextra.Npmextra;
|
||||
public kvStorage!: plugins.npmextra.KeyValueStore;
|
||||
public szciQenv!: plugins.qenv.Qenv;
|
||||
|
||||
private configObject: ISzciOptions;
|
||||
private configObject!: ISzciOptions;
|
||||
|
||||
constructor(szciRefArg: Szci) {
|
||||
this.szciRef = szciRefArg;
|
||||
}
|
||||
|
||||
public async init() {
|
||||
this.npmciNpmextra = new plugins.npmextra.Npmextra(paths.cwd);
|
||||
this.szciNpmextra = new plugins.npmextra.Npmextra(paths.cwd);
|
||||
this.kvStorage = new plugins.npmextra.KeyValueStore({
|
||||
typeArg: 'userHomeDir',
|
||||
identityArg: `.npmci_${this.szciRef.npmciEnv.repo.user}_${this.szciRef.npmciEnv.repo.repo}`,
|
||||
identityArg: `.szci_${this.szciRef.szciEnv.repo.user}_${this.szciRef.szciEnv.repo.repo}`,
|
||||
});
|
||||
this.npmciQenv = new plugins.qenv.Qenv(
|
||||
this.szciQenv = new plugins.qenv.Qenv(
|
||||
paths.SzciProjectDir,
|
||||
paths.SzciProjectNogitDir,
|
||||
false
|
||||
@@ -67,9 +67,9 @@ export class SzciConfig {
|
||||
npmRegistryUrl: 'registry.npmjs.org',
|
||||
gitlabRunnerTags: [],
|
||||
dockerBuildargEnvMap: {},
|
||||
urlCloudly: await this.npmciQenv.getEnvVarOnDemand('NPMCI_URL_CLOUDLY'),
|
||||
urlCloudly: await this.szciQenv.getEnvVarOnDemand('SZCI_URL_CLOUDLY'),
|
||||
};
|
||||
this.configObject = this.npmciNpmextra.dataFor<ISzciOptions>('szci', this.configObject);
|
||||
this.configObject = this.szciNpmextra.dataFor<ISzciOptions>('@ship.zone/szci', this.configObject);
|
||||
}
|
||||
|
||||
public getConfig(): ISzciOptions {
|
||||
|
||||
@@ -9,15 +9,17 @@ export class SzciEnv {
|
||||
|
||||
constructor(szciRefArg: Szci) {
|
||||
this.szciRef = szciRefArg;
|
||||
if (!this.repoString && Deno.env.get("GITLAB_CI")) {
|
||||
this.repoString = Deno.env.get("CI_REPOSITORY_URL");
|
||||
|
||||
// Determine repo string from environment
|
||||
let repoUrl: string | undefined;
|
||||
if (Deno.env.get("GITLAB_CI")) {
|
||||
repoUrl = Deno.env.get("CI_REPOSITORY_URL");
|
||||
}
|
||||
if (!this.repoString && Deno.env.get("NPMCI_COMPUTED_REPOURL")) {
|
||||
this.repoString = Deno.env.get("NPMCI_COMPUTED_REPOURL");
|
||||
}
|
||||
if (!this.repoString) {
|
||||
this.repoString = 'https://undefined:undefined@github.com/undefined/undefined.git';
|
||||
if (!repoUrl && Deno.env.get("SZCI_COMPUTED_REPOURL")) {
|
||||
repoUrl = Deno.env.get("SZCI_COMPUTED_REPOURL");
|
||||
}
|
||||
|
||||
this.repoString = repoUrl || 'https://undefined:undefined@github.com/undefined/undefined.git';
|
||||
this.repo = new plugins.smartstring.GitRepo(this.repoString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export const logger = new plugins.smartlog.Smartlog({
|
||||
companyunit: 'Some Unit',
|
||||
containerName: 'Some ContainerName',
|
||||
environment: 'test',
|
||||
runtime: 'node',
|
||||
runtime: 'deno',
|
||||
zone: 'Some Zone',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -13,4 +13,4 @@ export const SzciPackageConfig = plugins.path.join(SzciPackageRoot, './config.js
|
||||
export const SzciProjectDir = cwd;
|
||||
export const SzciProjectNogitDir = plugins.path.join(SzciProjectDir, './.nogit');
|
||||
export const SzciTestDir = plugins.path.join(cwd, './test');
|
||||
export const SzciCacheDir = plugins.path.join(cwd, './.npmci_cache');
|
||||
export const SzciCacheDir = plugins.path.join(cwd, './.szci_cache');
|
||||
|
||||
Reference in New Issue
Block a user