Skip to content

[Docker] Slim the server image from 3.37 GB to 1.13 GB - #2224

Merged
newfront merged 6 commits into
unitycatalog:mainfrom
newfront:feat/uc-docker-slim
Nov 18, 2026
Merged

newfront merged 6 commits into
unitycatalog:mainfrom
newfront:feat/uc-docker-slim

Conversation

@newfront

@newfront newfront commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

Related issue: #2236

The server image is 3.37 GB uncompressed (2.77 GB compressed). Its build artifacts are stored twice: recursive chmod/chown after COPY rewrites every file into another 1.54 GB layer. It also ships the whole coursier cache and source trees, even though the launchers use only the server and CLI classpaths.

This brings the arm64 image to 1.133 GB uncompressed (about 875 MB compressed) while retaining the server and bin/uc. The launchers are unchanged.

  • Create the service user first, pinning uid 100 and gid 101 to match the Helm chart. Set artifact ownership and mode with COPY --chown --chmod=550, avoiding a recursive permission-change layer. Explicitly set $HOME to 550 after the final copy; this changes one directory, not the artifact tree.
  • Stage only the server/CLI classpath files, their entries, and the two source files the launchers use as source-tree markers. Preserve their absolute build paths and fail the build if any path is outside $HOME.
  • Build only server/package and cli/package.
  • Use a jlink runtime without jmods, headers, or man pages (285 MB to 202 MB). Keep all JDK modules, including ones used by drivers added at deployment time, and retain CDS. Verify the runtime trust store is byte-identical to the build JDK's.
  • Install Alpine's gcompat: the new standalone Delta read exposed an amd64 Snappy JNI failure because ld-linux-x86-64.so.2 was missing. Keep the read test rather than dropping that coverage.
  • Expand the Helm workflow's path filter to cover all Dockerfile inputs and the launchers, including build files, sources, dev/, and etc/. Strengthen its standalone smoke step to assert uid/gid, directory modes and writability, catalog output, and actual Delta rows. An EXIT trap prints container/server-file logs on failure and always removes the container.

Compatibility and documentation

HOME, JAVA_HOME, uid/gid, startup command, launchers, and configuration paths are unchanged. $HOME and build artifacts are mode 550; etc/ and etc/conf are mode 755 and owned by the service user. Chart-mounted configuration remains writable by uid 100 / gid 101.

The image is not a development environment: it no longer contains complete source trees, API specifications, sbt/build scripts, or the full dependency cache. Some generated paths under clients/ and target/ remain because the classpaths reference them. The linked Java runtime still includes tools such as javac and keytool, but lacks jmods, so downstream builds that need a full JDK should use a separate build stage. This is documented in docs/docker_compose.md, under "Server image contents".

Validation

  • Built the full Dockerfile for arm64 natively and amd64 under emulation on Colima.
  • Ran the updated standalone CI smoke step against both architectures: service-user permissions, bin/uc catalog list, and an actual Delta read of unity.default.numbers.
  • Confirmed a control amd64 image without gcompat reproduces the missing-loader Snappy error.
  • Negative smoke checks: a missing CLI source marker, writable $HOME, and failed table read all fail the step; containers are removed, and server-file logs are emitted on failure.
  • On a dedicated arm64 kind v0.33.0 / Kubernetes v1.37.0 cluster: installed the packaged chart and ran helm test with H2, PostgreSQL, and MySQL. All passed, including the MySQL JDBC driver loaded via --module-path.
  • Upgraded the H2 release to include the legacy UI; helm test, the UI page, and its /api proxy passed. Catalog metadata survived server pod restarts on all three databases, and H2 retained the same catalog ID and schema across the restart and chart upgrade.
  • Ran helm lint, the workflow's non-default chart rendering assertions, actionlint, build/sbt -info javafmtAll, and git diff --check.

The local corporate network required CA trust in the kind node and temporary npm/Maven mirror overrides for the UI build and MySQL driver download. Those workstation-specific files and certificates are not committed. The kind runtime tests were arm64; amd64 was verified with the standalone image, not an amd64 Kubernetes cluster.

Further size work

The AWS SDK v2 bundle jar is still roughly 612 MB, from the CLI's hadoop-aws dependency. Replacing that bundle changes the CLI's dependencies outside Docker too, so it belongs in a separate PR.

This pull request and its description were written by Isaac.

