Repository navigation
[Docker] Slim the server image from 3.37 GB to 1.13 GB - #2224
Conversation
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]>
|
This is an exploration. I am running convergence tests now, but it looks like we can trim the docker image by a lot. |
|
I built the current image using this slimmed down version. It is currently up on dockerhub |
|
/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]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[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.
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]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[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.
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]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[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.
|
/review |
PR Checklist
docsis updatedDescription 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/chownafterCOPYrewrites 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.COPY --chown --chmod=550, avoiding a recursive permission-change layer. Explicitly set$HOMEto 550 after the final copy; this changes one directory, not the artifact tree.$HOME.server/packageandcli/package.jlinkruntime 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.gcompat: the new standalone Delta read exposed an amd64 Snappy JNI failure becauseld-linux-x86-64.so.2was missing. Keep the read test rather than dropping that coverage.dev/, andetc/. 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.$HOMEand build artifacts are mode 550;etc/andetc/confare 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/andtarget/remain because the classpaths reference them. The linked Java runtime still includes tools such asjavacandkeytool, but lacksjmods, so downstream builds that need a full JDK should use a separate build stage. This is documented indocs/docker_compose.md, under "Server image contents".Validation
bin/uc catalog list, and an actual Delta read ofunity.default.numbers.gcompatreproduces the missing-loader Snappy error.$HOME, and failed table read all fail the step; containers are removed, and server-file logs are emitted on failure.helm testwith H2, PostgreSQL, and MySQL. All passed, including the MySQL JDBC driver loaded via--module-path.helm test, the UI page, and its/apiproxy 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.helm lint, the workflow's non-default chart rendering assertions,actionlint,build/sbt -info javafmtAll, andgit 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
bundlejar is still roughly 612 MB, from the CLI'shadoop-awsdependency. 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.