-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Need to configure `secrets.DOCKERIO_USERNAME` and `secrets.DOCKERIO_TOKEN` Test in my repo: - https://github.com/silver-ymz/VectorChord-bm25/actions/runs/12965263681 - https://hub.docker.com/u/silverha --------- Signed-off-by: Mingzhuo Yin <[email protected]>
- Loading branch information
1 parent
f9fb146
commit 1617597
Showing
6 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
name: Publish | ||
|
||
on: | ||
release: | ||
types: [created] | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: 'tag name (semver without v-prefix)' | ||
required: true | ||
type: string | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
semver: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
SEMVER: ${{ steps.semver.outputs.SEMVER }} | ||
steps: | ||
- uses: actions/github-script@v7 | ||
id: semver | ||
with: | ||
script: | | ||
const tag = "${{ github.event.inputs.tag }}" || "${{ github.event.release.tag_name }}"; | ||
console.log(`Tag: ${tag}`); | ||
const r = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; | ||
if (!r.test(tag)) { | ||
core.setFailed(`Action failed with an invalid semver.`); | ||
} | ||
core.setOutput('SEMVER', tag); | ||
build: | ||
runs-on: ${{ matrix.runner }} | ||
needs: ["semver"] | ||
strategy: | ||
matrix: | ||
version: ["14", "15", "16", "17"] | ||
runner: ["ubicloud-standard-4", "ubicloud-standard-4-arm"] | ||
env: | ||
PGRX_IMAGE: "ghcr.io/tensorchord/vectorchord-pgrx:0.12.9-nightly-2024-12-25" | ||
SEMVER: ${{ needs.semver.outputs.SEMVER }} | ||
ARCH: ${{ matrix.runner == 'ubicloud-standard-4' && 'x86_64' || 'aarch64' }} | ||
PLATFORM: ${{ matrix.runner == 'ubicloud-standard-4' && 'amd64' || 'arm64' }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Configure sccache | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const url = process.env.ACTIONS_CACHE_URL || ''; | ||
const token = process.env.ACTIONS_RUNTIME_TOKEN || ''; | ||
core.exportVariable( | ||
'CACHE_ENVS', | ||
`-e CARGO_INCREMENTAL=0 -e SCCACHE_GHA_ENABLED=true -e RUSTC_WRAPPER=sccache -e ACTIONS_CACHE_URL=${url} -e ACTIONS_RUNTIME_TOKEN=${token}`, | ||
); | ||
- name: Set up pgrx docker images and permissions | ||
run: | | ||
docker pull $PGRX_IMAGE | ||
echo "Default user: $(id -u):$(id -g)" | ||
sudo chmod -R 777 . | ||
- name: Build | ||
env: | ||
VERSION: ${{ matrix.version }} | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE cargo build --lib --features pg$VERSION --release | ||
docker run --rm -v .:/workspace $CACHE_ENVS -e SEMVER=${SEMVER} $PGRX_IMAGE ./tools/schema.sh --features pg$VERSION --release | ||
./tools/package.sh | ||
ls ./build | ||
gh release upload --clobber $SEMVER ./build/vchord-bm25-pg${VERSION}_${SEMVER}_${PLATFORM}.deb | ||
gh release upload --clobber $SEMVER ./build/vchord-bm25-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip | ||
docker: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
needs: ["semver", "build"] | ||
strategy: | ||
matrix: | ||
version: ["14", "15", "16", "17"] | ||
env: | ||
SEMVER: ${{ needs.semver.outputs.SEMVER }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Download | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
mkdir -p build | ||
for arch in amd64 arm64; do | ||
gh release download $SEMVER --pattern "vchord-bm25-pg${{ matrix.version }}_${SEMVER}_${arch}.deb" --output ./build/vchord-bm25-pg${{ matrix.version }}_${SEMVER}_${arch}.deb | ||
done | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERIO_USERNAME }} | ||
password: ${{ secrets.DOCKERIO_TOKEN }} | ||
- name: Login to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Push binary release to Docker Registry | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: true | ||
platforms: "linux/amd64,linux/arm64" | ||
file: ./docker/binary.Dockerfile | ||
tags: | | ||
tensorchord/vchord_bm25-binary:pg${{ matrix.version }}-v${{ env.SEMVER }} | ||
ghcr.io/tensorchord/vchord_bm25-binary:pg${{ matrix.version }}-v${{ env.SEMVER }} | ||
build-args: | | ||
PG_VERSION=${{ matrix.version }} | ||
SEMVER=${{ env.SEMVER }} | ||
- name: Push PostgreSQL release to Docker Registry | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: true | ||
platforms: "linux/amd64,linux/arm64" | ||
file: ./docker/Dockerfile | ||
tags: | | ||
tensorchord/vchord_bm25-postgres:pg${{ matrix.version }}-v${{ env.SEMVER }} | ||
ghcr.io/tensorchord/vchord_bm25-postgres:pg${{ matrix.version }}-v${{ env.SEMVER }} | ||
build-args: | | ||
PG_VERSION=${{ matrix.version }} | ||
SEMVER=${{ env.SEMVER }} | ||
PGVECTOR=0.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ARG PG_VERSION=17 | ||
ARG PGVECTOR=0.8.0 | ||
|
||
FROM pgvector/pgvector:${PGVECTOR}-pg${PG_VERSION} | ||
|
||
ARG PG_VERSION | ||
ARG SEMVER=0.0.0 | ||
ARG TARGETARCH | ||
|
||
RUN echo ${PG_VERSION} | ||
COPY ./build/vchord-bm25-pg${PG_VERSION}_${SEMVER}_${TARGETARCH}.deb /tmp/vchord-bm25.deb | ||
RUN apt-get install -y /tmp/vchord-bm25.deb && rm -f /tmp/vchord-bm25.deb | ||
|
||
CMD ["postgres", "-c" ,"shared_preload_libraries=vchord_bm25.so"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM scratch | ||
|
||
ARG SEMVER | ||
ARG PG_VERSION | ||
ARG TARGETARCH | ||
|
||
WORKDIR /workspace | ||
COPY ./build/vchord-bm25-pg${PG_VERSION}_${SEMVER}_${TARGETARCH}.deb /workspace/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
printf "SEMVER = ${SEMVER}\n" | ||
printf "VERSION = ${VERSION}\n" | ||
printf "ARCH = ${ARCH}\n" | ||
printf "PLATFORM = ${PLATFORM}\n" | ||
|
||
rm -rf ./build/dir_zip | ||
rm -rf ./build/vchord-bm25-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip | ||
rm -rf ./build/dir_deb | ||
rm -rf ./build/vchord-bm25-pg${VERSION}_${SEMVER}_${PLATFORM}.deb | ||
|
||
mkdir -p ./build/dir_zip | ||
cp ./target/release/schema.sql ./build/dir_zip/vchord_bm25--$SEMVER.sql | ||
sed -e "s/@CARGO_VERSION@/$SEMVER/g" < ./vchord_bm25.control > ./build/dir_zip/vchord_bm25.control | ||
cp ./target/release/libvchord_bm25.so ./build/dir_zip/vchord_bm25.so | ||
zip ./build/vchord-bm25-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip -j ./build/dir_zip/* | ||
|
||
mkdir -p ./build/dir_deb | ||
mkdir -p ./build/dir_deb/DEBIAN | ||
mkdir -p ./build/dir_deb/usr/share/postgresql/$VERSION/extension/ | ||
mkdir -p ./build/dir_deb/usr/lib/postgresql/$VERSION/lib/ | ||
for file in $(ls ./build/dir_zip/*.sql | xargs -n 1 basename); do | ||
cp ./build/dir_zip/$file ./build/dir_deb/usr/share/postgresql/$VERSION/extension/$file | ||
done | ||
for file in $(ls ./build/dir_zip/*.control | xargs -n 1 basename); do | ||
cp ./build/dir_zip/$file ./build/dir_deb/usr/share/postgresql/$VERSION/extension/$file | ||
done | ||
for file in $(ls ./build/dir_zip/*.so | xargs -n 1 basename); do | ||
cp ./build/dir_zip/$file ./build/dir_deb/usr/lib/postgresql/$VERSION/lib/$file | ||
done | ||
echo "Package: vchord-bm25-pg${VERSION} | ||
Version: ${SEMVER} | ||
Section: database | ||
Priority: optional | ||
Architecture: ${PLATFORM} | ||
Maintainer: Tensorchord <[email protected]> | ||
Description: Vector database plugin for Postgres, written in Rust, specifically designed for LLM | ||
Homepage: https://github.com/tensorchord/VectorChord-bm25/ | ||
License: AGPLv3 or ELv2" \ | ||
> ./build/dir_deb/DEBIAN/control | ||
(cd ./build/dir_deb && md5sum usr/share/postgresql/$VERSION/extension/* usr/lib/postgresql/$VERSION/lib/*) > ./build/dir_deb/DEBIAN/md5sums | ||
dpkg-deb -Zxz --build ./build/dir_deb/ ./build/vchord-bm25-pg${VERSION}_${SEMVER}_${PLATFORM}.deb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# CONTROL_FILEPATH | ||
# SO_FILEPATH | ||
|
||
printf "fn main() {\n" | ||
|
||
cat << EOF | ||
vchord_bm25::__pgrx_marker(); | ||
let mut entities = Vec::new(); | ||
let control_file_path = std::path::PathBuf::from("$CONTROL_FILEPATH"); | ||
let control_file = ::pgrx::pgrx_sql_entity_graph::ControlFile::try_from(control_file_path).expect(".control file should properly formatted"); | ||
let control_file_entity = ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity::ExtensionRoot(control_file); | ||
entities.push(control_file_entity); | ||
EOF | ||
|
||
while read -r name_ident; do | ||
cat << EOF | ||
extern "Rust" { | ||
fn $name_ident() -> ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity; | ||
} | ||
let entity = unsafe { $name_ident() }; | ||
entities.push(entity); | ||
EOF | ||
done <<< $(nm -D -g $SO_FILEPATH | grep "T __pgrx_internals_" | awk '{print $3}') | ||
|
||
cat << EOF | ||
let pgrx_sql = ::pgrx::pgrx_sql_entity_graph::PgrxSql::build( | ||
entities.into_iter(), | ||
"vchord_bm25".to_string(), | ||
false, | ||
) | ||
.expect("SQL generation error"); | ||
eprintln!("SQL entities to {}", "/dev/stdout",); | ||
pgrx_sql | ||
.write(&mut std::io::stdout()) | ||
.expect("Could not write SQL to stdout"); | ||
EOF | ||
|
||
printf "}\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
if [[ " $@ " =~ --target' '([^ ]+) ]]; then | ||
TARGET="${BASH_REMATCH[1]}" | ||
if [[ " $@ " =~ " --release " ]]; then | ||
DIR="./target/$TARGET/release" | ||
else | ||
DIR="./target/$TARGET/debug" | ||
fi | ||
else | ||
if [[ " $@ " =~ " --release " ]]; then | ||
DIR="./target/release" | ||
else | ||
DIR="./target/debug" | ||
fi | ||
fi | ||
|
||
if [ "$TARGET" = "" ]; then | ||
printf "Target: [not specified]\n" 1>&2 | ||
RUNNER=() | ||
elif [ "$TARGET" = $(rustc -vV | awk '/^host/ { print $2 }') ]; then | ||
printf "Target: [host]\n" 1>&2 | ||
RUNNER=() | ||
elif [ "$TARGET" = "aarch64-unknown-linux-gnu" ]; then | ||
printf "Target: $TARGET\n" 1>&2 | ||
QEMU_LD_PREFIX="/usr/aarch64-linux-gnu" | ||
RUNNER=("qemu-aarch64-static") | ||
elif [ "$TARGET" = "riscv64gc-unknown-linux-gnu" ]; then | ||
printf "Target: $TARGET\n" 1>&2 | ||
QEMU_LD_PREFIX="/usr/riscv64-linux-gnu" | ||
RUNNER=("qemu-riscv64-static") | ||
else | ||
printf "Unknown target: $TARGET\n" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
code=$(mktemp) | ||
chmod 700 $code | ||
CONTROL_FILEPATH="./vchord_bm25.control" SO_FILEPATH="$DIR/libvchord_bm25.so" $(dirname "$0")/schema-codegen.sh >> $code | ||
|
||
PGRX_EMBED=$code cargo rustc --package vchord_bm25 --bin pgrx_embed_vchord_bm25 "$@" -- --cfg pgrx_embed | ||
|
||
CARGO_PKG_VERSION=${SEMVER} QEMU_LD_PREFIX=$QEMU_LD_PREFIX "${RUNNER[@]}" "$DIR/pgrx_embed_vchord_bm25" | expand -t 4 > $DIR/schema.sql |