@tahminator/pipeline 1.0.59-beta.2d7a142f → 1.0.59-beta.4cc29c8c

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 CHANGED
@@ -6,5 +6,6 @@ export * from "./pulumi";
6
6
  export * from "./types";
7
7
  export * from "./env";
8
8
  export * from "./postgres";
9
+ export * from "./redis";
9
10
  export * from "./utils";
10
11
  export * from "./versioning";
package/dist/index.js CHANGED
@@ -6,5 +6,6 @@ export * from "./pulumi";
6
6
  export * from "./types";
7
7
  export * from "./env";
8
8
  export * from "./postgres";
9
+ export * from "./redis";
9
10
  export * from "./utils";
10
11
  export * from "./versioning";
@@ -0,0 +1,11 @@
1
+ import type { RedisInternalState, RedisState } from "./types";
2
+ export declare class LocalRedisClient {
3
+ private readonly iState;
4
+ private constructor();
5
+ static create(state?: RedisState): Promise<LocalRedisClient>;
6
+ private static launch;
7
+ private static waitUntilReady;
8
+ get state(): RedisInternalState;
9
+ [Symbol.asyncDispose](): Promise<void>;
10
+ cleanup(): Promise<void>;
11
+ }
@@ -0,0 +1,72 @@
1
+ import { $, randomUUIDv7 } from "bun";
2
+ import { Utils } from "../utils";
3
+ export class LocalRedisClient {
4
+ iState;
5
+ constructor(iState) {
6
+ this.iState = iState;
7
+ }
8
+ static async create(state = {}) {
9
+ const iState = {
10
+ ...state,
11
+ password: "redis",
12
+ port: 6379,
13
+ host: "127.0.0.1",
14
+ dockerName: `local-redis-${randomUUIDv7()}`,
15
+ };
16
+ const hostPort = await this.launch(iState);
17
+ iState.port = hostPort;
18
+ await this.waitUntilReady(iState);
19
+ return new this(iState);
20
+ }
21
+ static async launch(iState) {
22
+ await $ `docker run -d \
23
+ --name ${iState.dockerName} \
24
+ -p 6379 \
25
+ mirror.gcr.io/library/redis:7-alpine \
26
+ redis-server --requirepass ${iState.password}`;
27
+ const raw = (await $ `docker port ${iState.dockerName} 6379/tcp`.text()).trim();
28
+ const match = raw.match(/:(\d+)/);
29
+ if (!match) {
30
+ throw new Error(`Could not parse host port from: ${raw}`);
31
+ }
32
+ return Number(match[1]);
33
+ }
34
+ static async waitUntilReady(iState) {
35
+ console.log(`Waiting for ${iState.dockerName} to become ready.`);
36
+ const attempts = 30;
37
+ for (let i = 1; i <= attempts; i++) {
38
+ const check = await $ `docker exec ${iState.dockerName} redis-cli -a ${iState.password} ping`
39
+ .quiet()
40
+ .nothrow();
41
+ if (check.exitCode === 0) {
42
+ console.log(`${iState.dockerName} is ready`);
43
+ return;
44
+ }
45
+ console.log(`Waiting for ${iState.dockerName}... (${i}/${attempts})`);
46
+ await Bun.sleep(2000);
47
+ }
48
+ const msg = `${iState.dockerName} failed to launch`;
49
+ console.error(msg);
50
+ throw new Error(msg);
51
+ }
52
+ get state() {
53
+ return this.iState;
54
+ }
55
+ async [Symbol.asyncDispose]() {
56
+ await this.cleanup();
57
+ }
58
+ async cleanup() {
59
+ console.log(`Stopping and removing ${this.iState.dockerName} container...`);
60
+ if (Utils.Log.isDebug) {
61
+ console.log(Utils.Colors.brightMagenta("=== REDIS LOGS ==="));
62
+ const logs = await $ `docker logs ${this.iState.dockerName}`.text();
63
+ logs
64
+ .split("\n")
65
+ .filter((s) => s.length > 0)
66
+ .forEach((line) => console.log(Utils.Colors.brightMagenta(line)));
67
+ console.log(Utils.Colors.brightMagenta("=== REDIS LOGS END ==="));
68
+ }
69
+ await $ `docker stop ${this.iState.dockerName}`.quiet().nothrow();
70
+ await $ `docker rm ${this.iState.dockerName}`.quiet().nothrow();
71
+ }
72
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./client";
2
+ export * from "./types";
@@ -0,0 +1,2 @@
1
+ export * from "./client";
2
+ export * from "./types";
@@ -0,0 +1,8 @@
1
+ export interface RedisState {
2
+ }
3
+ export interface RedisInternalState extends RedisState {
4
+ port: number;
5
+ host: string;
6
+ password: string;
7
+ dockerName: string;
8
+ }
File without changes
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-beta.2d7a142f",
6
+ "version": "1.0.59-beta.4cc29c8c",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },