update to deno
This commit is contained in:
@@ -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!');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user