fix(core): update

This commit is contained in:
2024-06-10 00:15:01 +02:00
parent 054585c7f5
commit 2e7e8ae5cf
8 changed files with 104 additions and 31 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiclient.xyz/docker',
version: '1.2.0',
version: '1.2.1',
description: 'Provides easy communication with Docker remote API from Node.js, with TypeScript support.'
}

View File

@ -28,6 +28,7 @@ export class DockerHost {
public socketPath: string;
private registryToken: string = '';
public imageStore: DockerImageStore;
public smartBucket: plugins.smartbucket.SmartBucket;
/**
* the constructor to instantiate a new docker sock instance
@ -274,4 +275,21 @@ export class DockerHost {
console.log(response.body);
return response;
}
/**
* add s3 storage
* @param optionsArg
*/
public async addS3Storage(optionsArg: plugins.tsclass.storage.IS3Descriptor) {
this.smartBucket = new plugins.smartbucket.SmartBucket(optionsArg);
if (!optionsArg.bucketName) {
throw new Error('bucketName is required');
}
const bucket = await this.smartBucket.getBucketByName(optionsArg.bucketName);
let wantedDirectory = await bucket.getBaseDirectory();
if (optionsArg.directoryPath) {
wantedDirectory = await wantedDirectory.getSubDirectoryByName(optionsArg.directoryPath);
}
this.imageStore.options.bucketDir = wantedDirectory;
}
}

View File

@ -166,7 +166,7 @@ export class DockerImage {
* exports an image to a tar ball
*/
public async exportToTarStream(): Promise<plugins.smartstream.stream.Readable> {
console.log(`Exporting image ${this.RepoTags[0]} to tar stream.`);
logger.log('info', `Exporting image ${this.RepoTags[0]} to tar stream.`);
const response = await this.dockerHost.requestStreaming('GET', `/images/${encodeURIComponent(this.RepoTags[0])}/get`);
let counter = 0;
const webduplexStream = new plugins.smartstream.SmartDuplex({

View File

@ -87,6 +87,12 @@ export class DockerImageStore {
});
logger.log('ok', `Repackaged image ${imageName} for s3.`);
await plugins.smartfile.fs.remove(extractionDir);
const finalTarReadStream = plugins.smartfile.fsStream.createReadStream(finalTarPath);
await this.options.bucketDir.fastPutStream({
stream: finalTarReadStream,
path: `${imageName}.tar`,
});
await plugins.smartfile.fs.remove(finalTarPath);
}
public async start() {