Skip to content

Conversation

@featheredtoast
Copy link
Member

@featheredtoast featheredtoast commented May 18, 2025

web_only images would not install postgres or redis, minimizing image sizes for setups that do not require those components.

release and dev images still install postgres and redis, but do it later in the process.

A savings of ~80MB compressed (~260MB uncompressed)

current slim: 576.66MB release: 967.01MB. new slim: 496.74MB release: 969.13MB

@featheredtoast featheredtoast force-pushed the add-web-only-image branch 3 times, most recently from f16457d to e016fc8 Compare May 18, 2025 16:20
web_only images do not install postgres or redis, minimizing image sizes for
setups that do not require those components.

release and dev images still install postgres and redis, but do it later in the
process.

remove rm runs

rm no longer affects image sizes as we are no longer squashing images
ADD thpoff.c /src/thpoff.c
RUN gcc -o /usr/local/sbin/thpoff /src/thpoff.c && rm /src/thpoff.c

# clean up for docker squash
Copy link
Member Author

Choose a reason for hiding this comment

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

We no longer use docker squash - that has been gone for a long time. Here, we now desire /tmp to stick around as a way of keeping /tmp/install-redis around for installing later within a build for discourse-dev.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could delete these after the RUN command that generates them to keep the image small.

Copy link
Member Author

Choose a reason for hiding this comment

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

The other option we have is to add a tmpfs have a for these during the build.

Note that I'm keeping /tmp around to ensure install-redis remains as needed - it's called in both this image as well as the dev image.

ADD install-jemalloc /tmp/install-jemalloc
RUN /tmp/install-jemalloc

ADD install-redis /tmp/install-redis
Copy link
Member

Choose a reason for hiding this comment

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

This can be moved too.

Copy link
Member Author

@featheredtoast featheredtoast May 21, 2025

Choose a reason for hiding this comment

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

We'd need a way to add it to the dev image as well when we build that, as that also needs to be able to run install-redis in a different context.

My concern with copying is that any changes to install-redis could get out of sync in an update.

Probably a preferred solution or way forward that would allow is to give a shared context, IE reorganize things so all dockerfiles live under a common directory. base.dockerfile dev.dockerfile test.dockerfile etc. but I'd prefer that reorganization be left for a potential future refactor stage.

ADD thpoff.c /src/thpoff.c
RUN gcc -o /usr/local/sbin/thpoff /src/thpoff.c && rm /src/thpoff.c

# clean up for docker squash
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could delete these after the RUN command that generates them to keep the image small.

@featheredtoast featheredtoast requested a review from nbianca June 20, 2025 19:25
@featheredtoast
Copy link
Member Author

@nbianca any update here?

@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/how-can-i-minimize-the-discourse-docker-image-size/378249/2

@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/daily-summary-9pm-utc/291850/589

@featheredtoast featheredtoast merged commit f2a4bca into main Aug 13, 2025
5 checks passed
@featheredtoast featheredtoast deleted the add-web-only-image branch August 13, 2025 19:54
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.

5 participants