diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..33bd3ca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# TimescaleDB tools +FROM docker.io/library/golang:alpine AS timescaledb-tools + +RUN apk update && apk add --no-cache git gcc musl-dev \ + && go install github.com/timescale/timescaledb-tune/cmd/timescaledb-tune@latest \ + && go install github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy@latest + +# TimescaleDB extension +FROM docker.io/timescale/timescaledb:2.16.1-pg16-bitnami AS timescaledb + +# Copy the last 3 versions of the extension +RUN cd /opt/bitnami/postgresql/lib \ + && cp timescaledb.so /tmp \ + && cp -r $(ls . | grep timescaledb- | sort | tail -n 3) /tmp \ + && cp -r $(ls . | grep timescaledb-tsl- | sort | tail -n 3) /tmp \ + && cd /opt/bitnami/postgresql/share/extension \ + && cp -r $(ls . | grep timescaledb | grep .sql) /tmp + +# PostgreSQL Server +FROM docker.io/bitnami/postgresql:16.4.0 AS postgresql + +# TimescaleDB tools +COPY --from=timescaledb-tools /go/bin/* /usr/local/bin/ + +# TimescaleDB extension (We will install last 3 versions) +COPY --from=timescaledb /tmp/*.so /opt/bitnami/postgresql/lib/ + +# TimescaleDB upgrade and downgrade scripts +COPY --from=timescaledb /tmp/*.sql /opt/bitnami/postgresql/share/extension/ + +# TimescaleDB initialization scripts +COPY --from=timescaledb /docker-entrypoint-initdb.d/*.sh /docker-entrypoint-initdb.d/ + +# Entrypoint +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh + +ENTRYPOINT [ "docker-entrypoint.sh" ] +CMD [ "/opt/bitnami/scripts/postgresql/run.sh" ] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..c49427a --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# Load PostgeSQL environment variables and Bitnami Logging Libraty +. /opt/bitnami/scripts/postgresql-env.sh +. /opt/bitnami/scripts/liblog.sh + +# We have to use the bitnami configuration variable to add timescaledb to +# shared preload list, or else it gets overwritten. +if [ -z "$POSTGRESQL_SHARED_PRELOAD_LIBRARIES" ] +then + POSTGRESQL_SHARED_PRELOAD_LIBRARIES=timescaledb +else + POSTGRESQL_SHARED_PRELOAD_LIBRARIES="$POSTGRESQL_SHARED_PRELOAD_LIBRARIES,timescaledb" +fi +export POSTGRESQL_SHARED_PRELOAD_LIBRARIES + +# If it's already init, run timescaledb-tune again (to update the config if needed) +if [ -f "$POSTGRESQL_VOLUME_DIR/.user_scripts_initialized" ]; then + # Run timescaledb-tune script + info "Running timescaledb-tune to update the configuration..." + /docker-entrypoint-initdb.d/001_timescaledb_tune.sh + info "timescaledb-tune finished" +fi + +# Fall through to the original entrypoint. Note that we use exec here because +# this wrapper script shouldn't change PID 1 of the container. +exec "/opt/bitnami/scripts/postgresql/entrypoint.sh" "$@"