Skip to content

Instantly share code, notes, and snippets.

@baronfel
Created May 16, 2019 23:27
Show Gist options
  • Save baronfel/7f87d0a6bdbeb3f2bf28803f4846af70 to your computer and use it in GitHub Desktop.
Save baronfel/7f87d0a6bdbeb3f2bf28803f4846af70 to your computer and use it in GitHub Desktop.
Postgres with plv8 dockerfile
# invoke with `docker build -t TAGNAME --build-arg POSTGRES_VERSION=11 --build-arg PLV8_VERSION=2.3.9 .`
# currently requires a minimum of plv8 2.3.9 to fix build issues
ARG POSTGRES_VERSION
FROM postgres:${POSTGRES_VERSION} as build
ARG PLV8_VERSION
# These deps come from the build instructions at https://plv8.github.io/#building-for-macos-linux
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-server-dev-$PG_MAJOR \
build-essential \
python \
git \
curl \
wget \
libc++-dev \
libc++abi-dev \
pkg-config \
ca-certificates \
# need certs in order to wget to github for the source tarball
&& update-ca-certificates
RUN wget https://github.com/plv8/plv8/archive/v${PLV8_VERSION}.tar.gz \
&& tar -xvzf v${PLV8_VERSION}.tar.gz
WORKDIR /plv8-${PLV8_VERSION}
# could run these as one command, but since we're copying out of this container anyway it didn't seem to make much sense
RUN make
# this command places the built files into the locations we copy from below, as well as using LLVM to create the `index` file we copy below
RUN make install
ARG POSTGRES_VERSION
FROM postgres:${POSTGRES_VERSION} as runtime
RUN apt-get update \
# v8 is compiled to use the system libc++1, and we bundle v8 as part of this component, so it needs to be installed
&& apt-get install -y libc++1 \
&& rm -rf /var/lib/apt/lists/*
ARG PLV8_VERSION
COPY --from=build /usr/lib/postgresql/${PG_MAJOR}/lib/plv8-${PLV8_VERSION}.so /usr/lib/postgresql/${PG_MAJOR}/lib/
COPY --from=build /usr/share/postgresql/${PG_MAJOR}/extension/plv8*.* /usr/share/postgresql/${PG_MAJOR}/extension/
COPY --from=build /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/plv8-${PLV8_VERSION} /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/plv8-${PLV8_VERSION}
COPY --from=build /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/plv8-${PLV8_VERSION}.index.bc /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/plv8-${PLV8_VERSION}.index.bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment