feat(images): can now import and export images, start work on local 100% JS oci imageregistry

This commit is contained in:
2024-06-05 14:10:44 +02:00
parent a5f4d93f50
commit e06ef454a6
17 changed files with 3653 additions and 2477 deletions

40
ts/classes.imagestore.ts Normal file
View File

@@ -0,0 +1,40 @@
import * as plugins from './plugins.js';
import * as paths from './paths.js';
export interface IDockerImageStoreConstructorOptions {
dirPath: string;
}
export class DockerImageStore {
public options: IDockerImageStoreConstructorOptions;
constructor(optionsArg: IDockerImageStoreConstructorOptions) {
this.options = optionsArg;
}
// Method to store tar stream
public async storeImage(imageName: string, tarStream: NodeJS.ReadableStream): Promise<void> {
const imagePath = plugins.path.join(this.options.dirPath, `${imageName}.tar`);
// Create a write stream to store the tar file
const writeStream = plugins.smartfile.fsStream.createWriteStream(imagePath);
return new Promise((resolve, reject) => {
tarStream.pipe(writeStream);
writeStream.on('finish', resolve);
writeStream.on('error', reject);
});
}
// Method to retrieve tar stream
public async getImage(imageName: string): Promise<plugins.smartstream.stream.Readable> {
const imagePath = plugins.path.join(this.options.dirPath, `${imageName}.tar`);
if (!(await plugins.smartfile.fs.fileExists(imagePath))) {
throw new Error(`Image ${imageName} does not exist.`);
}
return plugins.smartfile.fsStream.createReadStream(imagePath);
}
}