@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
88 lines • 5.14 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var KindDependencyManager_1;
import * as constants from '../constants.js';
import * as version from '../../../version.js';
import { inject, injectable } from 'tsyringe-neo';
import { patchInject } from '../dependency-injection/container-helper.js';
import { InjectTokens } from '../dependency-injection/inject-tokens.js';
import { BaseDependencyManager } from './base-dependency-manager.js';
import { PackageDownloader } from '../package-downloader.js';
import util from 'node:util';
import { SoloError } from '../errors/solo-error.js';
import fs from 'node:fs';
import { OperatingSystem } from '../../business/utils/operating-system.js';
import { PathEx } from '../../business/utils/path-ex.js';
const KIND_RELEASE_BASE_URL = 'https://kind.sigs.k8s.io/dl';
const KIND_ARTIFACT_TEMPLATE = '%s/kind-%s-%s';
let KindDependencyManager = KindDependencyManager_1 = class KindDependencyManager extends BaseDependencyManager {
constructor(downloader, installationDirectory, osArch, kindVersion) {
super(patchInject(downloader, InjectTokens.PackageDownloader, KindDependencyManager_1.name), patchInject(installationDirectory, InjectTokens.KindInstallationDirectory, KindDependencyManager_1.name), patchInject(osArch, InjectTokens.OsArch, KindDependencyManager_1.name), patchInject(kindVersion, InjectTokens.KindVersion, KindDependencyManager_1.name) || version.KIND_VERSION, constants.KIND, KIND_RELEASE_BASE_URL);
}
/**
* Get the Kind artifact name based on version, OS, and architecture
*/
getArtifactName() {
return util.format(KIND_ARTIFACT_TEMPLATE, this.getRequiredVersion(), OperatingSystem.getFormattedPlatform(), this.osArch);
}
async getVersion(executableWithPath) {
// The retry logic is to handle potential transient issues with the command execution
// The command `kind --version` was sometimes observed to return an empty output in the CI environment
const maxAttempts = 3;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
const output = await this.run(`"${executableWithPath}" --version`, [], false, false, {}, 30_000);
this.logger.debug(`Attempt ${attempt}: Output from '${executableWithPath} --version': ${output.join('\n')}`);
if (output.length > 0) {
const match = output[0].trim().match(/(\d+\.\d+\.\d+)/);
this.logger.debug(`Attempt ${attempt}: Extracted version from output: ${match ? match[1] : 'No match found'}`);
if (match && match[1]) {
return match[1];
}
}
}
catch (error) {
throw new SoloError(`Failed to check kind version for input ${executableWithPath}`, error);
}
}
throw new SoloError('Failed to check kind version - no output received after multiple attempts for ' + executableWithPath);
}
getDownloadURL() {
return `${this.downloadBaseUrl}/${this.artifactName}`;
}
/**
* Handle any post-download processing before copying to destination
* Child classes can override this for custom extraction or processing
*/
async processDownloadedPackage(packageFilePath, temporaryDirectory) {
// Default implementation - just return the downloaded file path
// Child classes can override for extraction or other processing
const kindExecutablePath = PathEx.join(temporaryDirectory, this.executableName);
fs.renameSync(packageFilePath, kindExecutablePath);
return [kindExecutablePath];
}
getChecksumURL() {
return `${this.downloadURL}.sha256sum`;
}
};
KindDependencyManager = KindDependencyManager_1 = __decorate([
injectable(),
__param(0, inject(InjectTokens.PackageDownloader)),
__param(1, inject(InjectTokens.KindInstallationDirectory)),
__param(2, inject(InjectTokens.OsArch)),
__param(3, inject(InjectTokens.KindVersion)),
__metadata("design:paramtypes", [PackageDownloader, String, String, String])
], KindDependencyManager);
export { KindDependencyManager };
//# sourceMappingURL=kind-dependency-manager.js.map