Skip to content

Commit dc386ae

Browse files
committed
perf(gnocchi): slim runtime image by ~50%
Cuts the Gnocchi container from ~4.8 GB uncompressed (1.6 GiB on GHCR) to roughly 2.5 GB by removing files and packages the service never uses at runtime. Changes - Strip unused Ceph libs from the dependency stage before they get copied into the runtime: librbd, librgw, libcephfs, libcephsqlite. Per upstream gnocchi setup.cfg the [ceph] extra has no python deps and only requires librados via python3-rados, so RBD, CephFS, and the RADOS gateway are dead weight (~1.3 GB). - Drop server packages that snuck into the runtime image: postgresql (server daemon — psycopg2 only needs libpq5, kept), memcached (server daemon — tooz uses pymemcache, kept), and the full ceph metapackage (replaced by librados from the dependency stage plus python3-rados, both kept). The PostgreSQL, memcached, and Ceph client paths are fully preserved. - Fix the no-op `apt-get purge -y --auto-remove` by passing an explicit BUILD_DEPS list (apache2-dev, build-essential, *-dev headers, pkg-config, python3-dev). These were previously installed to compile mod_wsgi and then never removed. - Drop runtime-irrelevant packages: git, wget, docutils-common, gettext, libjs-sphinxdoc, libjs-underscore. - Add `--no-cache-dir` to pip installs and clean /root/.cache, /tmp, and /var/tmp at the end of each stage. Not changed - ceph-libs base image (shared by other services, separate fix). - /usr/local/lib/ceph/ plugin tree is kept so librados can load erasure-code and compressor plugins for EC/compressed pools. - scripts/gnocchi-cve-patching.sh runs identically. - Trivy scanning workflow is untouched.
1 parent 01bb7b7 commit dc386ae

1 file changed

Lines changed: 20 additions & 34 deletions

File tree

ContainerFiles/gnocchi

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ARG OS_CONSTRAINTS=master
1010
RUN export DEBIAN_FRONTEND=noninteractive
1111
RUN curl -fsSL -o /tmp/upper-constraints.txt https://opendev.org/openstack/requirements/raw/branch/${OS_CONSTRAINTS}/upper-constraints.txt \
1212
&& sed -i '/^gnocchi===.*/d' /tmp/upper-constraints.txt \
13-
&& /var/lib/openstack/bin/pip install --constraint /tmp/upper-constraints.txt \
13+
&& /var/lib/openstack/bin/pip install -vvv --no-cache-dir --constraint /tmp/upper-constraints.txt \
1414
"gnocchi[postgresql,ceph,keystone,redis] @ git+https://github.com/gnocchixyz/gnocchi.git@${GNOCCHI_VERSION}" \
1515
gnocchiclient \
1616
PyMySQL \
@@ -23,12 +23,21 @@ RUN curl -fsSL -o /tmp/upper-constraints.txt https://opendev.org/openstack/requi
2323
COPY scripts/gnocchi-cve-patching.sh /opt/
2424
RUN bash /opt/gnocchi-cve-patching.sh
2525

26+
# Strip Ceph runtime libraries Gnocchi never uses. Per upstream setup.cfg the
27+
# `[ceph]` extra has no Python deps and relies on python3-rados, which only
28+
# needs librados. RBD (block device), CephFS, RGW (object gateway), and the
29+
# Ceph SQLite VFS are unrelated and account for ~1.3 GB on their own.
2630
RUN find / -name '*.pyc' -delete \
2731
&& find / -name '*.pyo' -delete \
2832
&& find / -name '__pycache__' -delete \
2933
&& find / -name '*.whl' -delete \
3034
&& rm -f /var/lib/openstack/lib/python*/site-packages/slapdtest/certs/client.key \
3135
&& rm -f /var/lib/openstack/lib/python*/site-packages/slapdtest/certs/server.key \
36+
&& rm -f /usr/local/lib/librbd.so* \
37+
&& rm -f /usr/local/lib/librgw.so* \
38+
&& rm -f /usr/local/lib/libcephfs.so* \
39+
&& rm -f /usr/local/lib/libcephsqlite.so* \
40+
&& rm -rf /root/.cache /tmp/* /var/tmp/* \
3241
&& for f in /var/lib/openstack/lib/python*/site-packages/PyJWT-*.dist-info/METADATA; do \
3342
if [ -f "$f" ]; then \
3443
sed -i '/^Usage/,/^Documentation\n^-.*$/d' "$f"; \
@@ -45,54 +54,31 @@ COPY --from=dependency_build /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu
4554
COPY --from=dependency_build /usr/lib/python3/dist-packages /usr/lib/python3/dist-packages
4655
COPY --from=dependency_build /var/lib/openstack /var/lib/openstack
4756
RUN export DEBIAN_FRONTEND=noninteractive \
57+
&& BUILD_DEPS="apache2-dev build-essential libffi-dev libldap2-dev libpq-dev libsasl2-dev libsnappy-dev libprotobuf-dev libssl-dev libsystemd-dev libxml2-dev libxslt1-dev librados-dev liberasurecode-dev pkg-config python3-dev" \
4858
&& apt-get update && apt-get upgrade -y \
4959
&& apt-get install --no-install-recommends -y \
5060
apache2 \
51-
apache2-dev \
61+
bash \
62+
brotli \
63+
curl \
5264
libffi8 \
5365
libpq5 \
5466
libsnappy1v5 \
5567
libxml2 \
68+
libxslt1.1 \
69+
locales \
5670
python3 \
57-
python3-dev \
5871
python3-memcache \
59-
bash \
60-
brotli \
61-
build-essential \
62-
curl \
63-
wget \
64-
locales \
65-
docutils-common \
66-
gettext \
67-
git \
68-
libffi-dev \
69-
libjs-sphinxdoc \
70-
libjs-underscore \
71-
libldap2-dev \
72-
libpq-dev \
73-
postgresql \
74-
memcached \
75-
librados-dev \
76-
liberasurecode-dev \
7772
python3-rados \
78-
ceph \
79-
libsasl2-dev \
80-
libsnappy-dev \
81-
libprotobuf-dev \
82-
libssl-dev \
83-
libsystemd-dev \
84-
libxml2-dev \
85-
libxslt1-dev \
86-
libxslt1.1 \
87-
pkg-config \
8873
ssl-cert \
8974
xmlsec1 \
90-
&& /var/lib/openstack/bin/pip install --upgrade mod_wsgi \
75+
$BUILD_DEPS \
76+
&& /var/lib/openstack/bin/pip install --no-cache-dir --upgrade mod_wsgi \
9177
&& /var/lib/openstack/bin/mod_wsgi-express module-config > /etc/apache2/mods-available/wsgi.load \
9278
&& a2enmod wsgi \
93-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
79+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
9480
&& apt-get clean -y \
95-
&& rm -rf /var/lib/apt/lists/* \
81+
&& rm -rf /var/lib/apt/lists/* /root/.cache /tmp/* /var/tmp/* \
9682
&& find / -name '*.pyc' -delete \
9783
&& find / -name '*.pyo' -delete \
9884
&& find / -name '__pycache__' -delete \

0 commit comments

Comments
 (0)