@wocker/ws 1.0.26 → 1.0.28-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/lib/AppModule.js +38 -4
  2. package/lib/modules/dns/controllers/DnsController.js +3 -0
  3. package/lib/modules/dns/index.js +5 -2
  4. package/lib/modules/dns/services/DnsService.d.ts +1 -1
  5. package/lib/modules/dns/services/DnsService.js +2 -2
  6. package/lib/modules/index.d.ts +0 -1
  7. package/lib/modules/index.js +0 -1
  8. package/lib/modules/preset/controllers/PresetController.d.ts +1 -1
  9. package/lib/modules/preset/controllers/PresetController.js +2 -2
  10. package/lib/modules/preset/controllers/PresetListener.d.ts +1 -1
  11. package/lib/modules/preset/controllers/PresetListener.js +2 -2
  12. package/lib/modules/preset/index.js +5 -2
  13. package/lib/modules/preset/repositories/PresetRepository.d.ts +3 -2
  14. package/lib/modules/preset/repositories/PresetRepository.js +9 -4
  15. package/lib/modules/preset/services/PresetService.js +1 -1
  16. package/lib/modules/project/controllers/ProjectController.js +13 -0
  17. package/lib/modules/project/index.js +6 -3
  18. package/lib/modules/project/services/ProjectService.d.ts +1 -1
  19. package/lib/modules/project/services/ProjectService.js +6 -4
  20. package/lib/modules/proxy/index.js +5 -2
  21. package/lib/modules/proxy/services/CertService.d.ts +1 -1
  22. package/lib/modules/proxy/services/CertService.js +2 -2
  23. package/lib/modules/proxy/services/ProxyService.d.ts +1 -1
  24. package/lib/modules/proxy/services/ProxyService.js +2 -2
  25. package/package.json +14 -4
  26. package/lib/modules/docker/index.d.ts +0 -9
  27. package/lib/modules/docker/index.js +0 -45
  28. package/lib/modules/docker/services/ComposeService.d.ts +0 -32
  29. package/lib/modules/docker/services/ComposeService.js +0 -127
  30. package/lib/modules/docker/services/ContainerService.d.ts +0 -14
  31. package/lib/modules/docker/services/ContainerService.js +0 -115
  32. package/lib/modules/docker/services/DockerService.d.ts +0 -31
  33. package/lib/modules/docker/services/DockerService.js +0 -245
  34. package/lib/modules/docker/services/ImageService.d.ts +0 -12
  35. package/lib/modules/docker/services/ImageService.js +0 -80
  36. package/lib/modules/docker/services/ModemService.d.ts +0 -15
  37. package/lib/modules/docker/services/ModemService.js +0 -156
  38. package/lib/modules/docker/services/ProtoService.d.ts +0 -6
  39. package/lib/modules/docker/services/ProtoService.js +0 -20
  40. package/lib/modules/docker/type/ComposeConfig.d.ts +0 -12
  41. package/lib/modules/docker/type/ComposeConfig.js +0 -2
  42. package/lib/modules/docker/utils/formatSizeUnits.d.ts +0 -1
  43. package/lib/modules/docker/utils/formatSizeUnits.js +0 -19
  44. package/proto/buildkit.proto +0 -55
  45. package/proto/solver/pb/ops.proto +0 -443
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ProtoService = exports.ModemService = exports.ImageService = exports.DockerService = exports.ContainerService = exports.ComposeService = exports.DockerModule = void 0;
10
- const core_1 = require("@wocker/core");
11
- const ComposeService_1 = require("./services/ComposeService");
12
- Object.defineProperty(exports, "ComposeService", { enumerable: true, get: function () { return ComposeService_1.ComposeService; } });
13
- const ContainerService_1 = require("./services/ContainerService");
14
- Object.defineProperty(exports, "ContainerService", { enumerable: true, get: function () { return ContainerService_1.ContainerService; } });
15
- const DockerService_1 = require("./services/DockerService");
16
- Object.defineProperty(exports, "DockerService", { enumerable: true, get: function () { return DockerService_1.DockerService; } });
17
- const ImageService_1 = require("./services/ImageService");
18
- Object.defineProperty(exports, "ImageService", { enumerable: true, get: function () { return ImageService_1.ImageService; } });
19
- const ModemService_1 = require("./services/ModemService");
20
- Object.defineProperty(exports, "ModemService", { enumerable: true, get: function () { return ModemService_1.ModemService; } });
21
- const ProtoService_1 = require("./services/ProtoService");
22
- Object.defineProperty(exports, "ProtoService", { enumerable: true, get: function () { return ProtoService_1.ProtoService; } });
23
- let DockerModule = class DockerModule {
24
- };
25
- exports.DockerModule = DockerModule;
26
- exports.DockerModule = DockerModule = __decorate([
27
- (0, core_1.Module)({
28
- providers: [
29
- ComposeService_1.ComposeService,
30
- ContainerService_1.ContainerService,
31
- DockerService_1.DockerService,
32
- ImageService_1.ImageService,
33
- ModemService_1.ModemService,
34
- ProtoService_1.ProtoService
35
- ],
36
- exports: [
37
- ComposeService_1.ComposeService,
38
- ContainerService_1.ContainerService,
39
- DockerService_1.DockerService,
40
- ImageService_1.ImageService,
41
- ModemService_1.ModemService,
42
- ProtoService_1.ProtoService
43
- ]
44
- })
45
- ], DockerModule);
@@ -1,32 +0,0 @@
1
- import { LogService } from "@wocker/core";
2
- import { ComposeConfig } from "../type/ComposeConfig";
3
- type UpOptions = {
4
- composefile: string;
5
- context: string;
6
- };
7
- type DownOptions = {
8
- composefile: string;
9
- context: string;
10
- };
11
- type BuildOptions = {
12
- composefile: string;
13
- context: string;
14
- };
15
- type ExecOptions = {
16
- service: string;
17
- args: string[];
18
- composefile: string;
19
- context: string;
20
- };
21
- export declare class ComposeService {
22
- protected readonly logService: LogService;
23
- constructor(logService: LogService);
24
- up(options: UpOptions): Promise<void>;
25
- down(options: DownOptions): Promise<void>;
26
- build(options: BuildOptions): Promise<void>;
27
- exec(options: ExecOptions): Promise<void>;
28
- protected getConfig(context: string, composefile: string): ComposeConfig;
29
- protected getConfigAsString(context: string, composefile: string): string;
30
- protected processChunk(chunk: Buffer<ArrayBufferLike>, streamSource?: "stdout" | "stderr"): void;
31
- }
32
- export {};
@@ -1,127 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- 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;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
- var __metadata = (this && this.__metadata) || function (k, v) {
42
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.ComposeService = void 0;
49
- const core_1 = require("@wocker/core");
50
- const yaml_1 = __importDefault(require("yaml"));
51
- const compose = __importStar(require("docker-compose"));
52
- let ComposeService = class ComposeService {
53
- constructor(logService) {
54
- this.logService = logService;
55
- }
56
- async up(options) {
57
- const { context, composefile } = options;
58
- const res = await compose.upAll({
59
- cwd: context,
60
- configAsString: this.getConfigAsString(context, composefile),
61
- callback: (chunk, streamSource) => this.processChunk(chunk, streamSource)
62
- });
63
- this.logService.debug("compose up", res);
64
- }
65
- async down(options) {
66
- const { context, composefile } = options;
67
- const res = await compose.downAll({
68
- cwd: context,
69
- configAsString: this.getConfigAsString(context, composefile),
70
- callback: (chunk, streamSource) => this.processChunk(chunk, streamSource)
71
- });
72
- this.logService.debug("compose down", res);
73
- }
74
- async build(options) {
75
- const { context, composefile } = options;
76
- const res = await compose.buildAll({
77
- cwd: context,
78
- config: composefile,
79
- callback: (chunk, streamSource) => this.processChunk(chunk, streamSource)
80
- });
81
- this.logService.debug("build", res);
82
- }
83
- async exec(options) {
84
- const { service, args, context, composefile } = options;
85
- await compose.exec(service, args, {
86
- configAsString: this.getConfigAsString(context, composefile),
87
- callback: (chunk, streamSource) => this.processChunk(chunk, streamSource)
88
- });
89
- }
90
- getConfig(context, composefile) {
91
- const fs = new core_1.FileSystem(context), config = fs.readYAML(composefile);
92
- if (!config.networks) {
93
- config.networks = {};
94
- }
95
- config.networks.workspace = {
96
- external: true
97
- };
98
- for (const name in config.services) {
99
- if (!config.services[name].networks) {
100
- config.services[name].networks = [];
101
- }
102
- if (!config.services[name].networks.includes("workspace")) {
103
- config.services[name].networks.push("workspace");
104
- }
105
- }
106
- return config;
107
- }
108
- getConfigAsString(context, composefile) {
109
- const config = this.getConfig(context, composefile);
110
- return yaml_1.default.stringify(config);
111
- }
112
- processChunk(chunk, streamSource) {
113
- switch (streamSource) {
114
- case "stdout":
115
- process.stdout.write(chunk);
116
- break;
117
- case "stderr":
118
- process.stderr.write(chunk);
119
- break;
120
- }
121
- }
122
- };
123
- exports.ComposeService = ComposeService;
124
- exports.ComposeService = ComposeService = __decorate([
125
- (0, core_1.Injectable)("DOCKER_COMPOSE_SERVICE"),
126
- __metadata("design:paramtypes", [core_1.LogService])
127
- ], ComposeService);
@@ -1,14 +0,0 @@
1
- import { LogService, DockerServiceParams as Params } from "@wocker/core";
2
- import { Duplex } from "stream";
3
- import type Docker from "dockerode";
4
- import type { Container } from "dockerode";
5
- import { ModemService } from "./ModemService";
6
- export declare class ContainerService {
7
- protected readonly logService: LogService;
8
- protected readonly modemService: ModemService;
9
- constructor(logService: LogService, modemService: ModemService);
10
- get docker(): Docker;
11
- get(name: string): Promise<Container>;
12
- rm(name: string): Promise<void>;
13
- exec(nameOrContainer: string | Container, options: Params.Exec | string[], _tty?: boolean): Promise<Duplex>;
14
- }
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ContainerService = void 0;
13
- const core_1 = require("@wocker/core");
14
- const ModemService_1 = require("./ModemService");
15
- let ContainerService = class ContainerService {
16
- constructor(logService, modemService) {
17
- this.logService = logService;
18
- this.modemService = modemService;
19
- }
20
- get docker() {
21
- return this.modemService.docker;
22
- }
23
- async get(name) {
24
- const containers = await this.docker.listContainers({
25
- all: true,
26
- filters: {
27
- name: [name]
28
- }
29
- });
30
- const container = containers.find((container) => {
31
- return container.Names.indexOf("/" + name) >= 0;
32
- });
33
- if (!container) {
34
- return null;
35
- }
36
- return this.docker.getContainer(container.Id);
37
- }
38
- async rm(name) {
39
- const container = await this.get(name);
40
- if (!container) {
41
- return;
42
- }
43
- const { State: { Status } } = await container.inspect();
44
- if (Status === "running" || Status === "restarting") {
45
- try {
46
- await container.stop();
47
- }
48
- catch (err) {
49
- this.logService.error("DockerService.removeContainer", err.message);
50
- }
51
- }
52
- try {
53
- await container.remove();
54
- }
55
- catch (err) {
56
- this.logService.error("DockerService.removeContainer: ", err.message);
57
- }
58
- }
59
- async exec(nameOrContainer, options, _tty) {
60
- const container = typeof nameOrContainer === "string"
61
- ? await this.get(nameOrContainer)
62
- : nameOrContainer;
63
- if (!container) {
64
- return;
65
- }
66
- const { cmd = [], tty = false, user } = Array.isArray(options) ? {
67
- cmd: options,
68
- tty: _tty
69
- } : options;
70
- const exec = await container.exec({
71
- AttachStdin: true,
72
- AttachStdout: true,
73
- AttachStderr: true,
74
- Tty: tty,
75
- User: user,
76
- Cmd: cmd,
77
- ConsoleSize: [
78
- process.stdout.rows,
79
- process.stdout.columns
80
- ]
81
- });
82
- const stream = await exec.start({
83
- hijack: true,
84
- stdin: tty,
85
- Tty: tty
86
- });
87
- if (tty) {
88
- const handleResize = async () => {
89
- const [width, height] = process.stdout.getWindowSize();
90
- this.logService.debug("Exec resize", {
91
- width,
92
- height
93
- });
94
- await exec.resize({
95
- w: width,
96
- h: height
97
- });
98
- };
99
- process.on("SIGWINCH", handleResize);
100
- try {
101
- await this.modemService.attachStream(stream);
102
- }
103
- finally {
104
- process.off("SIGWINCH", handleResize);
105
- }
106
- }
107
- return stream;
108
- }
109
- };
110
- exports.ContainerService = ContainerService;
111
- exports.ContainerService = ContainerService = __decorate([
112
- (0, core_1.Injectable)(),
113
- __metadata("design:paramtypes", [core_1.LogService,
114
- ModemService_1.ModemService])
115
- ], ContainerService);
@@ -1,31 +0,0 @@
1
- import { DockerService as CoreDockerService, DockerServiceParams as Params, LogService } from "@wocker/core";
2
- import type Docker from "dockerode";
3
- import type { Container, Volume, VolumeCreateResponse } from "dockerode";
4
- import { ContainerService } from "./ContainerService";
5
- import { ModemService } from "./ModemService";
6
- import { ImageService } from "./ImageService";
7
- export declare class DockerService extends CoreDockerService {
8
- protected readonly modemService: ModemService;
9
- protected readonly containerService: ContainerService;
10
- protected readonly imageService: ImageService;
11
- protected readonly logService: LogService;
12
- constructor(modemService: ModemService, containerService: ContainerService, imageService: ImageService, logService: LogService);
13
- get docker(): Docker;
14
- createVolume(name: string): Promise<VolumeCreateResponse>;
15
- hasVolume(name: string): Promise<boolean>;
16
- getVolume(name: string): Promise<Volume>;
17
- rmVolume(name: string): Promise<void>;
18
- createContainer(params: Params.CreateContainer): Promise<Container>;
19
- getContainer(name: string): Promise<Container | null>;
20
- removeContainer(name: string): Promise<void>;
21
- buildImage(params: Params.BuildImage): Promise<void>;
22
- imageExists(tag: string): Promise<boolean>;
23
- imageRm(tag: string, force?: boolean): Promise<void>;
24
- imageLs(options?: Params.ImageList): Promise<Docker.ImageInfo[]>;
25
- pullImage(tag: string): Promise<void>;
26
- attach(containerOrName: string | Container): Promise<NodeJS.ReadWriteStream>;
27
- attachStream(stream: NodeJS.ReadWriteStream): Promise<NodeJS.ReadWriteStream>;
28
- exec(nameOrContainer: string | Container, options: Params.Exec | string[], _tty?: boolean): Promise<import("stream").Duplex>;
29
- logs(containerOrName: string | Container): Promise<NodeJS.ReadableStream>;
30
- followProgress(stream: NodeJS.ReadableStream): Promise<void>;
31
- }
@@ -1,245 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DockerService = void 0;
13
- const core_1 = require("@wocker/core");
14
- const ContainerService_1 = require("./ContainerService");
15
- const ModemService_1 = require("./ModemService");
16
- const ImageService_1 = require("./ImageService");
17
- let DockerService = class DockerService extends core_1.DockerService {
18
- constructor(modemService, containerService, imageService, logService) {
19
- super();
20
- this.modemService = modemService;
21
- this.containerService = containerService;
22
- this.imageService = imageService;
23
- this.logService = logService;
24
- }
25
- get docker() {
26
- return this.modemService.docker;
27
- }
28
- async createVolume(name) {
29
- return await this.docker.createVolume({
30
- Name: name,
31
- Driver: "local"
32
- });
33
- }
34
- async hasVolume(name) {
35
- const volume = await this.getVolume(name);
36
- try {
37
- await volume.inspect();
38
- return true;
39
- }
40
- catch (err) {
41
- return false;
42
- }
43
- }
44
- async getVolume(name) {
45
- return this.docker.getVolume(name);
46
- }
47
- async rmVolume(name) {
48
- const volume = await this.getVolume(name);
49
- await volume.remove();
50
- }
51
- async createContainer(params) {
52
- const { name, user, entrypoint, tty, image, projectId, restart, memory, memorySwap, ulimits, extraHosts, networkMode = "bridge", links = [], env = {}, volumes = [], ports = [], cmd = [], network: networkName = "workspace", aliases } = params;
53
- const network = this.docker.getNetwork(networkName);
54
- try {
55
- await network.inspect();
56
- }
57
- catch (err) {
58
- if (err.statusCode === 404) {
59
- await this.docker.createNetwork({
60
- Name: networkName
61
- });
62
- }
63
- }
64
- await this.pullImage(image);
65
- return this.docker.createContainer({
66
- name,
67
- User: user,
68
- Image: image,
69
- Hostname: name,
70
- Labels: {
71
- ...projectId ? { projectId } : {}
72
- },
73
- AttachStdin: true,
74
- AttachStdout: true,
75
- AttachStderr: true,
76
- OpenStdin: true,
77
- StdinOnce: false,
78
- Entrypoint: entrypoint,
79
- Tty: true,
80
- Cmd: cmd,
81
- Env: Object.keys(env).map((key) => {
82
- const value = env[key];
83
- return `${key}=${value}`;
84
- }),
85
- ExposedPorts: ports.reduce((res, value) => {
86
- const [, , containerPort, type = "tcp"] = /(\d+):(\d+)(?:\/(\w+))?/.exec(value) || [];
87
- if (containerPort) {
88
- res[`${containerPort}/${type}`] = {};
89
- }
90
- return res;
91
- }, {}),
92
- HostConfig: {
93
- Memory: memory,
94
- MemorySwap: memorySwap,
95
- NetworkMode: networkMode,
96
- ExtraHosts: extraHosts,
97
- Ulimits: ulimits ? Object.keys(ulimits).reduce((res, name) => {
98
- return [
99
- ...res,
100
- {
101
- Name: name,
102
- Hard: ulimits[name].hard,
103
- Soft: ulimits[name].soft
104
- }
105
- ];
106
- }, []) : [],
107
- ...restart ? {
108
- RestartPolicy: {
109
- Name: restart
110
- }
111
- } : {},
112
- Binds: volumes,
113
- PortBindings: ports.reduce((res, value) => {
114
- const [, hostPort, containerPort, type = "tcp"] = /(\d+):(\d+)(?:\/(\w+))?/.exec(value) || [];
115
- if (hostPort && containerPort) {
116
- res[`${containerPort}/${type}`] = [
117
- { HostPort: hostPort }
118
- ];
119
- }
120
- else {
121
- this.logService.warn(`Invalid port format for container "${name}": "${value}". Expected format: hostPort:containerPort[/protocol]`);
122
- }
123
- return res;
124
- }, {})
125
- },
126
- NetworkingConfig: {
127
- EndpointsConfig: networkMode === "host" ? {} : {
128
- [networkName]: {
129
- Links: links,
130
- Aliases: aliases || (env.VIRTUAL_HOST ? env.VIRTUAL_HOST.split(",") : undefined)
131
- }
132
- }
133
- }
134
- });
135
- }
136
- async getContainer(name) {
137
- return this.containerService.get(name);
138
- }
139
- async removeContainer(name) {
140
- await this.containerService.rm(name);
141
- }
142
- async buildImage(params) {
143
- await this.imageService.build(params);
144
- }
145
- async imageExists(tag) {
146
- return this.imageService.exists(tag);
147
- }
148
- async imageRm(tag, force = false) {
149
- await this.imageService.rm(tag, force);
150
- }
151
- async imageLs(options) {
152
- const { tag, reference, labels } = options || {};
153
- const filters = {};
154
- if (reference) {
155
- filters.reference = [
156
- ...filters.reference || [],
157
- ...reference
158
- ];
159
- }
160
- if (tag) {
161
- filters.reference = [
162
- ...filters.reference || [],
163
- tag
164
- ];
165
- }
166
- if (labels) {
167
- filters.label = [];
168
- for (const i in labels) {
169
- filters.label.push(`${i}=${labels[i]}`);
170
- }
171
- }
172
- return this.docker.listImages({
173
- filters: JSON.stringify(filters)
174
- });
175
- }
176
- async pullImage(tag) {
177
- await this.imageService.pull(tag);
178
- }
179
- async attach(containerOrName) {
180
- let container = typeof containerOrName === "string"
181
- ? await this.getContainer(containerOrName)
182
- : containerOrName;
183
- if (!container) {
184
- return;
185
- }
186
- const stream = await container.attach({
187
- stream: true,
188
- hijack: true,
189
- stdin: true,
190
- stdout: true,
191
- stderr: true,
192
- logs: true,
193
- detachKeys: "ctrl-d"
194
- });
195
- await this.attachStream(stream);
196
- const handleResize = () => {
197
- const [width, height] = process.stdout.getWindowSize();
198
- container.resize({
199
- w: width,
200
- h: height
201
- });
202
- };
203
- process.stdout.on("resize", handleResize);
204
- handleResize();
205
- return stream;
206
- }
207
- async attachStream(stream) {
208
- return this.modemService.attachStream(stream);
209
- }
210
- async exec(nameOrContainer, options, _tty) {
211
- return await this.containerService.exec(nameOrContainer, options, _tty);
212
- }
213
- async logs(containerOrName) {
214
- const container = typeof containerOrName === "string"
215
- ? await this.getContainer(containerOrName)
216
- : containerOrName;
217
- if (!container) {
218
- return;
219
- }
220
- const stream = await container.logs({
221
- stdout: true,
222
- stderr: true,
223
- follow: true,
224
- tail: 4
225
- });
226
- stream.on("data", (data) => {
227
- process.stdout.write(data);
228
- });
229
- stream.on("error", (data) => {
230
- process.stderr.write(data);
231
- });
232
- return stream;
233
- }
234
- async followProgress(stream) {
235
- await this.modemService.followProgress(stream);
236
- }
237
- };
238
- exports.DockerService = DockerService;
239
- exports.DockerService = DockerService = __decorate([
240
- (0, core_1.Injectable)("DOCKER_SERVICE"),
241
- __metadata("design:paramtypes", [ModemService_1.ModemService,
242
- ContainerService_1.ContainerService,
243
- ImageService_1.ImageService,
244
- core_1.LogService])
245
- ], DockerService);
@@ -1,12 +0,0 @@
1
- import type Docker from "dockerode";
2
- import { DockerServiceParams as Params } from "@wocker/core";
3
- import { ModemService } from "./ModemService";
4
- export declare class ImageService {
5
- protected readonly modemService: ModemService;
6
- constructor(modemService: ModemService);
7
- get docker(): Docker;
8
- build(params: Params.BuildImage): Promise<void>;
9
- exists(tag: string): Promise<boolean>;
10
- pull(tag: string): Promise<void>;
11
- rm(tag: string, force?: boolean): Promise<void>;
12
- }