@docker-harpoon/core 0.1.3 → 0.1.4
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.
- package/dist/__tests__/bindings.test.js +9 -5
- package/dist/__tests__/container.test.js +30 -9
- package/dist/__tests__/database.test.js +0 -14
- package/dist/__tests__/docker-infra.template.d.ts +2 -0
- package/dist/__tests__/docker-infra.template.d.ts.map +1 -0
- package/dist/__tests__/docker-infra.template.js +174 -0
- package/dist/__tests__/test-setup.d.ts +9 -0
- package/dist/__tests__/test-setup.d.ts.map +1 -0
- package/dist/__tests__/test-setup.js +20 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/promise.d.ts +12 -2
- package/dist/api/promise.d.ts.map +1 -1
- package/dist/api/promise.js +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/resources/container.d.ts +18 -0
- package/dist/resources/container.d.ts.map +1 -1
- package/dist/resources/container.js +81 -48
- package/dist/resources/index.d.ts +1 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/schemas.d.ts +1 -0
- package/dist/resources/schemas.d.ts.map +1 -1
- package/dist/resources/schemas.js +1 -0
- package/package.json +1 -1
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* - Env var injection into containers
|
|
7
7
|
* - Binding composition
|
|
8
8
|
*/
|
|
9
|
-
import { describe, test, expect, afterEach, setDefaultTimeout } from 'bun:test';
|
|
9
|
+
import { describe, test, expect, afterEach, beforeAll, setDefaultTimeout } from 'bun:test';
|
|
10
10
|
import { Container, database, createEnvBinding, destroyAll } from '../index';
|
|
11
|
+
import { buildTestImage, TEST_IMAGE } from './test-setup';
|
|
11
12
|
setDefaultTimeout(30_000);
|
|
12
13
|
const waitUntil = (fn, timeout = 5000) => {
|
|
13
14
|
return new Promise((resolve) => {
|
|
@@ -20,6 +21,9 @@ const waitUntil = (fn, timeout = 5000) => {
|
|
|
20
21
|
});
|
|
21
22
|
};
|
|
22
23
|
describe('Bindings', () => {
|
|
24
|
+
beforeAll(async () => {
|
|
25
|
+
await buildTestImage();
|
|
26
|
+
});
|
|
23
27
|
afterEach(async () => {
|
|
24
28
|
await destroyAll();
|
|
25
29
|
});
|
|
@@ -40,7 +44,7 @@ describe('Bindings', () => {
|
|
|
40
44
|
APP_VERSION: '1.0.0',
|
|
41
45
|
});
|
|
42
46
|
const container = await Container('test-binding-env', {
|
|
43
|
-
image:
|
|
47
|
+
image: TEST_IMAGE,
|
|
44
48
|
cmd: ['sleep', '30'],
|
|
45
49
|
bindings: {
|
|
46
50
|
config: configBinding,
|
|
@@ -65,7 +69,7 @@ describe('Bindings', () => {
|
|
|
65
69
|
VAR_D: 'd',
|
|
66
70
|
});
|
|
67
71
|
const container = await Container('test-multi-binding', {
|
|
68
|
-
image:
|
|
72
|
+
image: TEST_IMAGE,
|
|
69
73
|
cmd: ['sleep', '30'],
|
|
70
74
|
bindings: {
|
|
71
75
|
first: binding1,
|
|
@@ -86,7 +90,7 @@ describe('Bindings', () => {
|
|
|
86
90
|
MY_VAR: 'from-binding',
|
|
87
91
|
});
|
|
88
92
|
const container = await Container('test-env-precedence', {
|
|
89
|
-
image:
|
|
93
|
+
image: TEST_IMAGE,
|
|
90
94
|
cmd: ['sleep', '30'],
|
|
91
95
|
bindings: {
|
|
92
96
|
config: binding,
|
|
@@ -109,7 +113,7 @@ describe('Bindings', () => {
|
|
|
109
113
|
REDIS_URL: db.connectionString,
|
|
110
114
|
});
|
|
111
115
|
const container = await Container('test-db-consumer', {
|
|
112
|
-
image:
|
|
116
|
+
image: TEST_IMAGE,
|
|
113
117
|
cmd: ['sleep', '30'],
|
|
114
118
|
bindings: {
|
|
115
119
|
db: dbBinding,
|
|
@@ -8,16 +8,20 @@
|
|
|
8
8
|
* - stats retrieval
|
|
9
9
|
* - Lifecycle (stop, destroy)
|
|
10
10
|
*/
|
|
11
|
-
import { describe, test, expect, afterEach, setDefaultTimeout } from 'bun:test';
|
|
11
|
+
import { describe, test, expect, afterEach, beforeAll, setDefaultTimeout } from 'bun:test';
|
|
12
12
|
import { Network, Container, destroyAll } from '../index';
|
|
13
|
+
import { buildTestImage, TEST_IMAGE } from './test-setup';
|
|
13
14
|
setDefaultTimeout(30_000);
|
|
14
15
|
describe('Container', () => {
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
await buildTestImage();
|
|
18
|
+
});
|
|
15
19
|
afterEach(async () => {
|
|
16
20
|
await destroyAll();
|
|
17
21
|
});
|
|
18
22
|
test('creates a container with basic config', async () => {
|
|
19
23
|
const container = await Container('test-container-basic', {
|
|
20
|
-
image:
|
|
24
|
+
image: TEST_IMAGE,
|
|
21
25
|
cmd: ['sleep', '30'],
|
|
22
26
|
});
|
|
23
27
|
expect(container.id).toBeDefined();
|
|
@@ -27,7 +31,7 @@ describe('Container', () => {
|
|
|
27
31
|
test('creates a container attached to a network', async () => {
|
|
28
32
|
const network = await Network('test-container-net');
|
|
29
33
|
const container = await Container('test-container-networked', {
|
|
30
|
-
image:
|
|
34
|
+
image: TEST_IMAGE,
|
|
31
35
|
cmd: ['sleep', '30'],
|
|
32
36
|
networks: [network],
|
|
33
37
|
});
|
|
@@ -39,7 +43,7 @@ describe('Container', () => {
|
|
|
39
43
|
});
|
|
40
44
|
test('exec runs commands inside container', async () => {
|
|
41
45
|
const container = await Container('test-container-exec', {
|
|
42
|
-
image:
|
|
46
|
+
image: TEST_IMAGE,
|
|
43
47
|
cmd: ['sleep', '30'],
|
|
44
48
|
});
|
|
45
49
|
await new Promise((r) => setTimeout(r, 500));
|
|
@@ -51,7 +55,7 @@ describe('Container', () => {
|
|
|
51
55
|
});
|
|
52
56
|
test('stats returns container resource statistics', async () => {
|
|
53
57
|
const container = await Container('test-container-stats', {
|
|
54
|
-
image:
|
|
58
|
+
image: TEST_IMAGE,
|
|
55
59
|
cmd: ['sleep', '30'],
|
|
56
60
|
});
|
|
57
61
|
await new Promise((r) => setTimeout(r, 500));
|
|
@@ -66,7 +70,7 @@ describe('Container', () => {
|
|
|
66
70
|
});
|
|
67
71
|
test('waitForLog detects log patterns', async () => {
|
|
68
72
|
const container = await Container('test-container-logs', {
|
|
69
|
-
image:
|
|
73
|
+
image: TEST_IMAGE,
|
|
70
74
|
cmd: ['sh', '-c', 'echo "Server started successfully" && sleep 30'],
|
|
71
75
|
});
|
|
72
76
|
await container.waitForLog('Server started', 5000);
|
|
@@ -75,7 +79,7 @@ describe('Container', () => {
|
|
|
75
79
|
});
|
|
76
80
|
test('stop gracefully shuts down container', async () => {
|
|
77
81
|
const container = await Container('test-container-stop', {
|
|
78
|
-
image:
|
|
82
|
+
image: TEST_IMAGE,
|
|
79
83
|
cmd: ['sh', '-c', 'trap "exit 0" TERM; while true; do sleep 1; done'],
|
|
80
84
|
});
|
|
81
85
|
await new Promise((r) => setTimeout(r, 500));
|
|
@@ -87,7 +91,7 @@ describe('Container', () => {
|
|
|
87
91
|
});
|
|
88
92
|
test('supports environment variables', async () => {
|
|
89
93
|
const container = await Container('test-container-env', {
|
|
90
|
-
image:
|
|
94
|
+
image: TEST_IMAGE,
|
|
91
95
|
cmd: ['sleep', '30'],
|
|
92
96
|
env: {
|
|
93
97
|
MY_VAR: 'hello',
|
|
@@ -105,11 +109,28 @@ describe('Container', () => {
|
|
|
105
109
|
});
|
|
106
110
|
test('supports port mappings', async () => {
|
|
107
111
|
const container = await Container('test-container-ports', {
|
|
108
|
-
image:
|
|
112
|
+
image: TEST_IMAGE,
|
|
109
113
|
cmd: ['sleep', '30'],
|
|
110
114
|
ports: [{ internal: 8080, external: 18080 }],
|
|
111
115
|
});
|
|
112
116
|
expect(container.id).toBeDefined();
|
|
113
117
|
await container.destroy();
|
|
114
118
|
});
|
|
119
|
+
test('streamLogs terminates without follow option', async () => {
|
|
120
|
+
const container = await Container('test-logs-terminate', {
|
|
121
|
+
image: TEST_IMAGE,
|
|
122
|
+
cmd: ['sh', '-c', 'echo "line1" && echo "line2" && echo "line3" && sleep 30'],
|
|
123
|
+
});
|
|
124
|
+
await container.waitForLog('line3', 5000);
|
|
125
|
+
const lines = [];
|
|
126
|
+
const logStream = await container.streamLogs({ tail: 3 });
|
|
127
|
+
for await (const line of logStream) {
|
|
128
|
+
lines.push(line.message);
|
|
129
|
+
}
|
|
130
|
+
// Loop should exit naturally
|
|
131
|
+
expect(lines).toContain('line1');
|
|
132
|
+
expect(lines).toContain('line2');
|
|
133
|
+
expect(lines).toContain('line3');
|
|
134
|
+
await container.destroy();
|
|
135
|
+
});
|
|
115
136
|
});
|
|
@@ -50,20 +50,6 @@ describe('database', () => {
|
|
|
50
50
|
expect(db.connectionString).toBe('redis://:secret@localhost:16380');
|
|
51
51
|
await db.destroy();
|
|
52
52
|
});
|
|
53
|
-
test('creates a mysql database with connection string', async () => {
|
|
54
|
-
const db = await database('test-mysql', {
|
|
55
|
-
image: 'mysql:8',
|
|
56
|
-
env: {
|
|
57
|
-
MYSQL_ROOT_PASSWORD: 'rootpass',
|
|
58
|
-
MYSQL_DATABASE: 'mydb',
|
|
59
|
-
},
|
|
60
|
-
hostPort: 13306,
|
|
61
|
-
});
|
|
62
|
-
expect(db.port).toBe(3306);
|
|
63
|
-
expect(db.hostPort).toBe(13306);
|
|
64
|
-
expect(db.connectionString).toBe('mysql://root:rootpass@localhost:13306/mydb');
|
|
65
|
-
await db.destroy();
|
|
66
|
-
});
|
|
67
53
|
test('attaches database to network', async () => {
|
|
68
54
|
const network = await Network('test-db-net');
|
|
69
55
|
const db = await database('test-db-networked', {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker-infra.template.d.ts","sourceRoot":"","sources":["../../src/__tests__/docker-infra.template.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docker Infrastructure Test Template
|
|
3
|
+
*
|
|
4
|
+
* Copy and customize this file to test your project's Dockerfile and entrypoint.
|
|
5
|
+
* Replace {{PROJECT_NAME}} and {{PROJECT_IMAGE}} with your values.
|
|
6
|
+
*
|
|
7
|
+
* This template demonstrates Harpoon's complete API for testing Docker infrastructure:
|
|
8
|
+
* - Image building with buildArgs
|
|
9
|
+
* - Container creation with volumes, capabilities, and user overrides
|
|
10
|
+
* - Log waiting and streaming
|
|
11
|
+
* - Command execution inside containers
|
|
12
|
+
* - Network isolation testing
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```bash
|
|
16
|
+
* # Copy and customize for your project
|
|
17
|
+
* cp docker-infra.template.ts my-project.test.ts
|
|
18
|
+
* # Edit PROJECT config and tests
|
|
19
|
+
* bun test my-project.test.ts
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { describe, test, expect, beforeAll, afterEach, setDefaultTimeout } from 'bun:test';
|
|
23
|
+
import { Image, Container, Network, destroyAll } from '@docker-harpoon/core';
|
|
24
|
+
// ============ PROJECT CONFIGURATION ============
|
|
25
|
+
// Customize these values for your project
|
|
26
|
+
const PROJECT = {
|
|
27
|
+
name: '{{PROJECT_NAME}}',
|
|
28
|
+
image: '{{PROJECT_IMAGE}}:latest',
|
|
29
|
+
context: './',
|
|
30
|
+
dockerfile: 'Dockerfile',
|
|
31
|
+
port: 3000,
|
|
32
|
+
healthPath: '/api/status',
|
|
33
|
+
};
|
|
34
|
+
// Set a generous timeout for Docker operations
|
|
35
|
+
setDefaultTimeout(120_000);
|
|
36
|
+
describe(`${PROJECT.name} Docker Infrastructure`, () => {
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
// Build the project image
|
|
39
|
+
await Image(PROJECT.image, {
|
|
40
|
+
context: PROJECT.context,
|
|
41
|
+
dockerfile: PROJECT.dockerfile,
|
|
42
|
+
buildArgs: { SEED_DATABASE: 'true' },
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
afterEach(async () => {
|
|
46
|
+
await destroyAll();
|
|
47
|
+
});
|
|
48
|
+
// ============ HEALTH CHECK TEST ============
|
|
49
|
+
test('health check responds 200', async () => {
|
|
50
|
+
const container = await Container('test-health', {
|
|
51
|
+
image: PROJECT.image,
|
|
52
|
+
env: { PORT: String(PROJECT.port) },
|
|
53
|
+
ports: [{ internal: PROJECT.port, external: 13000 }],
|
|
54
|
+
});
|
|
55
|
+
await container.waitForLog(/listening|started|ready/i, 30000);
|
|
56
|
+
const res = await fetch(`http://localhost:13000${PROJECT.healthPath}`);
|
|
57
|
+
expect(res.status).toBe(200);
|
|
58
|
+
});
|
|
59
|
+
// ============ VOLUME MOUNT TEST ============
|
|
60
|
+
test('db snapshot copy-on-boot pattern', async () => {
|
|
61
|
+
const container = await Container('test-snapshot', {
|
|
62
|
+
image: PROJECT.image,
|
|
63
|
+
env: {
|
|
64
|
+
DB_SOURCE: '/data/snapshot/app.db',
|
|
65
|
+
DB_PATH: '/app/data/test.db',
|
|
66
|
+
},
|
|
67
|
+
volumes: [
|
|
68
|
+
{ hostPath: '/tmp/test-snapshot.db', containerPath: '/data/snapshot/app.db', readonly: true },
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
await container.waitForLog(/snapshot copied|database ready/i, 30000);
|
|
72
|
+
});
|
|
73
|
+
// ============ FILE SYSTEM TEST ============
|
|
74
|
+
test('file upload directory setup', async () => {
|
|
75
|
+
const container = await Container('test-uploads', {
|
|
76
|
+
image: PROJECT.image,
|
|
77
|
+
env: { FILE_UPLOAD_PATH: '/app/custom-uploads' },
|
|
78
|
+
});
|
|
79
|
+
await container.waitForLog(/upload directory|ensuring/i, 10000);
|
|
80
|
+
const result = await container.exec(['ls', '-la', '/app/custom-uploads']);
|
|
81
|
+
expect(result.exitCode).toBe(0);
|
|
82
|
+
expect(result.stdout).toContain('drwx'); // Directory exists with permissions
|
|
83
|
+
});
|
|
84
|
+
// ============ NETWORK ISOLATION TEST ============
|
|
85
|
+
test('network isolation with iptables', async () => {
|
|
86
|
+
const network = await Network('isolated-net');
|
|
87
|
+
const container = await Container('test-isolation', {
|
|
88
|
+
image: PROJECT.image,
|
|
89
|
+
networks: [network],
|
|
90
|
+
env: { ENABLE_NETWORK_ISOLATION: 'true' },
|
|
91
|
+
capAdd: ['NET_ADMIN'],
|
|
92
|
+
});
|
|
93
|
+
await container.waitForLog(/network isolation configured|iptables/i, 15000);
|
|
94
|
+
});
|
|
95
|
+
// ============ PRIVILEGE DROPPING TEST ============
|
|
96
|
+
test('privilege dropping', async () => {
|
|
97
|
+
const container = await Container('test-privileges', {
|
|
98
|
+
image: PROJECT.image,
|
|
99
|
+
});
|
|
100
|
+
await container.waitForLog(/dropping privileges|started/i, 15000);
|
|
101
|
+
const result = await container.exec(['whoami']);
|
|
102
|
+
expect(result.exitCode).toBe(0);
|
|
103
|
+
expect(result.stdout.trim()).not.toBe('root');
|
|
104
|
+
});
|
|
105
|
+
// ============ ENVIRONMENT VARIABLE TEST ============
|
|
106
|
+
test('environment variable propagation', async () => {
|
|
107
|
+
const container = await Container('test-env', {
|
|
108
|
+
image: PROJECT.image,
|
|
109
|
+
env: {
|
|
110
|
+
PORT: '8080',
|
|
111
|
+
LOG_LEVEL: 'debug',
|
|
112
|
+
CUSTOM_VAR: 'test-value',
|
|
113
|
+
},
|
|
114
|
+
ports: [{ internal: 8080, external: 18080 }],
|
|
115
|
+
});
|
|
116
|
+
await container.waitForLog(/listening|started/i, 30000);
|
|
117
|
+
// Verify env vars are set
|
|
118
|
+
const envResult = await container.exec(['printenv']);
|
|
119
|
+
expect(envResult.stdout).toContain('PORT=8080');
|
|
120
|
+
expect(envResult.stdout).toContain('LOG_LEVEL=debug');
|
|
121
|
+
expect(envResult.stdout).toContain('CUSTOM_VAR=test-value');
|
|
122
|
+
});
|
|
123
|
+
// ============ USER OVERRIDE TEST ============
|
|
124
|
+
test('user override', async () => {
|
|
125
|
+
const container = await Container('test-user', {
|
|
126
|
+
image: PROJECT.image,
|
|
127
|
+
user: '1000:1000',
|
|
128
|
+
});
|
|
129
|
+
await container.waitForLog(/started|ready/i, 15000);
|
|
130
|
+
const result = await container.exec(['id']);
|
|
131
|
+
expect(result.exitCode).toBe(0);
|
|
132
|
+
expect(result.stdout).toContain('uid=1000');
|
|
133
|
+
expect(result.stdout).toContain('gid=1000');
|
|
134
|
+
});
|
|
135
|
+
// ============ CAPABILITIES TEST ============
|
|
136
|
+
test('dropped capabilities', async () => {
|
|
137
|
+
const container = await Container('test-caps', {
|
|
138
|
+
image: PROJECT.image,
|
|
139
|
+
capDrop: ['ALL'],
|
|
140
|
+
capAdd: ['NET_BIND_SERVICE'],
|
|
141
|
+
});
|
|
142
|
+
await container.waitForLog(/started|ready/i, 15000);
|
|
143
|
+
// Container should be running with minimal capabilities
|
|
144
|
+
const result = await container.exec(['cat', '/proc/1/status']);
|
|
145
|
+
expect(result.exitCode).toBe(0);
|
|
146
|
+
// CapEff should show limited capabilities
|
|
147
|
+
expect(result.stdout).toContain('CapEff');
|
|
148
|
+
});
|
|
149
|
+
// ============ GRACEFUL SHUTDOWN TEST ============
|
|
150
|
+
test('graceful shutdown', async () => {
|
|
151
|
+
const container = await Container('test-shutdown', {
|
|
152
|
+
image: PROJECT.image,
|
|
153
|
+
env: { PORT: String(PROJECT.port) },
|
|
154
|
+
});
|
|
155
|
+
await container.waitForLog(/listening|started|ready/i, 30000);
|
|
156
|
+
const metadata = await container.stop('SIGTERM', 10000);
|
|
157
|
+
expect(metadata.graceful).toBe(true);
|
|
158
|
+
expect(metadata.signal).toBe('SIGTERM');
|
|
159
|
+
});
|
|
160
|
+
// ============ RESOURCE STATS TEST ============
|
|
161
|
+
test('container stats', async () => {
|
|
162
|
+
const container = await Container('test-stats', {
|
|
163
|
+
image: PROJECT.image,
|
|
164
|
+
env: { PORT: String(PROJECT.port) },
|
|
165
|
+
});
|
|
166
|
+
await container.waitForLog(/listening|started|ready/i, 30000);
|
|
167
|
+
const stats = await container.stats();
|
|
168
|
+
expect(stats.cpu).toBeDefined();
|
|
169
|
+
expect(stats.cpu.percent).toBeGreaterThanOrEqual(0);
|
|
170
|
+
expect(stats.memory).toBeDefined();
|
|
171
|
+
expect(stats.memory.usage).toBeGreaterThan(0);
|
|
172
|
+
expect(stats.network).toBeDefined();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test setup for integration tests.
|
|
3
|
+
*
|
|
4
|
+
* Builds a minimal test image that can be used across all tests,
|
|
5
|
+
* ensuring tests are self-contained and don't rely on external images.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TEST_IMAGE = "harpoon-test:latest";
|
|
8
|
+
export declare function buildTestImage(): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=test-setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/test-setup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,eAAO,MAAM,UAAU,wBAAwB,CAAC;AAIhD,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAWpD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test setup for integration tests.
|
|
3
|
+
*
|
|
4
|
+
* Builds a minimal test image that can be used across all tests,
|
|
5
|
+
* ensuring tests are self-contained and don't rely on external images.
|
|
6
|
+
*/
|
|
7
|
+
import { Image } from '../index';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
export const TEST_IMAGE = 'harpoon-test:latest';
|
|
10
|
+
let imageBuilt = false;
|
|
11
|
+
export async function buildTestImage() {
|
|
12
|
+
if (imageBuilt) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
await Image(TEST_IMAGE, {
|
|
16
|
+
context: join(__dirname, 'fixtures'),
|
|
17
|
+
dockerfile: 'Dockerfile',
|
|
18
|
+
});
|
|
19
|
+
imageBuilt = true;
|
|
20
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Re-exports the Promise-based API for cleaner imports.
|
|
5
5
|
*/
|
|
6
|
-
export { Network, Container, database, Image, setDocker, resetDocker, destroyAll, type NetworkConfig, type NetworkResource, type ContainerConfig, type ContainerResource, type PortMapping, type ShutdownMetadata, type DatabaseConfig, type DatabaseResource, type ImageConfig, type ImageResource, type ContainerStats, type ExecOptions, type ExecResult, type LogOptions, type LogLine, } from './promise';
|
|
6
|
+
export { Network, Container, database, Image, setDocker, resetDocker, destroyAll, type NetworkConfig, type NetworkResource, type ContainerConfig, type ContainerResource, type PortMapping, type ShutdownMetadata, type DatabaseConfig, type DatabaseResource, type ImageConfig, type ImageResource, type ContainerStats, type ExecOptions, type ExecResult, type LogOptions, type LogLine, type VolumeMapping, } from './promise';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAK,EAGL,SAAS,EACT,WAAW,EACX,UAAU,EAGV,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,aAAa,EAGlB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAK,EAGL,SAAS,EACT,WAAW,EACX,UAAU,EAGV,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,aAAa,EAGlB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC"}
|
package/dist/api/promise.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* Inspired by Alchemy.run and Pulumi's IAC patterns.
|
|
8
8
|
*/
|
|
9
9
|
import Docker from 'dockerode';
|
|
10
|
-
import { type ContainerStats, type ExecOptions, type ExecResult, type LogOptions, type LogLine } from '../resources';
|
|
11
|
-
export type { ContainerStats, ExecOptions, ExecResult, LogOptions, LogLine, } from '../resources';
|
|
10
|
+
import { type ContainerStats, type ExecOptions, type ExecResult, type LogOptions, type LogLine, type VolumeMapping } from '../resources';
|
|
11
|
+
export type { ContainerStats, ExecOptions, ExecResult, LogOptions, LogLine, VolumeMapping, } from '../resources';
|
|
12
12
|
import type { Binding } from '../bindings/types';
|
|
13
13
|
export interface NetworkConfig {
|
|
14
14
|
/** Network driver (default: 'bridge') */
|
|
@@ -41,6 +41,16 @@ export interface ContainerConfig {
|
|
|
41
41
|
cmd?: string[];
|
|
42
42
|
/** Bindings that provide env vars and lifecycle hooks */
|
|
43
43
|
bindings?: Record<string, Binding>;
|
|
44
|
+
/** Volume mounts (host:container) */
|
|
45
|
+
volumes?: VolumeMapping[];
|
|
46
|
+
/** Capabilities to add (e.g., 'NET_ADMIN', 'SYS_PTRACE') */
|
|
47
|
+
capAdd?: string[];
|
|
48
|
+
/** Capabilities to drop (e.g., 'ALL') */
|
|
49
|
+
capDrop?: string[];
|
|
50
|
+
/** Run in privileged mode */
|
|
51
|
+
privileged?: boolean;
|
|
52
|
+
/** User/group to run as (e.g., '1000:1000') */
|
|
53
|
+
user?: string;
|
|
44
54
|
}
|
|
45
55
|
export interface ContainerResource {
|
|
46
56
|
readonly id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../src/api/promise.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,MAAM,MAAM,WAAW,CAAC;AAG/B,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../src/api/promise.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,MAAM,MAAM,WAAW,CAAC;AAG/B,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,cAAc,EACd,WAAW,EACX,UAAU,EACV,UAAU,EACV,OAAO,EACP,aAAa,GACd,MAAM,cAAc,CAAC;AAOtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIjD,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0BAA0B;IAC1B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM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AkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uCAAuC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AA0ID;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC;AA4CD;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,aAAkB,GACzB,OAAO,CAAC,eAAe,CAAC,CA+B1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,iBAAiB,CAAC,CAsE5B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,gBAAgB,CAAC,CAoE3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,KAAK,CACzB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,aAAa,CAAC,CAWxB;AAED;;;GAGG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAShD"}
|
package/dist/api/promise.js
CHANGED
|
@@ -237,6 +237,11 @@ export async function Container(name, config) {
|
|
|
237
237
|
...(config.env !== undefined && { env: config.env }),
|
|
238
238
|
...(config.cmd !== undefined && { cmd: config.cmd }),
|
|
239
239
|
...(config.bindings !== undefined && { bindings: config.bindings }),
|
|
240
|
+
...(config.volumes !== undefined && { volumes: config.volumes }),
|
|
241
|
+
...(config.capAdd !== undefined && { capAdd: config.capAdd }),
|
|
242
|
+
...(config.capDrop !== undefined && { capDrop: config.capDrop }),
|
|
243
|
+
...(config.privileged !== undefined && { privileged: config.privileged }),
|
|
244
|
+
...(config.user !== undefined && { user: config.user }),
|
|
240
245
|
};
|
|
241
246
|
const effectResource = await Effect.runPromise(EffectContainer(name, effectConfig, docker).pipe(Scope.extend(scope)));
|
|
242
247
|
const resourceId = `container:${effectResource.id}`;
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* - Binding interface for env var injection and lifecycle hooks
|
|
28
28
|
* - BuildBinding interface for Dockerfile transformations
|
|
29
29
|
*/
|
|
30
|
-
export { Network, Container, database, Image, setDocker, resetDocker, destroyAll, type NetworkConfig, type NetworkResource, type ContainerConfig, type ContainerResource, type PortMapping, type ShutdownMetadata, type DatabaseConfig, type DatabaseResource, type ImageConfig, type ImageResource, type ContainerStats, type ExecOptions, type ExecResult, type LogOptions, type LogLine, } from './api';
|
|
30
|
+
export { Network, Container, database, Image, setDocker, resetDocker, destroyAll, type NetworkConfig, type NetworkResource, type ContainerConfig, type ContainerResource, type PortMapping, type ShutdownMetadata, type DatabaseConfig, type DatabaseResource, type ImageConfig, type ImageResource, type ContainerStats, type ExecOptions, type ExecResult, type LogOptions, type LogLine, type VolumeMapping, } from './api';
|
|
31
31
|
export type { Binding, BuildBinding, BindingsEnv, FlatBindingsEnv, } from './bindings';
|
|
32
32
|
export { isBuildBinding, mergeBindingsEnv, createEnvBinding, } from './bindings';
|
|
33
33
|
export { HarpoonError, NetworkError, ImageError, ContainerError, ScopeError, BindingError, toHarpoonError, asCause, isHarpoonError, isNetworkError, isImageError, isContainerError, isScopeError, isBindingError, } from './errors';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,EAEL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAK,EAGL,SAAS,EACT,WAAW,EACX,UAAU,EAGV,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,aAAa,EAGlB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,EAEL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAK,EAGL,SAAS,EACT,WAAW,EACX,UAAU,EAGV,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,aAAa,EAGlB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,aAAa,GACnB,MAAM,OAAO,CAAC;AAIf,YAAY,EACV,OAAO,EACP,YAAY,EACZ,WAAW,EACX,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAIpB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,UAAU,EACV,YAAY,EACZ,cAAc,EACd,OAAO,EACP,cAAc,EACd,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,cAAc,GACf,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhD,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,8BAA8B,EAC9B,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,MAAM,EACN,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,GAChB,MAAM,2BAA2B,CAAC"}
|
|
@@ -14,6 +14,14 @@ export interface PortMapping {
|
|
|
14
14
|
internal: number;
|
|
15
15
|
external: number;
|
|
16
16
|
}
|
|
17
|
+
export interface VolumeMapping {
|
|
18
|
+
/** Host path to mount */
|
|
19
|
+
hostPath: string;
|
|
20
|
+
/** Container path to mount at */
|
|
21
|
+
containerPath: string;
|
|
22
|
+
/** Mount as read-only */
|
|
23
|
+
readonly?: boolean;
|
|
24
|
+
}
|
|
17
25
|
export interface ContainerConfig {
|
|
18
26
|
image: string;
|
|
19
27
|
networks?: Array<{
|
|
@@ -24,6 +32,16 @@ export interface ContainerConfig {
|
|
|
24
32
|
cmd?: string[];
|
|
25
33
|
/** Bindings that provide env vars and lifecycle hooks */
|
|
26
34
|
bindings?: Record<string, Binding>;
|
|
35
|
+
/** Volume mounts (host:container) */
|
|
36
|
+
volumes?: VolumeMapping[];
|
|
37
|
+
/** Capabilities to add (e.g., 'NET_ADMIN', 'SYS_PTRACE') */
|
|
38
|
+
capAdd?: string[];
|
|
39
|
+
/** Capabilities to drop (e.g., 'ALL') */
|
|
40
|
+
capDrop?: string[];
|
|
41
|
+
/** Run in privileged mode */
|
|
42
|
+
privileged?: boolean;
|
|
43
|
+
/** User/group to run as (e.g., '1000:1000') */
|
|
44
|
+
user?: string;
|
|
27
45
|
}
|
|
28
46
|
export interface ShutdownMetadata {
|
|
29
47
|
signalCount: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/resources/container.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAA0B,MAAM,QAAQ,CAAC;AAC/D,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,EACb,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,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AE,KAAK,CAAC,CAAC;IAC1E,iDAAiD;IACjD,QAAQ,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;CAC7F;AA6ED,eAAO,MAAM,SAAS,uHAgkBnB,CAAC"}
|
|
@@ -142,9 +142,14 @@ export const Container = (resourceId, config, docker) => Effect.acquireRelease(E
|
|
|
142
142
|
NetworkMode: config.networks?.[0]?.name,
|
|
143
143
|
AutoRemove: false,
|
|
144
144
|
PortBindings,
|
|
145
|
+
Binds: config.volumes?.map(v => `${v.hostPath}:${v.containerPath}${v.readonly ? ':ro' : ''}`),
|
|
146
|
+
CapAdd: config.capAdd,
|
|
147
|
+
CapDrop: config.capDrop,
|
|
148
|
+
Privileged: config.privileged,
|
|
145
149
|
},
|
|
146
150
|
ExposedPorts,
|
|
147
151
|
Cmd: config.cmd,
|
|
152
|
+
User: config.user,
|
|
148
153
|
StopSignal: 'SIGTERM',
|
|
149
154
|
StopTimeout: 10,
|
|
150
155
|
});
|
|
@@ -376,66 +381,94 @@ export const Container = (resourceId, config, docker) => Effect.acquireRelease(E
|
|
|
376
381
|
const stdout = opts.stdout ?? true;
|
|
377
382
|
const stderr = opts.stderr ?? true;
|
|
378
383
|
const timestamps = opts.timestamps ?? false;
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
// Create a wrapper to make the stream async iterable
|
|
389
|
-
const readable = stream;
|
|
390
|
-
// Convert NodeJS.ReadableStream to AsyncIterable<LogLine>
|
|
391
|
-
async function* logIterator() {
|
|
392
|
-
const chunks = [];
|
|
393
|
-
// Use Promise-based iteration for ReadableStream
|
|
394
|
-
for await (const chunk of readable) {
|
|
395
|
-
// Parse Docker log format (8-byte header + payload)
|
|
396
|
-
let offset = 0;
|
|
397
|
-
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
398
|
-
while (offset < buffer.length) {
|
|
399
|
-
if (offset + 8 > buffer.length) {
|
|
400
|
-
// Incomplete header, yield rest as stdout
|
|
384
|
+
const follow = opts.follow ?? false;
|
|
385
|
+
// Helper to parse Docker log format from a buffer
|
|
386
|
+
function* parseLogBuffer(buffer) {
|
|
387
|
+
let offset = 0;
|
|
388
|
+
while (offset < buffer.length) {
|
|
389
|
+
if (offset + 8 > buffer.length) {
|
|
390
|
+
// Incomplete header, yield rest as stdout
|
|
391
|
+
const remaining = buffer.slice(offset).toString('utf-8').trim();
|
|
392
|
+
if (remaining) {
|
|
401
393
|
yield {
|
|
402
394
|
stream: 'stdout',
|
|
403
|
-
message:
|
|
395
|
+
message: remaining,
|
|
404
396
|
};
|
|
405
|
-
break;
|
|
406
397
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
const streamType = buffer.readUInt8(offset);
|
|
401
|
+
const size = buffer.readUInt32BE(offset + 4);
|
|
402
|
+
if (offset + 8 + size > buffer.length) {
|
|
403
|
+
// Incomplete payload
|
|
404
|
+
const remaining = buffer.slice(offset + 8).toString('utf-8').trim();
|
|
405
|
+
if (remaining) {
|
|
411
406
|
yield {
|
|
412
407
|
stream: streamType === 2 ? 'stderr' : 'stdout',
|
|
413
|
-
message:
|
|
408
|
+
message: remaining,
|
|
414
409
|
};
|
|
415
|
-
break;
|
|
416
410
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
const payload = buffer.slice(offset + 8, offset + 8 + size);
|
|
414
|
+
const message = payload.toString('utf-8');
|
|
415
|
+
// Parse timestamp if present (format: "2024-01-14T21:00:00.000000000Z message")
|
|
416
|
+
let timestamp;
|
|
417
|
+
let content = message;
|
|
418
|
+
if (timestamps) {
|
|
419
|
+
const match = message.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z)\s+(.*)$/s);
|
|
420
|
+
if (match) {
|
|
421
|
+
timestamp = match[1];
|
|
422
|
+
content = match[2] ?? '';
|
|
428
423
|
}
|
|
429
|
-
yield {
|
|
430
|
-
stream: streamType === 2 ? 'stderr' : 'stdout',
|
|
431
|
-
timestamp,
|
|
432
|
-
message: content.trim(),
|
|
433
|
-
};
|
|
434
|
-
offset += 8 + size;
|
|
435
424
|
}
|
|
425
|
+
yield {
|
|
426
|
+
stream: streamType === 2 ? 'stderr' : 'stdout',
|
|
427
|
+
timestamp,
|
|
428
|
+
message: content.trim(),
|
|
429
|
+
};
|
|
430
|
+
offset += 8 + size;
|
|
436
431
|
}
|
|
437
432
|
}
|
|
438
|
-
return
|
|
433
|
+
// Dockerode has different return types based on follow option:
|
|
434
|
+
// - follow: false (or undefined) returns Buffer
|
|
435
|
+
// - follow: true returns NodeJS.ReadableStream
|
|
436
|
+
// We branch explicitly so TypeScript can infer correct types
|
|
437
|
+
if (follow) {
|
|
438
|
+
const readable = await container.logs({
|
|
439
|
+
follow: true,
|
|
440
|
+
stdout,
|
|
441
|
+
stderr,
|
|
442
|
+
since: opts.since,
|
|
443
|
+
until: opts.until,
|
|
444
|
+
tail: opts.tail,
|
|
445
|
+
timestamps,
|
|
446
|
+
});
|
|
447
|
+
async function* streamIterator() {
|
|
448
|
+
for await (const chunk of readable) {
|
|
449
|
+
if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string') {
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
453
|
+
yield* parseLogBuffer(buffer);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return streamIterator();
|
|
457
|
+
}
|
|
458
|
+
// Non-follow mode: Docker returns Buffer directly
|
|
459
|
+
const buffer = await container.logs({
|
|
460
|
+
follow: false,
|
|
461
|
+
stdout,
|
|
462
|
+
stderr,
|
|
463
|
+
since: opts.since,
|
|
464
|
+
until: opts.until,
|
|
465
|
+
tail: opts.tail,
|
|
466
|
+
timestamps,
|
|
467
|
+
});
|
|
468
|
+
async function* bufferIterator() {
|
|
469
|
+
yield* parseLogBuffer(buffer);
|
|
470
|
+
}
|
|
471
|
+
return bufferIterator();
|
|
439
472
|
},
|
|
440
473
|
catch: (e) => new Error(`streamLogs failed: ${e}`),
|
|
441
474
|
}),
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export { Network } from './network';
|
|
7
7
|
export type { NetworkConfig, NetworkResource } from './network';
|
|
8
8
|
export { Container } from './container';
|
|
9
|
-
export type { ContainerConfig, ContainerResource, PortMapping, ShutdownMetadata, } from './container';
|
|
9
|
+
export type { ContainerConfig, ContainerResource, PortMapping, ShutdownMetadata, VolumeMapping, } from './container';
|
|
10
10
|
export { containerStatsSchema, execOptionsSchema, execResultSchema, logOptionsSchema, logLineSchema, cpuStatsSchema, memoryStatsSchema, networkStatsSchema, statsOptionsSchema, } from './schemas';
|
|
11
11
|
export type { ContainerStats, CpuStats, MemoryStats, NetworkStats, ExecOptions, ExecResult, LogOptions, LogLine, StatsOptions, } from './schemas';
|
|
12
12
|
export { Image } from './image';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,aAAa,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,cAAc,EACd,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,UAAU,EACV,UAAU,EACV,OAAO,EACP,YAAY,GACb,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -95,6 +95,7 @@ export declare const logOptionsSchema: z.ZodObject<{
|
|
|
95
95
|
until: z.ZodOptional<z.ZodNumber>;
|
|
96
96
|
tail: z.ZodOptional<z.ZodNumber>;
|
|
97
97
|
timestamps: z.ZodOptional<z.ZodBoolean>;
|
|
98
|
+
follow: z.ZodOptional<z.ZodBoolean>;
|
|
98
99
|
}, z.core.$strip>;
|
|
99
100
|
/**
|
|
100
101
|
* A single log line from a container
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/resources/schemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;iBA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;iBAM/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AACtD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAI9D;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;iBAO5B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;iBAK3B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAI1D;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;iBAQ3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;iBAIxB,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC1D,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAIpD;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;iBAG7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -76,6 +76,7 @@ export const logOptionsSchema = z.object({
|
|
|
76
76
|
until: z.number().optional().describe('Unix timestamp to end at'),
|
|
77
77
|
tail: z.number().int().min(0).optional().describe('Number of lines to tail'),
|
|
78
78
|
timestamps: z.boolean().optional().describe('Include timestamps (default: false)'),
|
|
79
|
+
follow: z.boolean().optional().describe('Follow log output (default: false)'),
|
|
79
80
|
});
|
|
80
81
|
/**
|
|
81
82
|
* A single log line from a container
|