Skip to content

Instantly share code, notes, and snippets.

@olee
Last active November 24, 2023 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olee/5cbb4855c45854a873c698f70970c388 to your computer and use it in GitHub Desktop.
Save olee/5cbb4855c45854a873c698f70970c388 to your computer and use it in GitHub Desktop.
Build setup for pg_bm25 using dagger ci

Either use dagger ci tool to run the full build toolchain or run the scripts step by step (with the correct environment variables set)

#!/bin/bash
# Install basic dependencies
echo Fetching updates...
apt-get update -qq
echo Installing basic dependencies...
DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends \
wget curl ca-certificates gnupg2 lsb-release git \
build-essential pkg-config \
tzdata
#!/bin/bash
# Prevent interactive install of tzdata
ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
# Add postgresql apt repository
echo Adding postgres repository...
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Install postgresql dev dependencies
echo Installing postgres-${PG_VERSION}...
apt-get update -qq && apt-get install -qq -y --no-install-recommends \
postgresql-${PG_VERSION} postgresql-server-dev-${PG_VERSION}
#!/bin/bash
# Install rust
echo Installing rust...
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${RUST_VERSION}
#!/bin/bash
cargo install --locked cargo-pgrx --version $PGRX_VERSION
cargo pgrx init --pg15=`which pg_config`
#!/bin/bash
# Clone pg_bm25 extension
git clone --depth 1 --branch v${PG_BM25_VERSION} https://github.com/paradedb/paradedb.git /paradedb
cd /paradedb/pg_bm25
# Compile pg_bm25 extension
cargo pgrx package
#!/bin/bash
cd /paradedb
# delete old artifacts
rm -Rf archive pg_bm25-*
mkdir archive
cp `find target/release -type f -name "pg_bm25*"` archive
package_dir=pg_bm25-${PG_BM25_VERSION}-pg${PG_VERSION}-${ARCH}-linux-gnu
# Copy files into directory structure
mkdir -p ${package_dir}/usr/lib/postgresql/lib
mkdir -p ${package_dir}/var/lib/postgresql/extension
cp archive/*.so ${package_dir}/usr/lib/postgresql/lib
cp archive/*.control ${package_dir}/var/lib/postgresql/extension
cp archive/*.sql ${package_dir}/var/lib/postgresql/extension
# Symlinks to copy files into directory structure
mkdir -p ${package_dir}/usr/lib/postgresql/${PG_VERSION}/lib
mkdir -p ${package_dir}/usr/share/postgresql/${PG_VERSION}/extension
cp archive/*.so ${package_dir}/usr/lib/postgresql/${PG_VERSION}/lib
cp archive/*.control ${package_dir}/usr/share/postgresql/${PG_VERSION}/extension
cp archive/*.sql ${package_dir}/usr/share/postgresql/${PG_VERSION}/extension
# Create control file (package name cannot have underscore)
mkdir -p ${package_dir}/DEBIAN
touch ${package_dir}/DEBIAN/control
deb_version=${PG_BM25_VERSION}
control_file="${package_dir}/DEBIAN/control"
echo 'Package: pg-bm25' >> $control_file
echo "Version: ${deb_version}" >> $control_file
echo "Architecture: ${ARCH}" >> $control_file
echo 'Maintainer: ParadeDB <support@paradedb.com>' >> $control_file
echo 'Description: Full text search for PostgreSQL using BM25' >> $control_file
# Create deb package
chmod -R 00755 ${package_dir}
dpkg-deb --build --root-owner-group ${package_dir}
import path from 'node:path';
import { Container, connect } from '@dagger.io/dagger';
connect(async (client) => {
const PG_VERSION = '15';
const RUST_VERSION = '1.71.0';
const PGRX_VERSION = '0.11.0';
const PG_BM25_VERSION = '0.3.10';
const build = await client
.container()
.from('ubuntu:focal')
// Install basic dependencies
.withFile('/0-basic-deps.sh', client.host().file('./0-basic-deps.sh'))
.withExec(['/0-basic-deps.sh'])
// Install postgres
.withEnvVariable('PG_VERSION', PG_VERSION)
.withFile('/1-postgres.sh', client.host().file('./1-postgres.sh'))
.withExec(['/1-postgres.sh'])
// Install rust
.withEnvVariable('RUST_VERSION', RUST_VERSION)
.withFile('/2-rust.sh', client.host().file('./2-rust.sh'))
.withExec(['/2-rust.sh'])
.withEnvVariable('PATH', '/root/.cargo/bin:${PATH}', { expand: true })
// Install and init pgrx
.withEnvVariable('PGRX_VERSION', PGRX_VERSION)
.withFile('/3-pgrx.sh', client.host().file('./3-pgrx.sh'))
.withExec(['/3-pgrx.sh'])
// Build extension
.withEnvVariable('ARCH', 'amd64')
.withEnvVariable('PG_BM25_VERSION', PG_BM25_VERSION)
.withFile('/4-build.sh', client.host().file('./4-build.sh'))
.withExec(['/4-build.sh'])
// Create deb package
.withFile('/5-package.sh', client.host().file('./5-package.sh'))
.withExec(['/5-package.sh']);
const output = await build.stdout();
await build
.file(`/paradedb/pg_bm25-${PG_BM25_VERSION}-pg${PG_VERSION}-amd64-linux-gnu.deb`)
.export('./', { allowParentDirPath: true });
}, { LogOutput: process.stdout });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment