fix(core): Fix image retrieval and service deployment process for workload services

This commit is contained in:
Philipp Kunz 2024-12-29 14:11:01 +01:00
parent 21903acbbe
commit 6d818b4b36
5 changed files with 107 additions and 815 deletions

View File

@ -1,5 +1,13 @@
# Changelog # Changelog
## 2024-12-29 - 1.0.135 - fix(core)
Fix image retrieval and service deployment process for workload services
- Updated the handling of internal and external registry images when provisioning workload services.
- Refined the image pulling logic to accommodate both internal and external sources.
- Ensured proper secret management during service deployment.
- Corrected and optimized key function parameters and API calls for clarity and functionality.
## 2024-12-20 - 1.0.134 - fix(core) ## 2024-12-20 - 1.0.134 - fix(core)
Updated dependencies and refactored ClusterManager and CloudlyConnector for improved Docker management. Updated dependencies and refactored ClusterManager and CloudlyConnector for improved Docker management.

View File

@ -62,7 +62,7 @@
"dependencies": { "dependencies": {
"@api.global/typedrequest": "^3.1.10", "@api.global/typedrequest": "^3.1.10",
"@api.global/typedsocket": "^3.0.1", "@api.global/typedsocket": "^3.0.1",
"@apiclient.xyz/docker": "^1.2.7", "@apiclient.xyz/docker": "^1.3.0",
"@push.rocks/early": "^4.0.3", "@push.rocks/early": "^4.0.3",
"@push.rocks/lik": "^6.1.0", "@push.rocks/lik": "^6.1.0",
"@push.rocks/projectinfo": "^5.0.1", "@push.rocks/projectinfo": "^5.0.1",
@ -79,8 +79,8 @@
"@push.rocks/smartstream": "^3.2.5", "@push.rocks/smartstream": "^3.2.5",
"@push.rocks/smartstring": "^4.0.15", "@push.rocks/smartstring": "^4.0.15",
"@push.rocks/taskbuffer": "^3.0.10", "@push.rocks/taskbuffer": "^3.0.10",
"@serve.zone/api": "^4.5.1", "@serve.zone/api": "^4.10.0",
"@serve.zone/interfaces": "^4.5.1", "@serve.zone/interfaces": "^4.10.0",
"@tsclass/tsclass": "^4.2.0", "@tsclass/tsclass": "^4.2.0",
"@types/node": "22.10.2" "@types/node": "22.10.2"
}, },

835
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@serve.zone/coreflow', name: '@serve.zone/coreflow',
version: '1.0.134', version: '1.0.135',
description: 'A comprehensive tool for managing Docker-based applications and services, enabling efficient scaling, network management, and integration with cloud services.' description: 'A comprehensive tool for managing Docker-based applications and services, enabling efficient scaling, network management, and integration with cloud services.'
} }

View File

