Skip to content

Commit

Permalink
feat: customized timescaledb docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazmi35 committed Oct 8, 2024
0 parents commit 0ae139e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
27 changes: 27 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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" "$@"

0 comments on commit 0ae139e

Please sign in to comment.