Skip to content

Commit f5c72df

Browse files
committed
0.6.0 - publish postgres-ws-proxy container, use it in e2e test
1 parent 63c6ce5 commit f5c72df

22 files changed

Lines changed: 575 additions & 142 deletions

.github/workflows/build-test-and-publish.yml

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,77 @@ on:
55
branches:
66
- main
77

8-
permissions:
9-
packages: write
10-
id-token: write # Required for OIDC
11-
128
env:
139
BUN_VERSION: 1.3.3
10+
POSTGRES_VERSION: 17.7
11+
NODE_VERSION: 24
1412

1513
jobs:
16-
build-test-and-publish:
17-
name: "Build, test, & publish package"
14+
E2E-Tests:
15+
name: "Run E2E integration test(s)"
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
- name: Run E2E Tests with Docker Compose
21+
working-directory: tests
22+
run: |
23+
/bin/bash ./run_e2e_tests.sh
24+
25+
Unit-Tests:
26+
name: "Run unit test(s)"
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
- name: Setup Bun
32+
uses: oven-sh/setup-bun@v2
33+
with:
34+
bun-version: ${{ env.BUN_VERSION }}
35+
- name: Install dependencies with Bun
36+
run: bun install
37+
- name: Run Unit Tests with Bun
38+
run: bun run test:unit
39+
40+
Build-Package:
41+
name: "Compile package"
42+
runs-on: ubuntu-latest
43+
needs:
44+
- Unit-Tests
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
- name: Setup Bun
49+
uses: oven-sh/setup-bun@v2
50+
with:
51+
bun-version: ${{ env.BUN_VERSION }}
52+
- name: Install dependencies with Bun
53+
run: bun install
54+
- name: Build package with Bun
55+
run: bun run build
56+
- name: Pack up package with Bun
57+
run: bun pm pack --quiet --filename schemavaults-dbh.tgz
58+
- name: Upload package artifact
59+
uses: actions/upload-artifact@v6
60+
with:
61+
name: package-tarball
62+
path: schemavaults-dbh.tgz
63+
retention-days: 3
64+
65+
Publish-To-Github-Packages:
66+
name: "Publish package to GitHub Packages"
1867
runs-on: ubuntu-latest
68+
needs:
69+
- Build-Package
70+
- E2E-Tests
71+
permissions:
72+
packages: write
1973
steps:
74+
- name: Download package artifact
75+
uses: actions/download-artifact@v7
76+
with:
77+
name: package-tarball
78+
path: schemavaults-dbh.tgz
2079
- name: Checkout
2180
uses: actions/checkout@v4
2281
- name: Setup Bun
@@ -38,12 +97,49 @@ jobs:
3897
SCHEMAVAULTS_GITHUB_PACKAGE_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3998
- name: Delete .npmrc for GitHub NPM registry
4099
run: rm -rf .npmrc
100+
101+
Publish-To-NPMJS-Packages:
102+
name: "Publish package to NPMJS registry"
103+
needs:
104+
- Build-Package
105+
- E2E-Tests
106+
runs-on: ubuntu-latest
107+
permissions:
108+
id-token: write # Required for OIDC
109+
steps:
110+
- name: Download package artifact
111+
uses: actions/download-artifact@v7
112+
with:
113+
name: package-tarball
114+
path: schemavaults-dbh.tgz
115+
- uses: actions/setup-node@v5
116+
with:
117+
node-version: "24"
118+
registry-url: "https://registry.npmjs.org"
41119
- name: Configure .npmrc to publish to NPMJS registry
42120
run: cp .npmrc.npmjs .npmrc
43121
- name: Publish package to NPMJS registry
44-
run: bun publish --registry=https://registry.npmjs.org --access public
45-
env:
46-
NPM_PACKAGE_PUBLISH_USER: ${{ github.actor }}
47-
NPM_PACKAGE_PUBLISH_TOKEN: ${{ secrets.NPM_PACKAGE_PUBLISH_TOKEN }}
122+
run: npm publish ./schemavaults-dbh.tgz --provenance
48123
- name: Delete .npmrc for NPMJS registry
49124
run: rm -rf .npmrc
125+
126+
Publish-Websocket-Proxy-To-GHCR:
127+
needs:
128+
- E2E-Tests
129+
runs-on: ubuntu-latest
130+
steps:
131+
- name: Log in to GitHub Container Registry
132+
run: |
133+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
134+
- name: Set up QEMU
135+
uses: docker/setup-qemu-action@v3
136+
- name: Set up Docker Buildx
137+
uses: docker/setup-buildx-action@v3
138+
- name: Build and push Docker Image
139+
uses: docker/build-push-action@v6
140+
with:
141+
context: .
142+
file: postgres-ws-proxy/Dockerfile
143+
push: true
144+
tags: |
145+
ghcr.io/schemavaults/postgres-ws-proxy:latest

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ node_modules/
99
.env.staging
1010
.env.local
1111
.env.production
12+
13+
schemavaults-dbh-*.tgz
14+
schemavaults-dbh.tgz

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ dist/**/*.test.d.ts
1515
dist/**/*.test.js.map
1616
dist/**/*.test.js
1717

18+
dist/tests/
19+
1820

1921
.github/
2022

@@ -25,3 +27,14 @@ tsconfig.json
2527
.npmrc.github
2628
.npmrc.npmjs
2729
.npmrc
30+
31+
scripts/
32+
33+
tests/
34+
postgres/
35+
postgres-data/
36+
postgres-ws-proxy/
37+
38+
schemavaults-dbh.tgz
39+
40+
.zed/

.zed/tasks.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"label": "Kill Docker Desktop",
4+
"command": "sudo ./scripts/kill_docker_desktop.sh",
5+
//"args": [],
6+
// Env overrides for the command, will be appended to the terminal's environment from the settings.
7+
// "env": { "foo": "bar" },
8+
// Current working directory to spawn the command into, defaults to current project root.
9+
//"cwd": "/path/to/working/directory",
10+
// Whether to use a new terminal tab or reuse the existing one to spawn the process, defaults to `false`.
11+
"use_new_terminal": false,
12+
// Whether to allow multiple instances of the same task to be run, or rather wait for the existing ones to finish, defaults to `false`.
13+
"allow_concurrent_runs": false,
14+
// What to do with the terminal pane and tab, after the command was started:
15+
// * `always` — always show the task's pane, and focus the corresponding tab in it (default)
16+
// * `no_focus` — always show the task's pane, add the task's tab in it, but don't focus it
17+
// * `never` — do not alter focus, but still add/reuse the task's tab in its pane
18+
"reveal": "always",
19+
// What to do with the terminal pane and tab, after the command has finished:
20+
// * `never` — Do nothing when the command finishes (default)
21+
// * `always` — always hide the terminal tab, hide the pane also if it was the last tab in it
22+
// * `on_success` — hide the terminal tab on task success only, otherwise behaves similar to `always`
23+
"hide": "never",
24+
"shell": "system",
25+
// Whether to show the task line in the output of the spawned task, defaults to `true`.
26+
"show_summary": true,
27+
// Whether to show the command line in the output of the spawned task, defaults to `true`.
28+
"show_command": true,
29+
// Represents the tags for inline runnable indicators, or spawning multiple tasks at once.
30+
"tags": ["docker"]
31+
},
32+
{
33+
"label": "Launch E2E Test Pipeline",
34+
"command": "cd tests && ./run_e2e_tests.sh",
35+
//"args": [],
36+
// Env overrides for the command, will be appended to the terminal's environment from the settings.
37+
// "env": { "foo": "bar" },
38+
// Current working directory to spawn the command into, defaults to current project root.
39+
//"cwd": "/path/to/working/directory",
40+
// Whether to use a new terminal tab or reuse the existing one to spawn the process, defaults to `false`.
41+
"use_new_terminal": false,
42+
// Whether to allow multiple instances of the same task to be run, or rather wait for the existing ones to finish, defaults to `false`.
43+
"allow_concurrent_runs": false,
44+
// What to do with the terminal pane and tab, after the command was started:
45+
// * `always` — always show the task's pane, and focus the corresponding tab in it (default)
46+
// * `no_focus` — always show the task's pane, add the task's tab in it, but don't focus it
47+
// * `never` — do not alter focus, but still add/reuse the task's tab in its pane
48+
"reveal": "always",
49+
// What to do with the terminal pane and tab, after the command has finished:
50+
// * `never` — Do nothing when the command finishes (default)
51+
// * `always` — always hide the terminal tab, hide the pane also if it was the last tab in it
52+
// * `on_success` — hide the terminal tab on task success only, otherwise behaves similar to `always`
53+
"hide": "never",
54+
"shell": "system",
55+
// Whether to show the task line in the output of the spawned task, defaults to `true`.
56+
"show_summary": true,
57+
// Whether to show the command line in the output of the spawned task, defaults to `true`.
58+
"show_command": true,
59+
// Represents the tags for inline runnable indicators, or spawning multiple tasks at once.
60+
"tags": ["docker", "e2e", "tests"]
61+
}
62+
]

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@schemavaults/dbh",
3-
"version": "0.5.6",
3+
"version": "0.6.0",
44
"description": "Easily connect to PostgresDB from serverless environment",
55
"license": "UNLICENSED",
66
"private": false,
@@ -20,9 +20,11 @@
2020
},
2121
"scripts": {
2222
"build": "tsc --project tsconfig.json && tsc-alias --project tsconfig.json",
23-
"test": "bun test",
24-
"test:watch": "bun test --watch",
23+
"test:unit": "bun test --test-name-pattern 'DBH Init'",
24+
"test": "bun run test:unit",
25+
"test:e2e": "bun test ./src/tests/e2e/ConnectToLocalDatabase.test.ts",
2526
"cleanup:compiled_tests_in_dist_directory": "find ./dist -type f \\( -name \"*.test.js\" -o -name \"*.test.js.map\" -o -name \"*.test.d.ts\" \\) -delete",
27+
"cleanup:rm_tests_dir": "rm -rf ./dist/tests",
2628
"cleanup": "bun run cleanup:compiled_tests_in_dist_directory",
2729
"postbuild": "bun run cleanup"
2830
},

