UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

89 lines 4.44 kB
// 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); } }; import fs from 'node:fs/promises'; import path from 'node:path'; import { inject, injectable } from 'tsyringe-neo'; import { InjectTokens } from '../../core/dependency-injection/inject-tokens.js'; import { patchInject } from '../../core/dependency-injection/container-helper.js'; import { ShellRunner } from '../../core/shell-runner.js'; import { DefaultKindClientBuilder } from '../kind/impl/default-kind-client-builder.js'; import { DependencyManager } from '../../core/dependency-managers/index.js'; import * as constants from '../../core/constants.js'; import { LoadImageArchiveOptionsBuilder } from '../kind/model/load-image-archive/load-image-archive-options-builder.js'; import { Architecture } from '../../business/utils/architecture.js'; let DockerClient = class DockerClient { kindBuilder; logger; dependencyManager; shellRunner; constructor(kindBuilder, logger, dependencyManager) { this.kindBuilder = kindBuilder; this.logger = logger; this.dependencyManager = dependencyManager; this.kindBuilder = patchInject(kindBuilder, InjectTokens.KindBuilder, this.constructor.name); this.logger = patchInject(logger, InjectTokens.SoloLogger, this.constructor.name); this.dependencyManager = patchInject(dependencyManager, InjectTokens.DependencyManager, this.constructor.name); this.shellRunner = new ShellRunner(this.logger); } async pullImage(image) { const platform = Architecture.getLinuxPlatform(); await this.shellRunner.run('docker', ['pull', '--platform', platform, image]); } async saveImage(image, archivePath) { await fs.mkdir(path.dirname(archivePath), { recursive: true }); const platform = Architecture.getLinuxPlatform(); await this.shellRunner.run('crane', ['pull', '--platform', platform, image, archivePath]); } async loadImage(archivePath) { await this.shellRunner.run('docker', ['load', '--input', archivePath]); } async loadImageArchiveIntoCluster(archivePath, clusterReference) { const options = LoadImageArchiveOptionsBuilder.builder() .archivePath(archivePath) .name(clusterReference) .build(); const kindExecutable = await this.dependencyManager.getExecutable(constants.KIND); const kindClient = await this.kindBuilder.executable(kindExecutable).build(true); await kindClient.loadImageArchive(archivePath, options); } async removeImage(image) { await this.shellRunner.run('docker', ['image', 'rm', image]); } async listLoadedImagesInCluster(clusterName) { const nodeName = `${clusterName}-control-plane`; const output = await this.shellRunner.run('docker', [ 'exec', '--privileged', nodeName, 'ctr', '--namespace=k8s.io', 'images', 'ls', '-q', ]); return output .map((line) => line.trim()) .filter((line) => line.length > 0) .filter((line) => !line.startsWith('import-')); } }; DockerClient = __decorate([ injectable(), __param(0, inject(InjectTokens.KindBuilder)), __param(1, inject(InjectTokens.SoloLogger)), __param(2, inject(InjectTokens.DependencyManager)), __metadata("design:paramtypes", [DefaultKindClientBuilder, Object, DependencyManager]) ], DockerClient); export { DockerClient }; //# sourceMappingURL=docker-client.js.map