Skip to content

Commit

Permalink
Use a multistage build to reduce image size
Browse files Browse the repository at this point in the history
  • Loading branch information
r-ash committed Dec 30, 2024
1 parent 05ab6f9 commit 94d77fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 27 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
FROM ghcr.io/hivtools/naomi-base:minimal
FROM naomi-base:main AS stage1

COPY . /src
COPY docker/Rprofile.site /usr/local/lib/R/etc/Rprofile.site
COPY docker/bin /usr/local/bin/
COPY docker/Rprofile.site /usr/local/lib/R/etc/Rprofile.site

## Remove the large test data not needed for runtime
RUN install_packages remotes \
&& install_remote mrc-ide/naomi \
&& rm -r /usr/local/lib/R/site-library/naomi/extdata

RUN cd /src \
&& ./scripts/build_test_data \
WORKDIR /src
RUN ./scripts/build_test_data \
&& find /src/inst/output -type f ! -name "malawi_model_output.qs" -delete \
&& R CMD INSTALL /src \
&& rm -r /src

FROM rocker/r-ver:4 AS stage2

## Install just the runtime-dependencies
RUN apt-get update && apt-get -y install --no-install-recommends \
libudunits2-0 \
libhiredis1.1.0 \
libjq1 \
libsodium23 \
libssl3 \
gdal-bin \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*

COPY --from=stage1 /usr/local/lib/R/site-library /usr/local/lib/R/site-library
COPY --from=stage1 /usr/local/bin /usr/local/bin
COPY --from=stage1 /usr/bin/pandoc /usr/bin/pandoc

EXPOSE 8888
ENV HINTR_QUEUE_ID=hintr

Expand Down
2 changes: 1 addition & 1 deletion docker/Rprofile.site
Original file line number Diff line number Diff line change
@@ -1 +1 @@
options(knitr.chunk.dev = 'svglite')
options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/__linux__/noble/latest'), download.file.method = 'libcurl')

0 comments on commit 94d77fd

Please sign in to comment.