postgres-ws-proxy/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM ghcr.io/neondatabase/wsproxy:latest

postgres/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ARG POSTGRES_VERSION
2+
FROM postgres:${POSTGRES_VERSION}

scripts/kill_docker_desktop.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Function to kill Docker processes
4+
kill_docker_processes() {
5+
# Find all Docker processes
6+
docker_pids=$(pgrep -f "docker")
7+
8+
# Find all processes named "Docker Desktop"
9+
docker_desktop_pids=$(pgrep -f "Docker Desktop")
10+
11+
# Combine Docker and Docker Desktop process IDs
12+
docker_pids="$docker_pids $docker_desktop_pids"
13+
14+
# Check if any Docker processes were found
15+
if [ -z "$docker_pids" ]; then
16+
echo "No Docker processes found."
17+
return
18+
else
19+
echo "Found $(echo $docker_pids | wc -w) Docker processes to terminate."
20+
for pid in $docker_pids; do
21+
echo "Docker process to kill: PID $pid"
22+
done
23+
fi
24+
25+
# Kill each Docker process
26+
for pid in $docker_pids; do
27+
echo "Killing Docker process with PID: $pid"
28+
kill -9 $pid
29+
done
30+
31+
echo "All Docker processes have been terminated."
32+
}
33+
34+
# Run the function
35+
kill_docker_processes

src/DbhInit.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { describe, expect, test } from "bun:test";
2-
import { SchemaVaultsPostgresNeonProxyAdapter }
3-
from './schemavaults-postgres-neon-proxy-adapter'
2+
import SchemaVaultsPostgresNeonProxyAdapter from "@/schemavaults-postgres-neon-proxy-adapter";
43

54
describe("DBH Init", () => {
65
test("should export the SchemaVaultsPostgresNeonProxyAdapter", () => {
76
expect(SchemaVaultsPostgresNeonProxyAdapter).toBeDefined();
87
});
9-
8+
109
test("should initialize a dbh instance without an error", () => {
1110
const dbh = new SchemaVaultsPostgresNeonProxyAdapter({
12-
environment: 'test',
11+
environment: "test",
1312
credentials: {
14-
POSTGRES_DATABASE: 'test_db',
15-
POSTGRES_HOST: 'localhost',
16-
POSTGRES_PASSWORD: 'test_password',
13+
POSTGRES_DATABASE: "test_db",
14+
POSTGRES_HOST: "localhost",
15+
POSTGRES_PASSWORD: "test_password",
1716
POSTGRES_PORT: 5432,
18-
POSTGRES_URL: 'postgresql://test_user:test_password@localhost:5432/test_db',
19-
POSTGRES_USER: 'test_user',
20-
}
21-
})
17+
POSTGRES_URL:
18+
"postgresql://test_user:test_password@localhost:5432/test_db",
19+
POSTGRES_USER: "test_user",
20+
},
21+
});
22+
23+
void dbh;
2224
});
23-
})
25+
});

src/PostgresDatabaseCredentials.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
declare global {
32
namespace NodeJS {
43
interface ProcessEnv {
@@ -19,6 +18,14 @@ export interface PostgresDatabaseCredentials {
1918
POSTGRES_URL: string;
2019
POSTGRES_URL_NON_POOLING?: string;
2120
POSTGRES_HOST: string;
22-
POSTGRES_PORT: number;
21+
POSTGRES_PORT: number | string;
22+
POSTGRES_DATABASE: string;
23+
}
24+
25+
export interface BaseInitializablePostgresDatabaseCredentials
26+
extends Partial<PostgresDatabaseCredentials> {
27+
POSTGRES_HOST: string;
2328
POSTGRES_DATABASE: string;
24-
}
29+
POSTGRES_USER: string;
30+
POSTGRES_PASSWORD: string;
31+
}

0 commit comments

Comments
 (0)