From 190d26d12f417170ffe1880206ad58cf34a5ce23 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Mon, 17 Aug 2026 17:33:51 +0100 Subject: [PATCH] Further optimised Dockerfiles to reduce final image size --- Dockerfiles/murfey-instrument-server | 21 +++++++---- Dockerfiles/murfey-server | 52 +++++++++++++++------------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/Dockerfiles/murfey-instrument-server b/Dockerfiles/murfey-instrument-server index ac909bb57..b3c50b894 100644 --- a/Dockerfiles/murfey-instrument-server +++ b/Dockerfiles/murfey-instrument-server @@ -5,7 +5,9 @@ FROM docker.io/library/python:3.12-slim-bookworm AS base # Install Vim in base image -RUN apt-get update && \ +RUN \ + echo "Setting up base image..." && \ + apt-get update && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends \ rsync \ @@ -17,8 +19,11 @@ RUN apt-get update && \ # Build Murfey in a branch image FROM base as build -COPY ./ /python-murfey/ -RUN apt-get update && \ + +RUN \ + --mount=type=bind,source=.,target=/mnt/python-murfey,U \ + echo "Installing build dependencies..." && \ + apt-get update && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends \ build-essential \ @@ -27,12 +32,14 @@ RUN apt-get update && \ libpq-dev \ && \ busybox --install && \ + echo "Installing Murfey..." && \ + cp -r /mnt/python-murfey /tmp/python-murfey && \ python -m venv /venv && \ /venv/bin/python -m pip install --upgrade \ pip \ build \ importlib-metadata && \ - /venv/bin/python -m pip install /python-murfey[sxt] + /venv/bin/python -m pip install /tmp/python-murfey[sxt] # Transfer completed Murfey build to base image @@ -44,10 +51,10 @@ ARG groupname ARG userid # Copy completed Murfey build across and set user and group permissions -COPY --from=build /venv/ /venv/ -RUN groupadd -r -g "${groupid}" "${groupname}" && \ +COPY --from=build --chown="${userid}":"${groupid}" /venv/ /venv/ +RUN \ + groupadd -r -g "${groupid}" "${groupname}" && \ useradd -r -M "${groupname}" -u "${userid}" -g "${groupname}" && \ - chown -R "${userid}":"${groupid}" /venv && \ chmod -R a+x /venv ENV PATH=/venv/bin:$PATH USER "${userid}":"${groupid}" diff --git a/Dockerfiles/murfey-server b/Dockerfiles/murfey-server index b44a1b6d1..2cbf18a5d 100644 --- a/Dockerfiles/murfey-server +++ b/Dockerfiles/murfey-server @@ -5,12 +5,13 @@ FROM docker.io/library/python:3.12-slim-bookworm AS base # Install Vim and PostgreSQL dependencies in base image -RUN apt-get update && \ +RUN \ + echo "Setting up base image..." && \ + apt-get update && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends \ libpq-dev \ - vim \ - && \ + vim && \ apt-get autoremove && \ rm -rf /var/lib/apt/lists/* @@ -18,35 +19,38 @@ RUN apt-get update && \ # Build Murfey and IMOD in a branch image FROM base as build -# Set up build argumentss for this stage ARG IMOD_INSTALLER=imod_5.1.9_RHEL8-64_CUDA12.0.sh - -COPY ./ /python-murfey/ -RUN apt-get update && \ +RUN \ + --mount=type=bind,source=.,target=/mnt/python-murfey,U \ + echo "Installing build dependencies..." && \ + apt-get update && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends \ build-essential \ busybox \ curl \ - net-tools \ - && \ + net-tools && \ busybox --install && \ + echo "Installing Murfey..." && \ + cp -r /mnt/python-murfey /tmp/python-murfey && \ python -m venv /venv && \ /venv/bin/python -m pip install --upgrade \ pip \ build \ importlib-metadata \ - psycopg2-binary \ - && \ - /venv/bin/python -m pip install /python-murfey[server] && \ - if [ ! -f /python-murfey/installers/${IMOD_INSTALLER} ]; then \ + psycopg2-binary && \ + /venv/bin/python -m pip install /tmp/python-murfey[server] && \ + echo "Installing IMOD..." && \ + mkdir /imod && \ + if [ -f /mnt/python-murfey/installers/${IMOD_INSTALLER} ]; then \ + bash "/mnt/python-murfey/installers/${IMOD_INSTALLER}" -dir /imod -skip -y; \ + else \ echo "IMOD installer not found; downloading..."; \ - curl https://bio3d.colorado.edu/imod/AMD64-RHEL5/${IMOD_INSTALLER} > /python-murfey/installers/${IMOD_INSTALLER}; \ - fi && \ - chmod +x /python-murfey/installers/${IMOD_INSTALLER} && \ - mkdir imod && \ - /python-murfey/installers/${IMOD_INSTALLER} -dir imod -skip -y - + curl -L \ + -o "/tmp/${IMOD_INSTALLER}" \ + https://bio3d.colorado.edu/imod/AMD64-RHEL5/${IMOD_INSTALLER}; \ + bash "/tmp/${IMOD_INSTALLER}" -dir /imod -skip -y; \ + fi # Transfer completed builds to base image FROM base @@ -57,12 +61,12 @@ ARG groupname ARG userid # Copy completed Murfey and IMOD builds across and set user and group permissions -COPY --from=build /venv/ /venv/ -COPY --from=build /imod/ /imod/ -RUN groupadd -r -g "${groupid}" "${groupname}" && \ +COPY --from=build --chown="${userid}":"${groupid}" /venv/ /venv/ +COPY --from=build --chown="${userid}":"${groupid}" /imod/ /imod/ +RUN \ + groupadd -r -g "${groupid}" "${groupname}" && \ useradd -r -M "${groupname}" -u "${userid}" -g "${groupname}" && \ - chown -R "${userid}":"${groupid}" /venv && \ - chmod -R a+x /venv + chmod -R a+x /venv /imod ENV PATH=/venv/bin:/imod/IMOD/bin:$PATH ENV IMOD_DIR=/imod/IMOD USER "${userid}":"${groupid}"