Skip to content

Remove ~25 MB of unnecessary packages from Docker image#100

Merged
nitrobass24 merged 1 commit intodevelopfrom
chore/slim-docker-image
Feb 28, 2026
Merged

Remove ~25 MB of unnecessary packages from Docker image#100
nitrobass24 merged 1 commit intodevelopfrom
chore/slim-docker-image

Conversation

@nitrobass24
Copy link
Owner

@nitrobass24 nitrobass24 commented Feb 28, 2026

Summary

  • Replace p7zip + p7zip-full with 7zip — saves ~2.9 MB. The 7zip package provides 7zz, which patoolib 4.x supports natively. Added 7z → 7zz symlink for compatibility.
  • Replace gosu with setpriv — saves ~2.2 MB. setpriv is already available via util-linux (a base package).
  • Remove pytz, use stdlib datetime.timezone.utc — saves ~2.8 MB. Only 2 test files imported pytz; no runtime code uses it.
  • Remove pip + setuptools after install — saves ~16 MB. No runtime code needs pip or setuptools.

Estimated total savings: ~24 MB (184.7 MB → ~160 MB)

Test plan

  • make build — Docker image builds successfully
  • make run — container starts with correct UID/GID handling (validates setpriv)
  • Web UI loads at http://localhost:8800
  • In-container: 7zz --help and 7z --help (symlink) work
  • In-container: unrar works
  • In-container: which gosu returns nothing, which pip returns nothing
  • Image size check: docker image inspect --format '{{.Size}}' shows ~160 MB

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Optimized container runtime: replaced 7zip packaging, added compatible symlink, and removed an unneeded runtime dependency.
    • Switched execution helper for running processes in the container to a more minimal tool.
  • Dependencies

    • Removed pytz and migrated uses to the Python standard library timezone utilities.
  • Bug Fixes

    • Improved configuration parsing: boolean parsing replaced with an internal parser and empty-string handling now preserves None for None-default fields.
  • Tests

    • Updated tests to use standard timezone objects and reflect config behavior changes.

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

Warning

Rate limit exceeded

@nitrobass24 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 42 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0577995 and db4287d.

📒 Files selected for processing (9)
  • Makefile
  • src/docker/build/docker-image/Dockerfile
  • src/docker/build/docker-image/entrypoint.sh
  • src/python/common/config.py
  • src/python/pyproject.toml
  • src/python/requirements.txt
  • src/python/tests/unittests/test_common/test_config.py
  • src/python/tests/unittests/test_web/test_serialize/test_serialize_model.py
  • src/python/tests/unittests/test_web/test_serialize/test_serialize_status.py
📝 Walkthrough

Walkthrough

Replaced runtime packages and privilege helper in Docker, removed pytz from Python deps and migrated tests to datetime.timezone, and introduced an internal boolean parser replacing distutils.util.strtobool with corresponding test updates for empty-string handling.

Changes

Cohort / File(s) Summary
Docker runtime & entrypoint
src/docker/build/docker-image/Dockerfile, src/docker/build/docker-image/entrypoint.sh
Swapped p7zip/p7zip-full for 7zip, added /usr/bin/7zz symlink, removed RAR codec setup and gosu, added pip uninstall for pip/setuptools in image build, and replaced gosu usage with setpriv for running the final command as the resolved user.
Python dependency files
src/python/pyproject.toml, src/python/requirements.txt
Removed pytz from Poetry dependencies and requirements.txt.
Tests — timezone migration
src/python/tests/unittests/test_web/test_serialize/test_serialize_model.py, src/python/tests/unittests/test_web/test_serialize/test_serialize_status.py
Replaced pytz.timezone('UTC') imports/uses with datetime.timezone/timezone.utc in timestamp constructions and updated imports accordingly.
Config implementation & tests
src/python/common/config.py, src/python/tests/unittests/test_common/test_config.py
Added internal _strtobool to replace distutils.util.strtobool in Converters.bool; adjusted config parsing so empty strings for None-default fields are treated as missing (round-trip preserves None), and updated tests to match the new empty-string handling semantics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibbled old deps, setpriv did the trick,
7zz hops in, gosu's gone quick.
Timezones now from datetime's tree,
Configs parsed kindly, clean and free. 🎩

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the primary objective: reducing Docker image size by removing unnecessary packages. It directly reflects the main changes across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/slim-docker-image

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/docker/build/docker-image/Dockerfile`:
- Around line 59-66: The RUN step in the Dockerfile currently always runs ln -s
/usr/bin/7zz /usr/bin/7z which will fail if /usr/bin/7z already exists; update
that part of the RUN command (the same line that currently ends with ln -s
/usr/bin/7zz /usr/bin/7z) to be idempotent by checking for the target first,
e.g. replace the plain ln call with a conditional like [ -e /usr/bin/7z ] || ln
-s /usr/bin/7zz /usr/bin/7z (or use ln -sf if you prefer to force overwrite), so
the build won't fail when /usr/bin/7z is already present.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4cb1ea7 and 86bd9b5.

📒 Files selected for processing (6)
  • src/docker/build/docker-image/Dockerfile
  • src/docker/build/docker-image/entrypoint.sh
  • src/python/pyproject.toml
  • src/python/requirements.txt
  • src/python/tests/unittests/test_web/test_serialize/test_serialize_model.py
  • src/python/tests/unittests/test_web/test_serialize/test_serialize_status.py
💤 Files with no reviewable changes (2)
  • src/python/pyproject.toml
  • src/python/requirements.txt

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/python/common/config.py`:
- Around line 15-23: In _strtobool, replace the old %-formatting in the
exception with an f-string for consistency with modern Python; specifically
change the raise ValueError("invalid truth value %r" % (val,)) to use f-string
formatting such as raise ValueError(f"invalid truth value {val!r}") so the
message remains identical but follows current style.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86bd9b5 and 0577995.

📒 Files selected for processing (2)
  • src/python/common/config.py
  • src/python/tests/unittests/test_common/test_config.py

Comment on lines +15 to +23
def _strtobool(val: str) -> bool:
val = val.strip().lower()
if val in ('y', 'yes', 't', 'true', 'on', '1'):
return True
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
return False
else:
raise ValueError("invalid truth value %r" % (val,))

Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Good replacement for distutils.util.strtobool.

The implementation correctly handles the same boolean tokens as the original distutils.util.strtobool, which is necessary since setuptools/distutils are being removed from the Docker image.

One minor style improvement flagged by static analysis: consider using f-string formatting instead of % formatting for consistency with modern Python.

✨ Optional: Use f-string formatting
-        raise ValueError("invalid truth value %r" % (val,))
+        raise ValueError(f"invalid truth value {val!r}")
🧰 Tools
🪛 Ruff (0.15.2)

[warning] 22-22: Use format specifiers instead of percent format

Replace with format specifiers

(UP031)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/python/common/config.py` around lines 15 - 23, In _strtobool, replace the
old %-formatting in the exception with an f-string for consistency with modern
Python; specifically change the raise ValueError("invalid truth value %r" %
(val,)) to use f-string formatting such as raise ValueError(f"invalid truth
value {val!r}") so the message remains identical but follows current style.

- Replace p7zip + p7zip-full (5.4 MB) with 7zip (2.5 MB)
- Replace gosu (2.2 MB) with setpriv (already in util-linux)
- Remove pytz (2.8 MB), use stdlib datetime.timezone.utc instead
- Remove pip + setuptools (~16 MB) after dependency installation
- Replace distutils.util.strtobool with inline implementation
- Fix 6 pre-existing config test failures (round-trip guard behavior)
- Install lftp and openssh-client in test container for unit tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant