Skip to content

Conversation

@Miggets7
Copy link
Contributor

Reduces some of the size.
#12

Consolidated multiple RUN commands into single layers to minimize image size. Combined apt-get operations with cleanup in one RUN statement. Added fd-find removal after use and comprehensive cleanup of docs, man pages, cache, and temp files. Reorganized multi-stage build with clearer stage comments and added final cleanup of copied PostgreSQL version directories.
…d binary stripping

Restructured Dockerfile to use multi-stage build pattern with pg-all stage for extracting PostgreSQL 14/15 binaries. Added strip operations to remove debug symbols from all PostgreSQL binaries and shared libraries. Removed unnecessary extension, man, doc, and contrib files from old PostgreSQL versions before copying. Consolidated cleanup operations into single RUN layer and added locale cleanup.
@Miggets7 Miggets7 requested a review from richturner December 18, 2025 14:09
@Miggets7 Miggets7 added the enhancement New feature or request label Dec 18, 2025
Copy link
Member

@richturner richturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great step in the right direction I think we should limit our images to only include the version of postgres used in our last major release so the idea is you can do rolling upgrades with the various tag versions if needed, we can cut more out of this image then.

Init script should check if old version is one supported.

Split build and push steps for both amd64 and arm64 architectures to use --load instead of --push, allowing slim toolkit to optimize images before pushing. Added slim toolkit installation and slimming steps that preserve all necessary PostgreSQL paths, libraries, and binaries while removing unused components. Fixed arm64 platform specification from linux/aarch64 to linux/arm64. Added build_and_slim.sh script for build and slimming
@Miggets7 Miggets7 requested a review from richturner January 8, 2026 14:32
@ebariaux ebariaux linked an issue Jan 12, 2026 that may be closed by this pull request
Copy link
Member

@richturner richturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If using a bash script then this should be reused by the github workflow to avoid duplication.
  • Is there any value in removing some of the TS versions from the build?
  • Don't know how slim works but hopefully there isn't something it has missed in its' optimisation also does it provide enough benefit to warrant the extra dependency vs. just manually deleting stuff out of the image
  • If sticking with a bash script then use --build-arg to pass PG_MAJOR to docker build otherwise there is a potential mismatch issue.

…cumentation

Extracted duplicated slim toolkit configuration from GitHub Actions workflow into shared slim-image.sh script. Updated build_and_slim.sh to use the shared script with architecture detection. Enhanced README with prerequisites, installation instructions, and detailed upgrade documentation including manual upgrade steps and useful resources. Improved error messages in or-entrypoint.sh to include documentation links for OpenRemote, PostgreSQL and TimescaleDB
@Miggets7
Copy link
Contributor Author

Miggets7 commented Jan 14, 2026

@richturner

Is there any value in removing some of the TS versions from the build?

Not sure, but no TS version gets removed? The Dockerfile uses timescale/timescaledb-ha base image which includes multiple TimescaleDB versions.

Don't know how slim works but hopefully there isn't something it has missed in its' optimisation also does it provide enough benefit to warrant the extra dependency vs. just manually deleting stuff out of the image

Slim is a tool that runs the container, monitors which files are actually accessed, and removes everything else. We whitelist specific paths (PostgreSQL dirs, shell utilities used by the entrypoint) to ensure nothing critical is removed.

Why slim vs alternatives:

  • Manual rm -rf in Dockerfile - Would require deep knowledge of all PostgreSQL/TimescaleDB runtime dependencies and ongoing maintenance as versions change. Doable but time-consuming and error-prone.

  • Scratch/distroless base - Would need to manually trace and copy every binary + all its shared library dependencies (ldd output). PostgreSQL has complex deps (locales, timezone data, SSL certs, etc.) plus our entrypoint uses many shell utilities. This would take a lot of time to get right and would be fragile.

Slim provides ~60% size reduction with minimal effort. The trade-off is an extra CI dependency (installed via one-liner script) and the risk of missing edge-case files - which we mitigate with explicit --include-path and --include-bin flags for known requirements.

@richturner richturner self-requested a review January 14, 2026 14:44
Copy link
Member

@richturner richturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just built image locally without slim and started the container with a 14.6.0.3 DB and the container doesn't start but I also don't get the expected error messages in docker logs, just see this:

/usr/bin/env: ‘bash\r’: No such file or directory

@richturner
Copy link
Member

Just built image locally without slim and started the container with a 14.6.0.3 DB and the container doesn't start but I also don't get the expected error messages in docker logs, just see this:

/usr/bin/env: ‘bash\r’: No such file or directory

Ignore I think this is a lie ending issue with gihub checkout

@richturner
Copy link
Member

I upgraded from 14.6.0.3 -> 15.6.0.4 the tried using this image and it fails:

------------------------------------
New database initialisation complete
------------------------------------
---------------------------------------
Running pg_upgrade command, from /var/lib/postgresql/data
---------------------------------------
Running pg_upgrade --check first...
Performing Consistency Checks
-----------------------------
Checking cluster versions                                     ok
Checking database user is the install user                    ok
Checking database connection settings                         ok
Checking for prepared transactions                            ok
Checking for contrib/isn with bigint-passing mismatch         ok
Checking data type usage                                      ok
Checking for not-null constraint inconsistencies              ok
Checking for presence of required libraries                   fatal

Your installation references loadable libraries that are missing from the
new installation.  You can add these libraries to the new installation,
or remove the functions using them from the old installation.  A list of
problem libraries is in the file:
    /var/lib/postgresql/data/new/pg_upgrade_output.d/20260115T122704.976/loadable_libraries.txt
Failure, exiting
Running actual pg_upgrade with --link...
Performing Consistency Checks
-----------------------------
Checking cluster versions                                     ok
Checking database user is the install user                    ok
Checking database connection settings                         ok
Checking for prepared transactions                            ok
Checking for contrib/isn with bigint-passing mismatch         ok
Checking data type usage                                      ok
Checking for not-null constraint inconsistencies              ok
Creating dump of global objects                               ok
Creating dump of database schemas                             ok
Checking for presence of required libraries                   fatal

Your installation references loadable libraries that are missing from the
new installation.  You can add these libraries to the new installation,
or remove the functions using them from the old installation.  A list of
problem libraries is in the file:
    /var/lib/postgresql/data/new/pg_upgrade_output.d/20260115T122705.758/loadable_libraries.txt
Failure, exiting

@richturner
Copy link
Member

Here's the loadable_libraries.txt output:

could not load library "$libdir/timescaledb-2.9.1": ERROR:  could not access file "$libdir/timescaledb-2.9.1": No such file or directory
In database: template1
In database: postgres
In database: openremote
could not load library "$libdir/timescaledb_toolkit-1.13.1": ERROR:  could not access file "$libdir/timescaledb_toolkit-1.13.1": No such file or directory
In database: template1
In database: postgres
In database: openremote

@richturner
Copy link
Member

I can see 2.9.1 in /usr/lib/postgresql/15/lib but not in /usr/lib/postgresql/17/lib don't know why the timescale upgrade didn't resolve this

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce docker image size

3 participants