Skip to content

Commit ed010ed

Browse files
authored
Extension deb builder (#303)
1 parent 091df10 commit ed010ed

File tree

7 files changed

+138
-26
lines changed

7 files changed

+138
-26
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Extension builder.
3+
#
4+
ARG VERSION=22.04
5+
FROM ubuntu:${VERSION}
6+
7+
ARG PGVERSION=14
8+
ARG DEBIAN_FRONTEND=noninteractive
9+
ENV TZ=Etc/UTC
10+
11+
# Apt-fast
12+
RUN apt-get update && apt-get install software-properties-common -y
13+
14+
RUN add-apt-repository ppa:apt-fast/stable --yes
15+
RUN apt-get update && apt-get -y install apt-fast
16+
17+
RUN apt-fast install apt-fast curl unzip gpg -y
18+
19+
# PostgresSQL
20+
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg > /dev/null
21+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
22+
23+
# CMake
24+
RUN curl -L https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
25+
RUN echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/kitware.list >/dev/null
26+
27+
RUN apt-get update && apt-fast install postgresql-${PGVERSION} libopenblas-dev cmake postgresql-server-dev-${PGVERSION} pkg-config libssl-dev build-essential libclang-dev -y
28+
29+
USER postgres
30+
31+
# Install Rust
32+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
33+
ENV PATH="/var/lib/postgresql/.cargo/bin:${PATH}"
34+
35+
# Install tcdi/pgx
36+
RUN cargo install cargo-pgx
37+
RUN cargo pgx init --pg${PGVERSION} /usr/bin/pg_config
38+
39+
COPY --chown=postgres:postgres . /app
40+
WORKDIR /app
41+
42+
# Build and upload package to S3
43+
RUN cargo pgx package
44+
45+
# Deb file goes here, mount it on your local system
46+
VOLUME /output
47+
USER root
48+
49+
# Run
50+
ENTRYPOINT ["bash", "docker/build_ubuntu_deb.sh", "0.0.4", "/output"]
51+

pgml-extension/pgml_rust/README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,36 @@ Here we have some POC code to use Rust for PostgresML.
44

55
## Dependencies
66

7-
All dependencies are vendored. I downloaded XGBoost 1.62 and all its submodules. We're also using the `master` branch of `xgboost` Rust crate.
7+
All dependencies are vendored. I downloaded XGBoost 1.62 and all its submodules. We're also using the `master` branch of `xgboost` Rust crate and `openblas-src`.
88

99
If you haven't already, install:
1010

1111
- `cmake`
1212
- `libclang-dev`
13+
- `libopenblas-dev`
1314

1415
## Local development
1516

16-
1. `cargo install pgx`
17-
2. `cargo pgx run`
18-
3. `DROP EXTENSION IF EXISTS pgml_rust;`
19-
4. `CREATE EXTENSION pgml_rust;`
20-
5. `SELECT pgml_train('pgml.diabetes', ARRAY['age', 'sex'], 'target');`
21-
6. `SELECT * FROM pgml_predict(ARRAY[1, 5.0]);`
17+
1. `cargo install cargo-pgx`
18+
2. `cargo pgx init`
19+
3. `cargo pgx run`
20+
4. `DROP EXTENSION IF EXISTS pgml_rust;`
21+
5. `CREATE EXTENSION pgml_rust;`
22+
6. `SELECT pgml_rust.train('Project name', 'regression', pgml_rust.diabetes', 'target', 'xgboost', '{}');`
23+
7. `SELECT * FROM pgml_rust.predict('Project name', ARRAY[1, 5.0, 2.0]);`
2224

23-
Lots of todos, but still a decent PoC.
25+
## Packaging
26+
27+
We currently support Ubuntu 18.04 and newer. Mac OS (Apple Sillicon) support is in progress. Provided in the repo is the `.deb` builder, which requires Docker. Once Docker is installed, you can run:
28+
29+
```bash
30+
bash build_extension.sh
31+
```
32+
33+
which will produce a `.deb` file in the current directory. The deb file can be installed with `apt-get`, for example:
34+
35+
```bash
36+
apt-get install ./postgresql-pgml-12_0.0.4-ubuntu20.04-amd64.deb
37+
```
38+
39+
which will take care of installing its dependencies as well. Make sure to run this as root and not with sudo.

pgml-extension/pgml_rust/build_deb.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
#
3+
# Build the extension.
4+
#
5+
6+
echo "Building base image, this will take a little while"
7+
docker build . --build-arg VERSION=${1:-"22.04"} --build-arg PGVERSION=${2:-"14"}
8+
9+
IMAGE_ID=$(docker images | awk '{print $3}' | awk 'NR==2')
10+
11+
docker run -v $(pwd):/output ${IMAGE_ID}

pgml-extension/pgml_rust/control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Package: postgresql-pgml-14
1+
Package: postgresql-pgml-PGVERSION
22
Version: VERSION
33
Section: base
44
Priority: optional
55
Architecture: ARCH
6-
Depends: postgresql-14
6+
Depends: postgresql-PGVERSION, libopenblas-dev, postgresql-server-dev-PGVERSION
77
Maintainer: PostgresML <team@postgresml.org>
88
Description: PostgresML - machine learning with PostgreSQL
99
PostgresML is a PostgreSQL extension that allows to do machine
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
#
3+
# Build a .deb for the Postgres and Ubuntu version.
4+
#
5+
6+
VERSION=${1:-0.0.4}
7+
OUTPUT_DIR=${2:-"."}
8+
9+
if [[ $(uname) == *"aarch64"* ]]; then
10+
ARCH="arm64"
11+
else
12+
ARCH="amd64"
13+
fi
14+
15+
PGVERSION=$(pg_config | grep "VERSION")
16+
17+
if [[ $PGVERSION == *"12."* ]]; then
18+
PGVERSION="12"
19+
elif [[ $PGVERSION == *"13."* ]]; then
20+
PGVERSION="13"
21+
elif [[ $PGVERSION == *"14."* ]]; then
22+
PGVERSION="14"
23+
elif [[ $PGVERSION == *"11."* ]]; then
24+
PGVERSION="11"
25+
elif [[ $PGVERSION == *"10."* ]]; then
26+
PGVERSION="10"
27+
else
28+
echo "Unknown PostgreSQL version detected: ${PGVERSION}"
29+
exit 1
30+
fi
31+
32+
TARGET="target/release/pgml_rust-pg${PGVERSION}"
33+
UBUNTU_VERSION=$(lsb_release -a | grep Release | awk '{ print $2 }')
34+
35+
mkdir -p ${TARGET}/DEBIAN
36+
cp control ${TARGET}/DEBIAN/control
37+
38+
# Save version and arch.
39+
sed -i "s/PGVERSION/${PGVERSION}/g" ${TARGET}/DEBIAN/control
40+
sed -i "s/VERSION/${VERSION}/g" ${TARGET}/DEBIAN/control
41+
sed -i "s/ARCH/${ARCH}/g" ${TARGET}/DEBIAN/control
42+
43+
# Show me what we got.
44+
cat ${TARGET}/DEBIAN/control
45+
46+
PACKAGE=postgresql-pgml-${PGVERSION}_${VERSION}-ubuntu${UBUNTU_VERSION}-${ARCH}.deb
47+
48+
# Build the debian package
49+
dpkg-deb --build ${TARGET} $OUTPUT_DIR/${PACKAGE}

0 commit comments

Comments
 (0)