Skip to content

Commit 5ee9fee

Browse files
committed
add pgvector bundled
1 parent df0aeaa commit 5ee9fee

File tree

10 files changed

+116
-197
lines changed

10 files changed

+116
-197
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ jobs:
1717
uses: dtolnay/rust-toolchain@stable
1818

1919
- name: Build
20-
env:
21-
BUNDLE_POSTGRESQL: "true"
2220
run: cargo build --release
2321

2422
- name: Upload CLI artifact

.github/workflows/release-cli.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ jobs:
7676
echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
7777
7878
- name: Build
79-
env:
80-
BUNDLE_POSTGRESQL: "true"
8179
run: cargo build --release --target ${{ matrix.target }}
8280

8381
- name: Prepare artifact (Unix)
@@ -146,9 +144,9 @@ jobs:
146144
echo "- \`pg0-windows-x86_64.exe\` - Windows x64" >> release_notes.md
147145
echo "" >> release_notes.md
148146
echo "### Bundled Components" >> release_notes.md
149-
echo "PostgreSQL is bundled directly in the binary - no downloads required on first run!" >> release_notes.md
147+
echo "Everything is bundled directly in the binary - no downloads required, works completely offline!" >> release_notes.md
150148
echo "- PostgreSQL ${PG_VERSION}" >> release_notes.md
151-
echo "- pgvector ${PGVECTOR_VERSION} (downloaded on first run)" >> release_notes.md
149+
echo "- pgvector ${PGVECTOR_VERSION}" >> release_notes.md
152150
echo "" >> release_notes.md
153151
echo "### Installation (macOS/Linux)" >> release_notes.md
154152
echo "\`\`\`bash" >> release_notes.md

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,7 @@ pg0 start -c shared_buffers=1GB -c maintenance_work_mem=2GB
396396

397397
## How It Works
398398

399-
PostgreSQL is **bundled directly** into the pg0 binary - no downloads required on first run! On first start, pg0 extracts PostgreSQL to `~/.pg0/installation/` and initializes the database.
400-
401-
pgvector is downloaded on first run from pre-compiled binaries and cached in the installation directory.
399+
PostgreSQL and pgvector are **bundled directly** into the pg0 binary - no downloads required, works completely offline! On first start, pg0 extracts PostgreSQL and pgvector to `~/.pg0/installation/` and initializes the database.
402400

403401
Data is stored in `~/.pg0/instances/<name>/data/` (or your custom `--data-dir`) and persists between restarts.
404402

build.rs

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::path::PathBuf;
55

66
fn main() {
77
println!("cargo:rerun-if-changed=versions.env");
8-
println!("cargo:rerun-if-env-changed=BUNDLE_POSTGRESQL");
98

109
// Load versions from versions.env
1110
let versions_env = fs::read_to_string("versions.env").expect("Failed to read versions.env");
@@ -35,27 +34,11 @@ fn main() {
3534
println!("cargo:rustc-env=PGVECTOR_COMPILED_TAG={}", pgvector_tag);
3635
println!("cargo:rustc-env=PGVECTOR_COMPILED_REPO={}", pgvector_repo);
3736

38-
// Check if we should bundle PostgreSQL
39-
let bundle = env::var("BUNDLE_POSTGRESQL")
40-
.map(|v| v == "1" || v == "true")
41-
.unwrap_or(false);
42-
4337
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
4438

45-
if bundle {
46-
bundle_postgresql(&pg_version, &out_dir);
47-
} else {
48-
// Create an empty marker file so include_bytes! doesn't fail
49-
let marker = out_dir.join("postgresql_bundle.tar.gz");
50-
if !marker.exists() {
51-
fs::write(&marker, b"").expect("Failed to create empty bundle marker");
52-
}
53-
println!(
54-
"cargo:rustc-env=POSTGRESQL_BUNDLE_PATH={}",
55-
marker.display()
56-
);
57-
println!("cargo:rustc-env=POSTGRESQL_BUNDLED=false");
58-
}
39+
// Bundle PostgreSQL and pgvector
40+
bundle_postgresql(&pg_version, &out_dir);
41+
bundle_pgvector(&pg_version, &pgvector_tag, &pgvector_repo, &out_dir);
5942
}
6043

6144
fn bundle_postgresql(pg_version: &str, out_dir: &PathBuf) {
@@ -115,7 +98,71 @@ fn bundle_postgresql(pg_version: &str, out_dir: &PathBuf) {
11598
"cargo:rustc-env=POSTGRESQL_BUNDLE_PATH={}",
11699
bundle_path.display()
117100
);
118-
println!("cargo:rustc-env=POSTGRESQL_BUNDLED=true");
101+
}
102+
103+
fn bundle_pgvector(pg_version: &str, pgvector_tag: &str, pgvector_repo: &str, out_dir: &PathBuf) {
104+
let target = env::var("TARGET").unwrap();
105+
106+
// Map Rust target to pgvector platform name
107+
let pgvector_platform = match target.as_str() {
108+
"aarch64-apple-darwin" => "aarch64-apple-darwin",
109+
"x86_64-apple-darwin" => "x86_64-apple-darwin",
110+
"x86_64-unknown-linux-gnu" => "x86_64-unknown-linux-gnu",
111+
"x86_64-unknown-linux-musl" => "x86_64-unknown-linux-gnu", // musl uses gnu pgvector
112+
"aarch64-unknown-linux-gnu" => "aarch64-unknown-linux-gnu",
113+
"aarch64-unknown-linux-musl" => "aarch64-unknown-linux-gnu", // musl uses gnu pgvector
114+
"x86_64-pc-windows-msvc" => {
115+
eprintln!("Warning: pgvector not available for Windows, skipping bundle");
116+
let marker = out_dir.join("pgvector_bundle.tar.gz");
117+
fs::write(&marker, b"").expect("Failed to create empty pgvector marker");
118+
println!(
119+
"cargo:rustc-env=PGVECTOR_BUNDLE_PATH={}",
120+
marker.display()
121+
);
122+
return;
123+
}
124+
_ => {
125+
eprintln!(
126+
"Warning: Unknown target {}, pgvector will not be bundled",
127+
target
128+
);
129+
let marker = out_dir.join("pgvector_bundle.tar.gz");
130+
fs::write(&marker, b"").expect("Failed to create empty pgvector marker");
131+
println!(
132+
"cargo:rustc-env=PGVECTOR_BUNDLE_PATH={}",
133+
marker.display()
134+
);
135+
return;
136+
}
137+
};
138+
139+
// Get PG major version (e.g., "18" from "18.1.0")
140+
let pg_major = pg_version.split('.').next().unwrap_or("18");
141+
142+
let filename = format!("pgvector-{}-pg{}.tar.gz", pgvector_platform, pg_major);
143+
let url = format!(
144+
"https://github.com/{}/releases/download/{}/{}",
145+
pgvector_repo, pgvector_tag, filename
146+
);
147+
148+
let bundle_path = out_dir.join(&filename);
149+
150+
// Download if not already cached
151+
if !bundle_path.exists() {
152+
eprintln!(
153+
"Downloading pgvector for {} (PG {})...",
154+
pgvector_platform, pg_major
155+
);
156+
download_file(&url, &bundle_path).expect("Failed to download pgvector bundle");
157+
eprintln!("Downloaded to {}", bundle_path.display());
158+
} else {
159+
eprintln!("Using cached pgvector bundle: {}", bundle_path.display());
160+
}
161+
162+
println!(
163+
"cargo:rustc-env=PGVECTOR_BUNDLE_PATH={}",
164+
bundle_path.display()
165+
);
119166
}
120167

121168
fn download_file(url: &str, dest: &PathBuf) -> io::Result<()> {

docker-tests/README.md

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,6 @@ chmod +x *.sh
4747
./test_alpine_arm64.sh
4848
```
4949

50-
### Using GitHub Token (Avoid Rate Limiting)
51-
52-
To avoid GitHub API rate limiting, set a personal access token:
53-
54-
```bash
55-
# Create a token at https://github.com/settings/tokens
56-
# No scopes needed for public repos
57-
58-
export GITHUB_TOKEN=ghp_your_token_here
59-
60-
# Now run tests with 5000 req/hour instead of 60
61-
./test_debian_amd64.sh
62-
```
63-
64-
The token is automatically passed into the Docker containers.
65-
6650
## Expected Results
6751

6852
### Debian/Ubuntu (glibc)
@@ -78,15 +62,11 @@ The token is automatically passed into the Docker containers.
7862
## Requirements
7963

8064
- Docker installed and running
81-
- Internet connection (to download pg0 and PostgreSQL)
82-
- ~500MB free space for PostgreSQL binaries
65+
- Internet connection (to download pg0 binary)
66+
- ~50MB free space (PostgreSQL and pgvector are bundled in the binary)
8367

8468
## Troubleshooting
8569

86-
### Test hangs during PostgreSQL download
87-
88-
This may be due to GitHub API rate limiting. Wait a few minutes and try again.
89-
9070
### ARM64 tests are slow
9171

9272
ARM64 tests use emulation on x86_64 hosts, which is slower. This is expected.

docker-tests/test_alpine_amd64.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1212
INSTALL_SCRIPT="$SCRIPT_DIR/../install.sh"
1313

1414
docker run --rm --platform=linux/amd64 \
15-
-e GITHUB_TOKEN="${GITHUB_TOKEN:-}" \
1615
-v "$INSTALL_SCRIPT:/tmp/install.sh:ro" \
1716
python:3.11-alpine sh -c '
1817
set -e
@@ -39,7 +38,6 @@ echo ""
3938
echo "=== Switching to non-root user for pg0 ==="
4039
su - pguser << EOF
4140
set -e
42-
export GITHUB_TOKEN="${GITHUB_TOKEN}"
4341
4442
echo "=== Installing pg0 ==="
4543
bash /usr/local/bin/install.sh

docker-tests/test_alpine_arm64.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1212
INSTALL_SCRIPT="$SCRIPT_DIR/../install.sh"
1313

1414
docker run --rm --platform=linux/arm64 \
15-
-e GITHUB_TOKEN="${GITHUB_TOKEN:-}" \
1615
-v "$INSTALL_SCRIPT:/tmp/install.sh:ro" \
1716
python:3.11-alpine sh -c '
1817
set -e
@@ -39,7 +38,6 @@ echo ""
3938
echo "=== Switching to non-root user for pg0 ==="
4039
su - pguser << EOF
4140
set -e
42-
export GITHUB_TOKEN="${GITHUB_TOKEN}"
4341
4442
echo "=== Installing pg0 ==="
4543
bash /usr/local/bin/install.sh

docker-tests/test_debian_amd64.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ if [ -n "${PG0_BINARY_PATH:-}" ]; then
2121
fi
2222

2323
docker run --rm --platform=linux/amd64 \
24-
-e GITHUB_TOKEN="${GITHUB_TOKEN:-}" \
2524
$BINARY_ENV \
2625
-v "$INSTALL_SCRIPT:/tmp/install.sh:ro" \
2726
$VOLUME_ARGS \
@@ -54,7 +53,6 @@ echo ""
5453
echo "=== Switching to non-root user for pg0 ==="
5554
su - pguser << EOF
5655
set -e
57-
export GITHUB_TOKEN="${GITHUB_TOKEN}"
5856
export PG0_BINARY_URL="${PG0_BINARY_URL}"
5957
6058
echo "=== Installing pg0 ==="

docker-tests/test_debian_arm64.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1212
INSTALL_SCRIPT="$SCRIPT_DIR/../install.sh"
1313

1414
docker run --rm --platform=linux/arm64 \
15-
-e GITHUB_TOKEN="${GITHUB_TOKEN:-}" \
1615
-v "$INSTALL_SCRIPT:/tmp/install.sh:ro" \
1716
python:3.11-slim bash -c '
1817
set -e
@@ -43,7 +42,6 @@ echo ""
4342
echo "=== Switching to non-root user for pg0 ==="
4443
su - pguser << EOF
4544
set -e
46-
export GITHUB_TOKEN="${GITHUB_TOKEN}"
4745
4846
echo "=== Installing pg0 ==="
4947
bash /usr/local/bin/install.sh

0 commit comments

Comments
 (0)