@kunk/docker 3.0.4 → 3.0.5
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/package.json +11 -1
- package/.turbo/turbo-build.log +0 -12
- package/.turbo/turbo-deploy.log +0 -0
- package/.turbo/turbo-version$colon$patch.log +0 -4
- package/CHANGELOG.md +0 -15
- package/src/containers/PostgresContainer.ts +0 -98
- package/src/containers/_utils.ts +0 -27
- package/src/index.ts +0 -1
- package/tsconfig.json +0 -16
- package/tsdown.config.ts +0 -14
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kunk/docker",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
7
7
|
"module": "./src/index.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
8
11
|
"scripts": {
|
|
9
12
|
"build": "tsdown",
|
|
10
13
|
"version:patch": "bun pm version patch",
|
|
@@ -19,6 +22,13 @@
|
|
|
19
22
|
"testcontainers": "^11.12.0",
|
|
20
23
|
"dockerode": "4.0.9"
|
|
21
24
|
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
22
32
|
"publishConfig": {
|
|
23
33
|
"access": "public"
|
|
24
34
|
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
[0m[2m[35m$[0m [2m[1mtsdown[0m
|
|
3
|
-
[34mℹ[39m tsdown [2mv0.20.3[22m powered by rolldown [2mv1.0.0-rc.3[22m
|
|
4
|
-
[34mℹ[39m config file: [4m/Users/ag/auxo/kunk/packages/docker/tsdown.config.ts[24m
|
|
5
|
-
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
6
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
7
|
-
[34mℹ[39m Build start
|
|
8
|
-
[34mℹ[39m Cleaning 2 files
|
|
9
|
-
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m1.93 kB[22m [2m│ gzip: 0.94 kB[22m
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m0.44 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
11
|
-
[34mℹ[39m 2 files, total: 2.38 kB
|
|
12
|
-
[32m✔[39m Build complete in [32m1359ms[39m
|
package/.turbo/turbo-deploy.log
DELETED
|
File without changes
|
package/CHANGELOG.md
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { type StartedTestContainer } from "testcontainers"
|
|
2
|
-
import { PostgreSqlContainer } from "@testcontainers/postgresql"
|
|
3
|
-
import { Wait } from "testcontainers"
|
|
4
|
-
import { migrate } from "@kunk/database"
|
|
5
|
-
import { DatabaseConfig } from "@kunk/server"
|
|
6
|
-
import { dockerExec } from "./_utils"
|
|
7
|
-
|
|
8
|
-
export class PostgresContainer {
|
|
9
|
-
|
|
10
|
-
private container: StartedTestContainer | null = null
|
|
11
|
-
static CLEAR_TEST_DATA: () => Promise<void>
|
|
12
|
-
|
|
13
|
-
static async start(options: { hostname?: string, port?: string | number, username?: string, password?: string, database?: string } = {}) {
|
|
14
|
-
const pg = new PostgresContainer()
|
|
15
|
-
await pg.start(options)
|
|
16
|
-
return pg
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private async start(options: { hostname?: string, port?: string | number, username?: string, password?: string, database?: string }) {
|
|
20
|
-
|
|
21
|
-
const root_username = options.username ?? "kunk"
|
|
22
|
-
const root_password = options.password ?? "kunk"
|
|
23
|
-
const root_database = options.database ?? "kunk"
|
|
24
|
-
|
|
25
|
-
const logging = Boolean(process.env['LOGGING'])
|
|
26
|
-
let container = new PostgreSqlContainer("postgres:18")
|
|
27
|
-
.withWaitStrategy(Wait.forLogMessage("database system is ready to accept connections", 1) as any)
|
|
28
|
-
.withName(`postgres-${root_database}`)
|
|
29
|
-
.withDatabase(root_database)
|
|
30
|
-
.withUsername(root_username)
|
|
31
|
-
.withPassword(root_password)
|
|
32
|
-
.withResourcesQuota({
|
|
33
|
-
memory: 0.5,
|
|
34
|
-
cpu: 1
|
|
35
|
-
})
|
|
36
|
-
.withLogConsumer((stream) => {
|
|
37
|
-
stream.on("data", (chunk) => {
|
|
38
|
-
if (!logging) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
console.debug("PostgreSQL: ", chunk.toString());
|
|
42
|
-
});
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (options.port) {
|
|
47
|
-
container = container.withReuse()
|
|
48
|
-
.withExposedPorts({
|
|
49
|
-
container: 5432,
|
|
50
|
-
host: Number(options.port),
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.container = await container.start()
|
|
55
|
-
|
|
56
|
-
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
57
|
-
|
|
58
|
-
await migrate({
|
|
59
|
-
adapter: 'postgres',
|
|
60
|
-
hostname: this.container.getHost(),
|
|
61
|
-
port: this.container.getMappedPort(5432),
|
|
62
|
-
username: root_username,
|
|
63
|
-
password: root_password,
|
|
64
|
-
database: root_database,
|
|
65
|
-
max: 1
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
DatabaseConfig.set({
|
|
70
|
-
uri: `postgresql://app_user:${root_password}@${this.container.getHost()}:${this.container.getMappedPort(5432)}/${root_database}`,
|
|
71
|
-
maxPoolSize: 3,
|
|
72
|
-
idleTimeout: 5,
|
|
73
|
-
connectionTimeout: 30,
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
console.log("DATABASE CONFIG FINISHED")
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async stop() {
|
|
80
|
-
await this.container?.stop()
|
|
81
|
-
this.container = null
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async clear() {
|
|
85
|
-
if (this.container) {
|
|
86
|
-
await dockerExec(this.container, [
|
|
87
|
-
"psql",
|
|
88
|
-
"--username", "kunk",
|
|
89
|
-
"--password", "kunk",
|
|
90
|
-
"--host", this.container.getHost(),
|
|
91
|
-
"--port", this.container.getMappedPort(5432).toString(),
|
|
92
|
-
"--database", "kunk",
|
|
93
|
-
"--command", "DROP DATABASE kunk"
|
|
94
|
-
])
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}
|
package/src/containers/_utils.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { StartedTestContainer } from "testcontainers";
|
|
2
|
-
|
|
3
|
-
export async function dockerExec(container: StartedTestContainer, command: string[]) {
|
|
4
|
-
const Dockerode = await import("dockerode").then(module => module.default)
|
|
5
|
-
const docker = new Dockerode();
|
|
6
|
-
try {
|
|
7
|
-
const exec = await docker.getContainer(container.getId() ?? "").exec({
|
|
8
|
-
Cmd: command,
|
|
9
|
-
AttachStdout: true,
|
|
10
|
-
AttachStderr: true,
|
|
11
|
-
});
|
|
12
|
-
const stream = await exec.start({
|
|
13
|
-
abortSignal: AbortSignal.timeout(2000),
|
|
14
|
-
});
|
|
15
|
-
let output = "";
|
|
16
|
-
|
|
17
|
-
stream.on("data", (chunk) => {
|
|
18
|
-
output += chunk.toString();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
await new Promise((resolve) => stream.on("end", resolve));
|
|
22
|
-
|
|
23
|
-
console.log("Output:", output);
|
|
24
|
-
} catch (error) {
|
|
25
|
-
debugger
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./containers/PostgresContainer"
|
package/tsconfig.json
DELETED