Skip to content

Commit 8884e39

Browse files
committed
layer immich-postgres ontop of postgres
1 parent 0fdfcbf commit 8884e39

1 file changed

Lines changed: 22 additions & 42 deletions

File tree

Containerfile

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
# PostgreSQL 14 with pgvector + VectorChord for Immich
1+
# Immich PostgreSQL - layers pgvector + VectorChord on top of postgres:14
22
# Drop-in compatible with official Immich PostgreSQL image
33

44
ARG BASE_VERSION=15
5+
ARG PG_VERSION=14
6+
7+
# Builder stage - compile extensions
58
FROM ghcr.io/daemonless/base:${BASE_VERSION} AS builder
9+
ARG PG_VERSION
610

7-
# Build dependencies for pgvector and VectorChord
8-
# FreeBSD-*-dev packages provide libraries needed for Rust linking
9-
# FreeBSD-toolchain provides ar for linking
11+
# Build dependencies
1012
RUN pkg update && pkg install -y \
11-
postgresql14-server postgresql14-contrib \
13+
postgresql${PG_VERSION}-server postgresql${PG_VERSION}-contrib \
1214
FreeBSD-bmake FreeBSD-clibs-dev FreeBSD-clang FreeBSD-clang-dev FreeBSD-toolchain \
1315
FreeBSD-libexecinfo FreeBSD-libexecinfo-dev FreeBSD-runtime-dev FreeBSD-utilities-dev \
1416
rust gmake git-lite pkgconf \
1517
&& pkg clean -ay
1618

1719
# Fetch minimal ports tree for pgvector
18-
RUN fetch -qo /tmp/ports.tar.gz \
19-
"http://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz" && \
20+
RUN fetch -qo /tmp/ports.tar.zst \
21+
"https://download.freebsd.org/ports/ports/ports.tar.zst" && \
2022
mkdir -p /usr/ports && \
21-
tar -xzf /tmp/ports.tar.gz -C /usr/ports --strip-components=1 \
23+
tar -xf /tmp/ports.tar.zst -C /usr/ports --strip-components=1 \
2224
ports/databases/pgvector ports/Mk ports/Templates ports/Keywords && \
23-
rm /tmp/ports.tar.gz
25+
rm /tmp/ports.tar.zst
2426

2527
# Build pgvector for PostgreSQL 14
2628
WORKDIR /usr/ports/databases/pgvector
27-
RUN make DEFAULT_VERSIONS+=pgsql=14 BATCH=yes install clean
29+
RUN make DEFAULT_VERSIONS+=pgsql=${PG_VERSION} BATCH=yes install clean
2830

29-
# Build VectorChord from source
31+
# Build VectorChord from source (not in ports)
3032
ARG VECTORCHORD_VERSION=0.4.3
3133
RUN fetch -qo /tmp/vectorchord.tar.gz \
3234
"https://github.com/tensorchord/VectorChord/archive/refs/tags/${VECTORCHORD_VERSION}.tar.gz" && \
@@ -35,12 +37,12 @@ RUN fetch -qo /tmp/vectorchord.tar.gz \
3537
gmake build && \
3638
gmake install
3739

38-
# Production image
39-
FROM ghcr.io/daemonless/base:${BASE_VERSION}
40+
# Production image - layer on postgres:14
41+
ARG PG_VERSION
42+
FROM localhost/postgres:${PG_VERSION}
4043

4144
ARG FREEBSD_ARCH=amd64
42-
ARG PKG_NAME=postgresql14-server
43-
ARG PACKAGES="postgresql14-server postgresql14-contrib"
45+
ARG VECTORCHORD_VERSION=0.4.3
4446

4547
LABEL org.opencontainers.image.title="Immich PostgreSQL" \
4648
org.opencontainers.image.description="PostgreSQL 14 with pgvector + VectorChord for Immich" \
@@ -51,40 +53,18 @@ LABEL org.opencontainers.image.title="Immich PostgreSQL" \
5153
org.opencontainers.image.authors="daemonless" \
5254
io.daemonless.port="5432" \
5355
io.daemonless.arch="${FREEBSD_ARCH}" \
54-
io.daemonless.config-mount="/config" \
5556
io.daemonless.category="Databases" \
56-
io.daemonless.pkg-name="${PKG_NAME}" \
57-
io.daemonless.packages="${PACKAGES}"
57+
io.daemonless.vectorchord-version="${VECTORCHORD_VERSION}"
5858

59-
# Install PostgreSQL, then remove LLVM JIT (saves ~2GB, JIT not needed for Immich)
60-
RUN pkg update && \
61-
pkg install -y ${PACKAGES} && \
62-
mkdir -p /app && pkg info postgresql14-server | sed -n 's/.*Version.*: *//p' > /app/version && \
63-
pkg delete -fy llvm19 perl5 python311 || true && \
64-
pkg autoremove -y || true && \
65-
pkg clean -ay && \
66-
rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
67-
68-
# Copy built extensions from builder and fix permissions
59+
# Copy built extensions from builder
6960
COPY --from=builder /usr/local/lib/postgresql/vector.so /usr/local/lib/postgresql/
7061
COPY --from=builder /usr/local/share/postgresql/extension/vector* /usr/local/share/postgresql/extension/
7162
COPY --from=builder /usr/local/lib/postgresql/vchord.so /usr/local/lib/postgresql/
7263
COPY --from=builder /usr/local/share/postgresql/extension/vchord* /usr/local/share/postgresql/extension/
64+
65+
# Fix permissions
7366
RUN chmod 644 /usr/local/share/postgresql/extension/vchord* && \
7467
chmod 755 /usr/local/lib/postgresql/vchord.so
7568

76-
# Create data directory
77-
RUN mkdir -p /config/data /run/postgresql && \
78-
chown -R bsd:bsd /config /run/postgresql
79-
80-
# Copy service files
81-
COPY root/ /
82-
RUN chmod +x /etc/services.d/*/run /etc/cont-init.d/* 2>/dev/null || true
83-
84-
ENV PGDATA=/config/data
85-
ENV POSTGRES_USER=postgres
86-
ENV POSTGRES_PASSWORD=postgres
69+
# Immich-specific defaults
8770
ENV POSTGRES_DB=immich
88-
89-
EXPOSE 5432
90-
VOLUME /config

0 commit comments

Comments
 (0)