Skip to content

Commit a5fd842

Browse files
authored
chore: build docker image ourselves (#3)
* chore: build docker image ourselves see https://community.fly.io/t/adding-pgvector-to-fly-postgres/12202 * test: re-run actions * chore: extract the script * feat: specify this targets 13 * test: fix typo * chore: limit test pg * fix: platforms * chore: remove terminal stuff * chore: fix shell script usage * test: linux install requires sudo * fix: build image * test: exclude pg 13 * fix: pg image reference (bump minor)
1 parent 0416939 commit a5fd842

File tree

4 files changed

+125
-46
lines changed

4 files changed

+125
-46
lines changed

.github/workflows/build-image.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ jobs:
2929
context: .
3030
file: ./Dockerfile
3131
# platforms: ${{ matrix.platforms }}
32-
platforms: linux/amd64
32+
platforms: linux/amd64,linux/arm64/v8
3333
push: true
34-
tags: ghcr.io/x-b-e/server-pg:latest
34+
tags: ghcr.io/x-b-e/server-pg:13
3535
build-args: |
3636
PG_MAJOR=13
37-
PG_TAG=13-13.3
37+
PG_IMAGE=postgis/postgis:13-3.4
3838
# outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=XBE server pg
3939
# cache-from: ghcr.io/x-b-e/server-pg

.github/workflows/build.yml

+8-26
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,20 @@ jobs:
1212
os: ubuntu-22.04
1313
- postgres: 14
1414
os: ubuntu-22.04
15-
- postgres: 13
16-
os: ubuntu-20.04
17-
- postgres: 12
18-
os: ubuntu-20.04
19-
- postgres: 11
20-
os: ubuntu-18.04
15+
# - postgres: 13
16+
# os: ubuntu-20.04
17+
# - postgres: 12
18+
# os: ubuntu-20.04
19+
# - postgres: 11
20+
# os: ubuntu-18.04
2121
steps:
2222
- uses: actions/checkout@v3
2323
- uses: ankane/setup-postgres@v1
2424
with:
2525
postgres-version: ${{ matrix.postgres }}
2626
dev-files: true
27-
- run: make
2827
- run: |
29-
export PG_CONFIG=`which pg_config`
30-
sudo --preserve-env=PG_CONFIG make install
31-
- run: make installcheck
32-
- if: ${{ failure() }}
33-
run: cat regression.diffs
34-
- run: |
35-
sudo apt-get update
36-
sudo apt-get install libipc-run-perl
37-
- run: make prove_installcheck
28+
sudo script/install_pgvector install 0.4.1 pgvector
3829
mac:
3930
runs-on: macos-latest
4031
if: ${{ !startsWith(github.ref_name, 'windows') }}
@@ -43,17 +34,8 @@ jobs:
4334
- uses: ankane/setup-postgres@v1
4435
with:
4536
postgres-version: 14
46-
- run: make
47-
- run: make install
48-
- run: make installcheck
49-
- if: ${{ failure() }}
50-
run: cat regression.diffs
5137
- run: |
52-
brew install cpanm
53-
cpanm --notest IPC::Run
54-
wget -q https://github.com/postgres/postgres/archive/refs/tags/REL_14_5.tar.gz
55-
tar xf REL_14_5.tar.gz
56-
- run: make prove_installcheck PROVE_FLAGS="-I ./postgres-REL_14_5/src/test/perl" PERL5LIB="/Users/runner/perl5/lib/perl5"
38+
script/install_pgvector install 0.4.1 pgvector
5739
windows:
5840
runs-on: windows-latest
5941
if: ${{ !startsWith(github.ref_name, 'mac') }}

Dockerfile

+28-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
# syntax=docker/dockerfile:1
22

33
ARG PG_MAJOR="13"
4-
ARG PG_TAG="13-13.3"
4+
# see https://hub.docker.com/r/postgis/postgis for valid images
5+
ARG PG_IMAGE="postgis/postgis:13-3.4"
56

6-
FROM postgis/postgis:13-3.3
7-
# FROM postgis/postgis:${PG_TAG}
7+
FROM $PG_IMAGE
88

99
LABEL org.opencontainers.image.source "https://github.com/x-b-e/pgvector"
1010
LABEL org.opencontainers.image.description "XBE server postgres with postgis, pgvector"
1111
LABEL org.opencontainers.image.licenses "PostgreSQL License"
1212

1313
# ARG PG_MAJOR
1414
# ENV PG_MAJOR=${PG_MAJOR}
15-
ENV PG_MAJOR=13
16-
17-
COPY . /tmp/pgvector
15+
# ENV PG_MAJOR=13
1816

1917
RUN apt-get update && \
20-
apt-get install -y --no-install-recommends build-essential postgresql-server-dev-${PG_MAJOR} && \
21-
cd /tmp/pgvector && \
22-
make clean && \
23-
make OPTFLAGS="" && \
24-
make install && \
25-
mkdir /usr/share/doc/pgvector && \
26-
cp LICENSE README.md /usr/share/doc/pgvector && \
27-
rm -r /tmp/pgvector && \
28-
apt-get remove -y build-essential postgresql-server-dev-${PG_MAJOR} && \
29-
apt-get autoremove -y && \
30-
rm -rf /var/lib/apt/lists/*
18+
apt-get install -y --no-install-recommends \
19+
build-essential \
20+
curl \
21+
postgresql-server-dev-all
22+
23+
# Set the pgvector version
24+
ARG PGVECTOR_VERSION=0.4.1
25+
ARG PGVECTOR_BUILD_DIR="pgvector"
26+
27+
COPY script/install_pgvector /tmp/install_pgvector
28+
29+
# Download and extract the pgvector release, build the extension, and install it
30+
RUN /tmp/install_pgvector install "${PGVECTOR_VERSION}" "${PGVECTOR_BUILD_DIR}" && \
31+
rm -rf /tmp/*
32+
33+
# Clean up build dependencies and temporary files
34+
RUN apt-get remove -y \
35+
build-essential \
36+
curl \
37+
postgresql-server-dev-all && \
38+
apt-get autoremove -y && \
39+
apt-get clean && \
40+
rm -rf /var/lib/apt/lists/* && \
41+
rm -rf "$PGVECTOR_BUILD_DIR"

script/install_pgvector

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
#
3+
# Usage:
4+
# script/pgvector install PGVECTOR_VERSION PGVECTOR_BUILD_DIR
5+
# script/pgvector help
6+
7+
set -euo pipefail
8+
IFS=$'\n\t'
9+
unset CDPATH
10+
11+
# Influenced by https://dev.to/thiht/shell-scripts-matter
12+
# And see https://github.com/bf4/Notes/wiki/Shell-Scripting
13+
14+
# Log errors, if any, bash pseudo-signal: ERR
15+
# Usage:
16+
# trap 'finish_error $LINENO' ERR
17+
finish_error() {
18+
errcode=$?
19+
echo " END ERROR Running script: ${0##*/}:$1: exited with '${errcode}'." >&2
20+
}
21+
22+
trap 'finish_error $LINENO' ERR
23+
24+
readonly DEBUG="${DEBUG:-}"
25+
# shellcheck disable=SC2155
26+
readonly TIMEZONE="${TZ:-America/Chicago}"
27+
logstamp() { printf "[%s]" "$(TZ="'${TIMEZONE}'" date +'%Y-%m-%d %H:%M:%S')" ; }
28+
topic() { echo "-----> $(logstamp) $*" >&2 ; }
29+
info() { echo " $*" >&2 ; }
30+
debug() { if [ "$DEBUG" = "true" ]; then echo -e "[DEBUG] $*" >&2 ; fi ; }
31+
indent() { sed -u 's/^/ /' ; } # it always runs on linux. on darwin is 'sed -l'
32+
warn() { info "WARNING - ${*}" ; }
33+
error() { info "ERROR - ${*}" ; }
34+
fail() { error "$*" ; exit 1 ; }
35+
36+
abort=0
37+
help() {
38+
sed -ne '/^#/!q;s/.\{1,2\}//;1d;p' < "$0" >&$((abort+1))
39+
exit "$abort"
40+
}
41+
42+
# $1 is the PGVECTOR_VERSION
43+
readonly PGVECTOR_VERSION="${2:-}"
44+
readonly PGVECTOR_BUILD_DIR="${3:-pgvector-${PGVECTOR_VERSION}}"
45+
if [ "$DEBUG" = "true" ]; then set -x ; fi
46+
47+
validate_env_vars() {
48+
if [ -z "${PGVECTOR_VERSION}" ]; then
49+
info "PGVECTOR_VERSION not set"
50+
exit 1
51+
fi
52+
if [ -z "${PGVECTOR_BUILD_DIR}" ]; then
53+
info "PGVECTOR_BUILD_DIR not set"
54+
exit 1
55+
fi
56+
}
57+
58+
run_cmd() {
59+
local cmd
60+
cmd="$*"
61+
debug "cmd: $cmd"
62+
eval "$cmd"
63+
}
64+
65+
install() {
66+
# Download and extract the pgvector release, build the extension, and install it
67+
mkdir "${PGVECTOR_BUILD_DIR}"
68+
(
69+
cd "${PGVECTOR_BUILD_DIR}"
70+
curl -L -o pgvector.tar.gz "https://github.com/pgvector/pgvector/archive/refs/tags/v${PGVECTOR_VERSION}.tar.gz" && \
71+
tar -xzf pgvector.tar.gz && \
72+
cd "pgvector-${PGVECTOR_VERSION}" && \
73+
make && \
74+
make install
75+
)
76+
}
77+
78+
case "${1:-}" in
79+
help) help ;;
80+
install) install ;;
81+
*)
82+
abort=1
83+
error "Unknown command: $*"
84+
help
85+
;;
86+
esac

0 commit comments

Comments
 (0)