fix(imagemanager): prepare proper storage and retrieval of container images
This commit is contained in:
@ -2,6 +2,8 @@ import * as plugins from './plugins.js';
|
||||
|
||||
export type TClientType = 'coreflow' | 'cli' | 'serverconfig';
|
||||
|
||||
import { Image } from './classes.image.js';
|
||||
|
||||
export class CloudlyClient {
|
||||
private cloudlyUrl: string;
|
||||
private registerAs: string;
|
||||
@ -55,15 +57,18 @@ export class CloudlyClient {
|
||||
this.typedrouter,
|
||||
this.cloudlyUrl
|
||||
);
|
||||
console.log(`CloudlyCluent connected to cloudly at ${this.cloudlyUrl}. Remember to get an identity.`)
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.typedsocketClient.stop();
|
||||
}
|
||||
|
||||
public identity: plugins.servezoneInterfaces.data.IClusterIdentifier;
|
||||
public async getIdentityByJumpCode(
|
||||
jumpCodeArg: string,
|
||||
tagConnection = false
|
||||
tagConnection = false,
|
||||
statefullIdentity = true
|
||||
): Promise<plugins.servezoneInterfaces.data.IClusterIdentifier> {
|
||||
const identityRequest =
|
||||
this.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.identity.IRequest_Any_Cloudly_CoreflowManager_GetIdentityByJumpCode>(
|
||||
@ -80,6 +85,10 @@ export class CloudlyClient {
|
||||
this.typedsocketClient.addTag('identity', identity);
|
||||
}
|
||||
|
||||
if (statefullIdentity) {
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
return identity;
|
||||
}
|
||||
|
||||
@ -127,4 +136,9 @@ export class CloudlyClient {
|
||||
});
|
||||
return typedResponse.certificate;
|
||||
}
|
||||
|
||||
// Images
|
||||
public async getImages() {
|
||||
return Image.getImages(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,84 @@
|
||||
import type { CloudlyClient } from './classes.cloudlyclient.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export class Image {
|
||||
public getImages() {
|
||||
|
||||
export class Image implements plugins.servezoneInterfaces.data.IImage {
|
||||
public static async getImages(cloudlyClientRef: CloudlyClient) {
|
||||
const getAllImagesTR = cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_GetAllImages>(
|
||||
'getAllImages'
|
||||
);
|
||||
const response = await getAllImagesTR.fire({
|
||||
jwt: cloudlyClientRef.identity.jwt,
|
||||
});
|
||||
const resultImages: Image[] = [];
|
||||
for (const image of response.images) {
|
||||
const newImage = new Image(cloudlyClientRef);
|
||||
Object.assign(newImage, image);
|
||||
resultImages.push(newImage);
|
||||
}
|
||||
return resultImages;
|
||||
}
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
cloudlyClientRef: CloudlyClient;
|
||||
|
||||
id: plugins.servezoneInterfaces.data.IImage['id'];
|
||||
data: plugins.servezoneInterfaces.data.IImage['data'];
|
||||
|
||||
constructor(cloudlyClientRef: CloudlyClient) {
|
||||
this.cloudlyClientRef = cloudlyClientRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the image data
|
||||
*/
|
||||
public async update() {
|
||||
const getVersionsTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_GetImageMetadata>(
|
||||
'getImageMetadata'
|
||||
);
|
||||
const response = await getVersionsTR.fire({
|
||||
jwt: this.cloudlyClientRef.identity.jwt,
|
||||
imageId: this.id,
|
||||
});
|
||||
Object.assign(this, response.image);
|
||||
}
|
||||
|
||||
/**
|
||||
* pushes a new version of the image
|
||||
* @param imageVersion
|
||||
* @param imageReadableArg
|
||||
*/
|
||||
public async pushImageVersion(imageVersion: string, imageReadableArg: ReadableStream<Uint8Array>): Promise<void> {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const pullImageTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_PushImageVersion>(
|
||||
'pushImageVersion'
|
||||
);
|
||||
const virtualStream = new plugins.typedrequest.VirtualStream();
|
||||
const response = await pullImageTR.fire({
|
||||
jwt: this.cloudlyClientRef.identity.jwt,
|
||||
imageId: this.id,
|
||||
versionString: '',
|
||||
imageStream: virtualStream,
|
||||
});
|
||||
await virtualStream.readFromWebstream(imageReadableArg);
|
||||
await done.promise;
|
||||
await this.update();
|
||||
};
|
||||
|
||||
/**
|
||||
* pulls a version of the image
|
||||
*/
|
||||
public async pullImageVersion(versionStringArg: string): Promise<ReadableStream<Uint8Array>> {
|
||||
const pullImageTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_PullImageVersion>(
|
||||
'pullImageVersion'
|
||||
);
|
||||
const response = await pullImageTR.fire({
|
||||
jwt: this.cloudlyClientRef.identity.jwt,
|
||||
imageId: this.id,
|
||||
versionString: versionStringArg,
|
||||
});
|
||||
const imageStream = response.imageStream;
|
||||
const webduplexStream = new plugins.webstream.WebDuplexStream({});
|
||||
imageStream.writeToWebstream(webduplexStream.writable);
|
||||
return webduplexStream.readable;
|
||||
};
|
||||
}
|
||||
|
@ -6,10 +6,14 @@ export {
|
||||
}
|
||||
|
||||
// @push.rocks scope
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartrx from '@push.rocks/smartrx';
|
||||
import * as webstream from '@push.rocks/smartstream/web';
|
||||
|
||||
export {
|
||||
smartpromise,
|
||||
smartrx,
|
||||
webstream,
|
||||
}
|
||||
|
||||
// @api.global scope
|
||||
|
Reference in New Issue
Block a user