Skip to content

Instantly share code, notes, and snippets.

@ItsWendell
Created October 22, 2023 09:58
Show Gist options
  • Select an option

  • Save ItsWendell/af2e2b4c93bb2f5d73f34b87406af435 to your computer and use it in GitHub Desktop.

Select an option

Save ItsWendell/af2e2b4c93bb2f5d73f34b87406af435 to your computer and use it in GitHub Desktop.

Revisions

  1. ItsWendell created this gist Oct 22, 2023.
    46 changes: 46 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@

    ## 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/