Skip to content

Instantly share code, notes, and snippets.

@cocowalla
Last active November 7, 2022 15:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocowalla/cd123d3fafb73c3ac0343a4494ef45b7 to your computer and use it in GitHub Desktop.
Save cocowalla/cd123d3fafb73c3ac0343a4494ef45b7 to your computer and use it in GitHub Desktop.
TimescaleDB on debian stretch-slim
# Docker image for PostgreSQL with the TimescaleDB extensions installed, running on a Debian Stretch-Slim base
# Begin by building TimescaleDB
FROM postgres:11.2 AS build
ENV TIMESCALEDB_VERSION 1.2.2
ENV TIMESCALEDB_SHASUM="c8e8071c24707e3fa8a50abb788c85d03a1bd9d9dea2e273b4abf407f39c182a timescaledb-${TIMESCALEDB_VERSION}.tar.gz"
RUN buildDeps="curl build-essential ca-certificates git python gnupg libc++-dev libc++abi-dev pkg-config glib2.0 cmake libssl-dev" \
&& apt-get update \
&& apt-get install -y --no-install-recommends ${buildDeps} \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& apt-get update \
&& apt-get install -y --no-install-recommends postgresql-server-dev-$PG_MAJOR \
&& mkdir -p /tmp/build \
&& curl -o /tmp/build/timescaledb-${TIMESCALEDB_VERSION}.tar.gz -SL "https://github.com/timescale/timescaledb/releases/download/${TIMESCALEDB_VERSION}/timescaledb-${TIMESCALEDB_VERSION}.tar.gz" \
&& cd /tmp/build \
&& echo ${TIMESCALEDB_SHASUM} | sha256sum -c \
&& tar -xzf /tmp/build/timescaledb-${TIMESCALEDB_VERSION}.tar.gz -C /tmp/build/ \
&& cd /tmp/build/timescaledb \
&& ./bootstrap \
&& cd build \
&& make \
&& make install \
&& strip /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb.so \
&& strip /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-${TIMESCALEDB_VERSION}.so \
&& strip /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-tsl-${TIMESCALEDB_VERSION}.so \
&& cd / \
&& rm -rf /tmp/build \
&& apt-get remove -y --purge ${buildDeps} \
&& apt-get autoremove -y --purge \
&& rm -rf /var/lib/apt/lists/*
# Copy the extension build output into an image based on postgres on debian stretch-slim
FROM postgres:11.2
LABEL description="PostgreSQL with the TimescaleDB extension installed"
ENV TIMESCALEDB_VERSION 1.2.2
COPY --from=build /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb.so /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb.so
COPY --from=build /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-${TIMESCALEDB_VERSION}.so /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-${TIMESCALEDB_VERSION}.so
COPY --from=build /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-tsl-${TIMESCALEDB_VERSION}.so /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-tsl-${TIMESCALEDB_VERSION}.so
COPY --from=build /usr/share/postgresql/${PG_MAJOR}/extension/timescaledb.control /usr/share/postgresql/${PG_MAJOR}/extension/timescaledb.control
COPY --from=build /usr/share/postgresql/${PG_MAJOR}/extension/timescaledb--${TIMESCALEDB_VERSION}.sql /usr/share/postgresql/${PG_MAJOR}/extension/timescaledb--${TIMESCALEDB_VERSION}.sql
RUN apt-get update \
&& apt-get install -y --no-install-recommends libc++1 \
&& rm -rf /var/lib/apt/lists/* \
&& chmod 0755 /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb.so \
&& chmod 0755 /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-${TIMESCALEDB_VERSION}.so \
&& chmod 0755 /usr/lib/postgresql/${PG_MAJOR}/lib/timescaledb-tsl-${TIMESCALEDB_VERSION}.so \
&& chmod 0644 /usr/share/postgresql/${PG_MAJOR}/extension/timescaledb.control \
&& chmod 0644 /usr/share/postgresql/${PG_MAJOR}/extension/timescaledb--${TIMESCALEDB_VERSION}.sql \
&& echo 'CREATE EXTENSION timescaledb;' > /docker-entrypoint-initdb.d/timescaledb.sql
@skoschik
Copy link

skoschik commented Jun 3, 2019

Nice image.
I think line 31 should be
&& apt-get remove -y --purge ${buildDeps} \

@cocowalla
Copy link
Author

@skoschik good catch, it's updated now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment