Skip to content

Commit 65bae97

Browse files
author
Susan Vanderplas
committed
Buildkit caching
1 parent 2e5a7f3 commit 65bae97

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
env:
11+
DOCKER_BUILDKIT: 1
1112
NEWSAPI_KEY: ${{ secrets.NEWSAPI_KEY }}
1213
GH_APP_ID: ${{ secrets.GH_APP_ID }}
1314
GH_APP_SECRET: ${{ secrets.GH_APP_SECRET }}

Dockerfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# At the top
2-
ARG RENV_CACHE=/root/.local/share/renv
2+
ARG RENV_CACHE=/root/.cache/R/renv/
33
ARG PIP_CACHE=/root/.cache/pip
44

55
# Base image
66
FROM rocker/verse:latest
77

88
# Set environment variables so renv/pip use them
9+
ENV R_CACHE_DIR=/root/.cache/R/
910
ENV RENV_PATHS_CACHE=${RENV_CACHE}
1011
ENV PIP_CACHE_DIR=${PIP_CACHE}
1112

@@ -52,23 +53,23 @@ ENV DEBIAN_FRONTEND=noninteractive
5253
# RUN mkdir -p ${RENV_CACHE} ${PIP_CACHE}
5354

5455
# Install tinytex system-wide (for LaTeX support)
55-
RUN Rscript -e "install.packages('tinytex'); tinytex::install_tinytex(force=T)"
56+
RUN --mount=type=cache,target=${R_CACHE_DIR} Rscript -e "install.packages('tinytex'); tinytex::install_tinytex(force=T)"
5657

5758
# Install minimal R packages for system-level support
58-
RUN Rscript -e "install.packages(c('digest','devtools','renv','reticulate'))"
59+
RUN --mount=type=cache,target=${R_CACHE_DIR} Rscript -e "install.packages(c('digest','devtools','renv','reticulate','yaml'))"
5960

6061
# Copy renv.lock and renv directory for layer caching, install R dependencies via renv
6162
COPY renv.lock /project/renv.lock
6263
COPY renv /project/renv
63-
RUN R -e "renv::restore(lockfile = '/project/renv.lock', prompt = FALSE)"
64+
65+
# Restore R deps from renv.lock using persistent cache
66+
RUN --mount=type=cache,target=${R_CACHE_DIR} Rscript -e 'renv::restore(lockfile = '/project/renv.lock', prompt = FALSE)'
6467

6568
# Copy Python requirements file if exists (cached separately)
6669
COPY setup/requirements.txt ${REQ_FILE}
67-
RUN python3 -m venv /root/.virtualenvs/venv && \
70+
RUN --mount=type=cache,target=${PIP_CACHE_DIR} python3 -m venv /root/.virtualenvs/venv && \
6871
"${VENV_PATH}/bin/pip" install --cache-dir "${PIP_CACHE_DIR}" -r "${REQ_FILE}"
6972

70-
71-
7273
# Copy the rest of the project
7374
COPY . /project
7475
WORKDIR /project

0 commit comments

Comments
 (0)