forked from docker/node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.test.ts
More file actions
54 lines (49 loc) · 1.91 KB
/
Copy pathbuild.test.ts
File metadata and controls
54 lines (49 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { expect, test } from 'vitest';
import { DockerClient } from '../lib/docker-client.js';
import { pack as createTarPack } from 'tar-stream';
import { Readable } from 'node:stream';
test('imageBuild: build image from Dockerfile with tar-stream context', async () => {
const client = await DockerClient.fromDockerConfig();
const testImageName = 'test-build-image';
const testTag = 'latest';
try {
const pack = createTarPack();
pack.entry(
{ name: 'Dockerfile' },
`FROM scratch
COPY test.txt /test.txt
`,
);
pack.entry({ name: 'test.txt' }, 'Hello from Docker build test!');
pack.finalize();
const builtImage = await client
.imageBuild(
Readable.toWeb(pack, { strategy: { highWaterMark: 16384 } }),
{
tag: `${testImageName}:${testTag}`,
rm: true,
forcerm: true,
},
)
.wait();
// Inspect the built builtImage to confirm it was created successfully
console.log(` Inspecting built image ${builtImage}`);
const imageInspect = await client.imageInspect(builtImage || '');
console.log(' Image found! Build was successful.');
expect(imageInspect.RepoTags).toContain(`${testImageName}:${testTag}`);
console.log(` Image size: ${imageInspect.Size} bytes`);
} finally {
// Clean up: delete the test image
console.log(' Cleaning up test image...');
try {
await client.imageDelete(`${testImageName}:${testTag}`, {
force: true,
});
console.log(' Test image deleted successfully');
} catch (cleanupError) {
console.log(
` Warning: Failed to delete test image: ${(cleanupError as any)?.message}`,
);
}
}
}, 60000); // 60 second timeout