@tahminator/pipeline 1.0.59-beta.2d7a142f → 1.0.59
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/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +1 -1
- package/dist/postgres/client.d.ts +0 -11
- package/dist/postgres/client.js +0 -75
- package/dist/postgres/index.d.ts +0 -2
- package/dist/postgres/index.js +0 -2
- package/dist/postgres/types.d.ts +0 -10
- package/dist/postgres/types.js +0 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"author": "Tahmid Ahmed",
|
|
5
5
|
"description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
|
|
6
|
-
"version": "1.0.59
|
|
6
|
+
"version": "1.0.59",
|
|
7
7
|
"repository": {
|
|
8
8
|
"url": "git+https://github.com/tahminator/pipeline.git"
|
|
9
9
|
},
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PostgresInternalState, PostgresState } from "./types";
|
|
2
|
-
export declare class LocalPostgresClient {
|
|
3
|
-
private readonly iState;
|
|
4
|
-
private constructor();
|
|
5
|
-
static create(state: PostgresState): Promise<LocalPostgresClient>;
|
|
6
|
-
private static launch;
|
|
7
|
-
private static waitUntilReady;
|
|
8
|
-
get state(): PostgresInternalState;
|
|
9
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
10
|
-
cleanup(): Promise<void>;
|
|
11
|
-
}
|
package/dist/postgres/client.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { $, randomUUIDv7 } from "bun";
|
|
2
|
-
import { Utils } from "../utils";
|
|
3
|
-
export class LocalPostgresClient {
|
|
4
|
-
iState;
|
|
5
|
-
constructor(iState) {
|
|
6
|
-
this.iState = iState;
|
|
7
|
-
}
|
|
8
|
-
static async create(state) {
|
|
9
|
-
const iState = {
|
|
10
|
-
...state,
|
|
11
|
-
user: "postgres",
|
|
12
|
-
password: "postgres",
|
|
13
|
-
port: 5432,
|
|
14
|
-
host: "127.0.0.1",
|
|
15
|
-
dockerName: `local-db-${randomUUIDv7()}`,
|
|
16
|
-
};
|
|
17
|
-
const hostPort = await this.launch(iState);
|
|
18
|
-
iState.port = hostPort;
|
|
19
|
-
await this.waitUntilReady(iState);
|
|
20
|
-
return new this(iState);
|
|
21
|
-
}
|
|
22
|
-
static async launch(iState) {
|
|
23
|
-
await $ `docker run -d \
|
|
24
|
-
--name ${iState.dockerName} \
|
|
25
|
-
-e POSTGRES_USER=${iState.user} \
|
|
26
|
-
-e POSTGRES_PASSWORD=${iState.password} \
|
|
27
|
-
-e POSTGRES_DB=${iState.database} \
|
|
28
|
-
-p 5432 \
|
|
29
|
-
mirror.gcr.io/library/postgres:16-alpine`;
|
|
30
|
-
const raw = (await $ `docker port ${iState.dockerName} 5432/tcp`.text()).trim();
|
|
31
|
-
const match = raw.match(/:(\d+)/);
|
|
32
|
-
if (!match) {
|
|
33
|
-
throw new Error(`Could not parse host port from: ${raw}`);
|
|
34
|
-
}
|
|
35
|
-
return Number(match[1]);
|
|
36
|
-
}
|
|
37
|
-
static async waitUntilReady(iState) {
|
|
38
|
-
console.log(`Waiting for ${iState.dockerName} to become ready.`);
|
|
39
|
-
const attempts = 30;
|
|
40
|
-
for (let i = 1; i <= attempts; i++) {
|
|
41
|
-
const check = await $ `docker exec ${iState.dockerName} pg_isready -U ${iState.user}`
|
|
42
|
-
.quiet()
|
|
43
|
-
.nothrow();
|
|
44
|
-
if (check.exitCode === 0) {
|
|
45
|
-
console.log(`${iState.dockerName} is ready`);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
console.log(`Waiting for ${iState.dockerName}... (${i}/${attempts})`);
|
|
49
|
-
await Bun.sleep(2000);
|
|
50
|
-
}
|
|
51
|
-
const msg = `${iState.dockerName} failed to launch`;
|
|
52
|
-
console.error(msg);
|
|
53
|
-
throw new Error(msg);
|
|
54
|
-
}
|
|
55
|
-
get state() {
|
|
56
|
-
return this.iState;
|
|
57
|
-
}
|
|
58
|
-
async [Symbol.asyncDispose]() {
|
|
59
|
-
await this.cleanup();
|
|
60
|
-
}
|
|
61
|
-
async cleanup() {
|
|
62
|
-
console.log(`Stopping and removing ${this.iState.dockerName} container...`);
|
|
63
|
-
if (Utils.Log.isDebug) {
|
|
64
|
-
console.log(Utils.Colors.brightMagenta("=== DB LOGS ==="));
|
|
65
|
-
const logs = await $ `docker logs ${this.iState.dockerName}`.text();
|
|
66
|
-
logs
|
|
67
|
-
.split("\n")
|
|
68
|
-
.filter((s) => s.length > 0)
|
|
69
|
-
.forEach((line) => console.log(Utils.Colors.brightMagenta(line)));
|
|
70
|
-
console.log(Utils.Colors.brightMagenta("=== DB LOGS END ==="));
|
|
71
|
-
}
|
|
72
|
-
await $ `docker stop ${this.iState.dockerName}`.quiet().nothrow();
|
|
73
|
-
await $ `docker rm ${this.iState.dockerName}`.quiet().nothrow();
|
|
74
|
-
}
|
|
75
|
-
}
|
package/dist/postgres/index.d.ts
DELETED
package/dist/postgres/index.js
DELETED
package/dist/postgres/types.d.ts
DELETED
package/dist/postgres/types.js
DELETED
|
File without changes
|