-
-
Save ishan-marikar/90ac10dc7c39ae2c1d4f051c8c69d1d8 to your computer and use it in GitHub Desktop.
Postgres Dockerfile with Custom Extensions using pgxn
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
## Alternatives: postgres:15-alpine | |
ARG BASE_IMAGE=postgis/postgis:15-3.4-alpine | |
## Custom Alpine Postgres docker file with custom extensions | |
FROM ${BASE_IMAGE} as builder | |
# Install required dependencies | |
RUN apk --no-cache add \ | |
python3 \ | |
py3-pip \ | |
cmake \ | |
make \ | |
gcc \ | |
g++ \ | |
clang15 \ | |
llvm15 \ | |
postgresql-dev \ | |
&& pip install pgxnclient | |
# Install extensions using pgxn | |
RUN pgxn install 'h3=4.1.3' \ | |
&& pgxn install 'vector=0.4.4' \ | |
&& pgxn install 'pg_uuidv7=1.3.0' | |
## Cleanup to reduce image size | |
RUN apk del \ | |
python3 \ | |
py3-pip \ | |
cmake \ | |
make \ | |
gcc \ | |
g++ \ | |
clang15 \ | |
llvm15 \ | |
postgresql-dev \ | |
&& rm -rf /var/cache/apk/* \ | |
&& rm -rf /root/.cache \ | |
&& rm -rf /root/.pgxn | |
## Custom Alpine Postgres docker file with our extensions | |
FROM ${BASE_IMAGE} | |
## Copy all extensions from the builder stage | |
COPY --from=builder /usr/local/lib/postgresql/* /usr/local/lib/postgresql/ | |
COPY --from=builder /usr/local/share/postgresql/extension/* /usr/local/share/postgresql/extension/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment