1717# ============================================================================
1818# STAGE 1: Base - CRAN packages and build environment
1919# ============================================================================
20- FROM rocker/r-ver:4.4.3 AS base
20+ FROM rocker/r2u:24.04 AS base
21+
22+ # Configure renv cache to use the same path as runtime
23+ # This ensures symlinks remain valid when copied to runtime stage
24+ ENV RENV_PATHS_CACHE="/app/renv/.cache"
2125
2226# Install system dependencies needed for compilation AND runtime
2327# Build tools are needed here to compile CRAN packages
@@ -35,7 +39,7 @@ RUN apt-get update && apt-get install -y \
3539 libjpeg-dev \
3640 && rm -rf /var/lib/apt/lists/*
3741
38- WORKDIR /base
42+ WORKDIR /app
3943
4044# OPTIMIZATION 1: Copy only dependency files first
4145# This creates a cache-friendly layer that only rebuilds when CRAN dependencies change
@@ -84,7 +88,10 @@ COPY app.R app.R
8488# ============================================================================
8589# STAGE 3: Runtime - Pure application (NO build tools)
8690# ============================================================================
87- FROM rocker/r-ver:4.4.3
91+ FROM rocker/r2u:24.04
92+
93+ # Configure renv cache location to match where packages were installed
94+ ENV RENV_PATHS_CACHE="/app/renv/.cache"
8895
8996# Install ONLY runtime system dependencies (no -dev packages, no build tools)
9097# Note: Using minimal runtime libraries without -dev packages
@@ -103,13 +110,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
103110
104111WORKDIR /app
105112
106- # Copy CRAN packages from base stage
107- COPY --from=base /base/renv /app/renv
108- COPY --from=base /base/.Rprofile /app/.Rprofile
109- COPY --from=base /base/renv.lock /app/renv.lock
110-
111- # Copy the renv cache (symlinks in renv/library point to this cache)
112- COPY --from=base /root/.cache/R/renv /root/.cache/R/renv
113+ # Copy CRAN packages from base stage (includes cache at /app/renv/.cache)
114+ COPY --from=base /app/renv /app/renv
115+ COPY --from=base /app/.Rprofile /app/.Rprofile
116+ COPY --from=base /app/renv.lock /app/renv.lock
113117
114118# Copy custom packages from builder stage (if any were installed)
115119# COPY --from=builder /usr/local/lib/R/site-library/mypackage /usr/local/lib/R/site-library/mypackage
@@ -123,7 +127,7 @@ EXPOSE 3838
123127# Run the application
124128# Note: Use --vanilla to skip .Rprofile and avoid renv activation at runtime
125129# The renv library path is already in R's search path
126- CMD ["R", "--vanilla", "-e", ".libPaths('/app/renv/library/linux-ubuntu-noble/R-4.4 /x86_64-pc-linux-gnu'); shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]
130+ CMD ["R", "--vanilla", "-e", ".libPaths('/app/renv/library/linux-ubuntu-noble/R-4.5 /x86_64-pc-linux-gnu'); shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]
127131
128132# ============================================================================
129133# Layer Optimization Strategy:
0 commit comments