The runtime stage stored its build artifacts twice: the recursive chmod and
chown that ran after the COPY rewrote every file into a second 1.54 GB
layer. It also copied the whole coursier cache (sbt, Scala, and the
connectors' Spark and Delta dependencies) and the source trees, though the
launchers load only the server and CLI classpaths.

- Create the service user first, and set owner and mode in the COPY with
  --chown and --chmod=550, so no later layer rewrites the files.
- Stage only the server and CLI classpath files, their entries, and the
  source files bin/start-uc-server and bin/uc check, at their build paths.
- Ship a jlink runtime with every JDK module and a CDS archive, without
  jmods, headers, or man pages (285 MB to 202 MB). Every module stays
  because the Helm chart loads the MySQL driver with
  --add-modules=ALL-MODULE-PATH.
- Build only server/package and cli/package.

Ownership, modes, and uid 100 / gid 101 (the Helm chart's fsGroup) match
the previous image. Compressed size goes from 2.77 GB to 875 MB.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Scott Haines <[email protected]>
@newfront
newfront requested a review from yili-db November 13, 2026 00:55
@newfront

Copy link
Copy Markdown
Collaborator Author

This is an exploration. I am running convergence tests now, but it looks like we can trim the docker image by a lot.

@newfront

Copy link
Copy Markdown
Collaborator Author

@newfront

Copy link
Copy Markdown
Collaborator Author

/review

…n CI

Addresses the review of the slimmed image:

- Pin uid 100 and gid 101, which the Helm chart's fsGroup and its chown of
  etc/conf expect, instead of relying on Alpine's allocation order.
- Fail the build when a classpath path is outside $HOME, since the runtime
  stage copies only $HOME and the server would otherwise fail at startup.
- Check that the jlink runtime keeps the JDK's trust store, and say why it
  keeps every module: a missing one fails only on the code path that loads
  it, including drivers added at deploy time.
- Run the image without the chart in the Helm workflow, which builds it on
  every Dockerfile change: the server starts as its user, and bin/uc lists
  catalogs and reads a Delta table. The chart mounts etc/conf and the
  database, so it doesn't check the image's own files and modes.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Scott Haines <[email protected]>
@newfront
newfront marked this pull request as ready for review November 14, 2026 01:33
@yili-db

yili-db commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[AI Assisted] Verdict: comment, no blockers. The slimmed runtime matches what the Helm chart and the launchers expect: uid and gid 100:101, the paths under /home/unitycatalog, the command, and the staged classpath and source-file checks. Most inline comments are about the new CI step, which claims more than it checks, and the path filter, which leaves the image unguarded for changes to build.sbt, bin/ and the server and CLI sources. Items 1, 2 and 4 are worth addressing before merge; the rest are nits or optional. Item 4 is a mode claim that does not hold: $HOME is 755, not 550. I checked it with a minimal two-stage reproduction using the same adduser and COPY pattern. etc/ is 755 in both the old and new images, so nothing changes there, and the released image's write access for the service user is unchanged apart from $HOME.

Comment thread .github/workflows/helm-chart-tests.yml Resolved
Comment thread .github/workflows/helm-chart-tests.yml Resolved
Comment thread .github/workflows/helm-chart-tests.yml Resolved
Comment thread Dockerfile Resolved
Comment thread Dockerfile Resolved
Comment thread Dockerfile Resolved
Comment thread Dockerfile Resolved
Address the review of unitycatalog#2224 and the file-backend CI failure. Snappy's
amd64 JNI library needs ld-linux-x86-64.so.2, so include Alpine gcompat
rather than dropping the standalone Delta read test.

Assert the image's uid/gid, home and configuration permissions, catalog
output, and actual Delta rows. Always clean up the smoke container and
print its server-file log on failure. Trigger the workflow for all server
image inputs, including the launchers and build configuration.

Set only the home directory's mode explicitly after COPY, preserving 550
without another recursive artifact layer. Document the reduced image
contents and clarify the staging and group-permission comments.

Verified full arm64 and amd64 builds and standalone smoke tests; local
kind chart installs and helm tests for H2, PostgreSQL, and MySQL; UI/API
proxy, catalog persistence after server rollouts, negative smoke cases,
chart rendering checks, actionlint, and javafmtAll.

Signed-off-by: Scott Haines <[email protected]>
Co-authored-by: Isaac <[email protected]>
@newfront
newfront requested a review from openinx as a code owner November 15, 2026 21:14
@yili-db

yili-db commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[AI Assisted] Re-review of 8a20872: most earlier findings are addressed, and the javac question I raised was wrong (the docs are accurate). Two normal items remain: the failure logs cannot be read from an exited container, and the exact 755 assertion depends on the host umask. The rest are nits or optional.

Comment thread Dockerfile Resolved
Comment thread Dockerfile Resolved
Comment thread .github/workflows/helm-chart-tests.yml Resolved
Comment thread .github/workflows/helm-chart-tests.yml Resolved
Comment thread .github/workflows/helm-chart-tests.yml Resolved
Comment thread docs/docker_compose.md Resolved
Comment thread docs/docker_compose.md Resolved
Address the re-review of unitycatalog#2224.

- The smoke step's cleanup reads etc/logs/server.log with docker cp, which
  also works on an exited container. docker exec failed after a startup
  crash, and the container was then removed with the only log.
- Set etc/ and etc/conf to 755 next to $HOME's 550. COPY gives them the
  build context's modes, so a checkout made with umask 002 produced 775
  and failed the step's exact-mode check. Only the three directories
  change, so no layer stores the artifacts again.
- Put each permission assertion on its own line: under sh -e, a failing
  term before the last in an AND list does not stop the script. Drop the
  ! -w "$HOME" check, which the 550 check already covers.
- Describe the image's current contents in the docs, and call the build
  artifacts read-only by default, since their owner can change the mode.

Verified on arm64 and amd64 builds from 755 and 775 contexts: the step
passes, prints server.log after a startup crash, fails on each broken
permission, and leaves no container. helm test passes on the H2,
PostgreSQL, and MySQL releases in a local kind cluster.

Signed-off-by: Scott Haines <[email protected]>
Co-authored-by: Isaac <[email protected]>
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[AI Assisted] All earlier items are addressed. I verified the new Dockerfile tail and the smoke-step checks with a throwaway docker repro, and the USER item is accepted as a follow-up. One optional nit is inline and does not block approval.

Comment thread .github/workflows/helm-chart-tests.yml Resolved
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

@newfront
newfront merged commit 9a99a64 into unitycatalog:main Nov 18, 2026
23 checks passed
@newfront newfront linked an issue Nov 19, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docker] Reduce the size of the Unity Catalog image.

2 participants