update to deno

This commit is contained in:
2025-12-13 13:27:51 +00:00
parent dba2e2ae68
commit 9ad5222b95
25 changed files with 196 additions and 225 deletions

View File

@@ -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);

View File

@@ -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!');
}

View File

@@ -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];