@ -178,30 +178,55 @@ export class ClusterManager {
} }
public async provisionWorkloadService( public async provisionWorkloadService(
serviceArg: plugins.servezoneInterfaces.data.IService serviceArgFromCloudly: plugins.servezoneInterfaces.data.IService
) { ) {
logger.log('info', `deploying service ${serviceArg.data.name}@${serviceArg.data.imageVersion}...`); logger.log('info', `deploying service ${serviceArgFromCloudly.data.name}@${serviceArgFromCloudly.data.imageVersion}...`);
// get the image from cloudly // get the image from cloudly
logger.log('info', `getting image for ${serviceArg.data.name}@${serviceArg.data.imageVersion}`); logger.log('info', `getting image for ${serviceArgFromCloudly.data.name}@${serviceArgFromCloudly.data.imageVersion}`);
const containerImage = await this.coreflowRef.cloudlyConnector.cloudlyApiClient.images.getImageById(serviceArg.data.imageId); const containerImageFromCloudly = await this.coreflowRef.cloudlyConnector.cloudlyApiClient.image.getImageById(serviceArgFromCloudly.data.imageId);
const imageStream = await containerImage.pullImageVersion(serviceArg.data.imageVersion); let localDockerImage: plugins.docker.DockerImage
await plugins.docker.DockerImage.createFromTarStream(this.coreflowRef.dockerHost, {
creationObject: { // lets get the docker image for the service
imageUrl: containerImage.id, if (containerImageFromCloudly.data.location.internal) {
imageTag: serviceArg.data.imageVersion, const imageStream = await containerImageFromCloudly.pullImageVersion(serviceArgFromCloudly.data.imageVersion);
}, localDockerImage= await plugins.docker.DockerImage.createFromTarStream(this.coreflowRef.dockerHost, {
tarStream: plugins.smartstream.nodewebhelpers.convertWebReadableToNodeReadable(imageStream) creationObject: {
}); imageUrl: containerImageFromCloudly.id,
imageTag: serviceArgFromCloudly.data.imageVersion,
},
tarStream: plugins.smartstream.nodewebhelpers.convertWebReadableToNodeReadable(imageStream)
});
} else if (
containerImageFromCloudly.data.location.externalRegistryId
&& containerImageFromCloudly.data.location.externalImageTag
) {
const externalRegistry = await this.coreflowRef.cloudlyConnector.cloudlyApiClient.externalRegistry.getRegistryById(containerImageFromCloudly.data.location.externalRegistryId);
// Lets authenticate against the external registry
// TODO: deduplicate this, check wether we are already authenticated
await this.coreflowRef.dockerHost.auth({
username: externalRegistry.data.username,
password: externalRegistry.data.password,
serveraddress: externalRegistry.data.url,
});
localDockerImage = await plugins.docker.DockerImage.createFromRegistry(this.coreflowRef.dockerHost, {
creationObject: {
imageUrl: containerImageFromCloudly.id,
imageTag: serviceArgFromCloudly.data.imageVersion,
},
});
await localDockerImage.pullLatestImageFromRegistry();
} else {
throw new Error('Invalid image location');
}
let containerService = await plugins.docker.DockerService.getServiceByName( let containerService = await plugins.docker.DockerService.getServiceByName(
this.coreflowRef.dockerHost, this.coreflowRef.dockerHost,
serviceArg.data.name serviceArgFromCloudly.data.name
); );
const secretBundleId = serviceArg.data.secretBundleId;
this.coreflowRef.cloudlyConnector.cloudlyApiClient; this.coreflowRef.cloudlyConnector.cloudlyApiClient;
const dockerSecretName = `${serviceArg.id}_${serviceArg.data.name}_Secret`; const dockerSecretName = `${serviceArgFromCloudly.id}_${serviceArgFromCloudly.data.name}_Secret`;
let containerSecret = await plugins.docker.DockerSecret.getSecretByName( let containerSecret = await plugins.docker.DockerSecret.getSecretByName(
this.coreflowRef.dockerHost, this.coreflowRef.dockerHost,
dockerSecretName dockerSecretName
@ -231,23 +256,25 @@ export class ClusterManager {
await containerSecret.remove(); await containerSecret.remove();
} }
const secretBundle: plugins.servezoneInterfaces.data.ISecretBundle =this.coreflowRef.cloudlyConnector.cloudlyApiClient.; const secretBundle = await this.coreflowRef.cloudlyConnector.cloudlyApiClient.secretbundle.getSecretBundleById(serviceArgFromCloudly.data.secretBundleId);
// lets create the relevant stuff on the docker side
containerSecret = await plugins.docker.DockerSecret.createSecret(this.coreflowRef.dockerHost, { containerSecret = await plugins.docker.DockerSecret.createSecret(this.coreflowRef.dockerHost, {
name: dockerSecretName, name: dockerSecretName,
contentArg: JSON.stringify(secretBundle.data.), contentArg: JSON.stringify(await secretBundle.getFlatKeyValueObjectForEnvironment()),
labels: {}, labels: {},
version: await containerImage.getVersion(), version: await containerImageFromCloudly.data.versions[serviceArgFromCloudly.data.imageVersion],
}); });
containerService = await plugins.docker.DockerService.createService(this.coreflowRef.dockerHost, { containerService = await plugins.docker.DockerService.createService(this.coreflowRef.dockerHost, {
name: deploymentDirectiveArg.name, name: serviceArgFromCloudly.data.name,
image: containerImage, image: localDockerImage,
networks: [webGatewayNetwork], networks: [webGatewayNetwork],
secrets: [containerSecret], secrets: [containerSecret],
ports: [], ports: [],
labels: {}, labels: {},
resources: deploymentDirectiveArg.resources, resources: serviceArgFromCloudly.data.resources,
networkAlias: deploymentDirectiveArg.name, // TODO: introduce a clean name here, that is guaranteed to work with APIs.
networkAlias: serviceArgFromCloudly.data.name,
}); });
} }
} }