Files
Cyril Rohr d482f1f708 Fix docker bloat (#21948)
* Refactor Docker build/runtime stages for slimmer images

Split runtime and build dependencies into separate stages and build the app in a dedicated stage before runtime copy.

Add a slim prune stage that removes non-runtime source trees, source maps, duplicate enterprise source videos, module test/doc folders, and extra vendored gem artifacts.

This ensures bytes are removed before the final slim copy, so layer size actually decreases while keeping runtime behavior intact.

* Add target-specific Docker image validation in CI

Introduce script/ci/docker_validate_image.sh with validations for slim, slim-bim, and all-in-one images.

Checks include runtime binary presence/absence, plugin asset/module integrity, slim pruning expectations, BIM tooling, and all-in-one API startup/embedded services.

Update docker workflow to run the validator for every matrix target before push.

* fix

* Generate YAML-safe auto Hocuspocus secret

All-in-one startup auto-generates OPENPROJECT_COLLABORATIVE__EDITING__HOCUSPOCUS__SECRET in the entrypoint.

Environment overrides are parsed through YAML, so leading punctuation in the previous charset (e.g. %) could trigger Psych parsing errors and abort boot.

Restrict generated secret characters to alphanumeric to keep parsing stable while preserving high entropy.

* Fix all-in-one hocuspocus runtime and validation

* Fix all-in-one memcached startup handover
2026-02-11 10:40:54 +01:00

39 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -euxo pipefail
APP_PATH=${APP_PATH:-/app}
# Remove source-only trees that are not needed for slim runtime images.
rm -rf \
"$APP_PATH/spec" \
"$APP_PATH/screenshots" \
"$APP_PATH/lookbook" \
"$APP_PATH/frontend"
# Keep precompiled enterprise media in public/assets and remove duplicate source videos.
if [ -d "$APP_PATH/public/assets/enterprise" ]; then
rm -rf "$APP_PATH/app/assets/videos/enterprise"
fi
# Source maps are useful during development, but unnecessary in slim runtime images.
find "$APP_PATH/public/assets" -type f -name '*.map' -delete
# Lookbook source is removed above, so its compiled static assets are unnecessary too.
rm -rf "$APP_PATH/public/assets/lookbook"
# Module test and documentation folders are not used at runtime.
find "$APP_PATH/modules" -mindepth 2 -maxdepth 2 -type d \
\( -name spec -o -name test -o -name tests -o -name doc -o -name docs \) \
-prune -exec rm -rf '{}' +
# Remove leftover git metadata and common non-runtime folders from vendored git gems.
for gem_root in "$APP_PATH/vendor/bundle"/ruby/*/gems "$APP_PATH/vendor/bundle"/ruby/*/bundler/gems; do
[ -d "$gem_root" ] || continue
rm -rf "$gem_root"/*/.git
rm -rf "$gem_root"/*/{doc,docs,example,examples,benchmark,benchmarks}
done
# Remove static/object files left by native builds.
find "$APP_PATH/vendor/bundle" -type f \( -name '*.a' -o -name '*.o' \) -delete