Skip to content

Separate builders for build tools, drop some unused library dependencies#994

Open
featheredtoast wants to merge 11 commits into
mainfrom
superslim-base
Open

Separate builders for build tools, drop some unused library dependencies#994
featheredtoast wants to merge 11 commits into
mainfrom
superslim-base

Conversation

@featheredtoast
Copy link
Copy Markdown
Member

@featheredtoast featheredtoast commented Aug 14, 2025

Separate out builders for thpoff, jemalloc and oxipng/jhead
Copy over the results of all libraries to reduce dependencies
for base image needing build tools.

drop extra -dev packages from base image as we only need the nginx runtime libs.

refactor parallel stop without parallel package

mount tmpfs for apt caches
remove unreferenced libtcmalloc

reorganize gem dependencies

@featheredtoast featheredtoast marked this pull request as ready for review August 14, 2025 07:04
@featheredtoast featheredtoast force-pushed the superslim-base branch 3 times, most recently from 75ae8e3 to 7d9e6fe Compare August 19, 2025 20:16
@featheredtoast featheredtoast changed the title Remove build tools from base image Separate builders for build tools, drop some unused library dependencies Aug 19, 2025
Comment thread image/base/sbin/boot
for pid in $ORPHANS; do
(timeout 5 /bin/bash -c "kill $pid && wait $pid" 2>/dev/null || kill -9 $pid 2>/dev/null) &
done
wait
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you know what the history is with this? Why are we killing ORPHANS in the first place? Unclean shutdown feels out of scope for this script and ought to be handled one level up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's related to how docker/launcher interacted with the containers previously, but I don't have history other than the note in git history:

FIX: force all sub processes to stop on TERM, wait for them to finish
This works around docker bug where containers will not stop

Change here attempted to remove parallel without rocking the boat too much on lifecycle.

Comment thread image/base/Dockerfile

RUN --mount=type=tmpfs,target=/var/log \
--mount=type=tmpfs,target=/var/cache/apt \
--mount=type=tmpfs,target=/var/lib/apt \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know what the lifecycle of this container is. Are we potentially increasing the RAM usage for every Discourse here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, this Dockerfile is only done by the builder for building the base dependencies image. All Discourse images /containers build or run later don't inherit a tmpfs from this.

The idea here is just to have an image that is clear of apt caches on downstream images.

We used to do this back in the day by doing a later RUN rm-all-caches and flattening image layers, but tmpfs is the way to achieve this now for directories we don't want saved in a final image.

*Cache mounting for apt is also given as an example on Docker's docs page as well.

Comment thread image/base/Dockerfile
gawk anacron wget \
psmisc whois brotli \
pngcrush pngquant ripgrep poppler-utils \
catdoc antiword \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pulling and labelling the sections below is awesome. Should we do the same with the preceding as # discourse runtime requirements?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've added it - Just for full transparency, I initially didn't label the first block above as it's less clear to me as to exactly what is a hard discourse requirement (I'm not so sure about a Discourse hard requirement on fping, gawk, psmisc, ripgrep, or whois for example).
Some are known for container boot (anacron, wget, gnupg, sudo, curl).
Others I know are Discourse requirements - pngcrush, pngquant, poppler-utils, catdoc, antiword.

It's possible there's crossover.

Comment thread image/base/Dockerfile Outdated
COPY --from=thpoff_builder /usr/local/sbin/thpoff /usr/local/sbin
COPY --from=jemalloc_builder /usr/lib/libjemalloc.so /usr/lib
COPY --from=oxipng_builder /usr/local/bin/jhead /usr/local/bin
COPY --from=oxipng_builder /usr/local/bin/oxipng /usr/local/bin
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bikeshed: Infrastructure convention is to use hyphens instead of underscores in these names.

@featheredtoast
Copy link
Copy Markdown
Member Author

@andrewschleifer updated 👍

Separate out builders for thpoff, jemalloc and oxipng/jhead
Copy over the results of all libraries to reduce dependencies
for base image needing build tools.
Remove the dependency on parallel for two commands
drop -dev packages for nginx compilation now that this is separate
..and remove extra cmake reference, this is already in a line above
Build in arm vs amd64 acts a bit differently - arm builds to libjemalloc.so.2
and symlinks whereas amd64 does not.

build and copy over library directly to /usr/lib/libjemalloc.so in both cases.
Add comment for Discourse dependencies, as best I can put.
updating name to dashes, run ruby lint
Allows for an image to potentially build from discourse-runtime-dependencies

Evict all of the built-time tools from a discourse-runtime-dependencies target
Rename new target to discourse-runtime-base to better reflect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants