@tahminator/pipeline 1.0.59-beta.2d7a142f → 1.0.59-beta.5f3d9514

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