Skip to content

Commit d2110c4

Browse files
committed
copy renv cache in multi stage build
1 parent b7d316a commit d2110c4

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

Dockerfile.multistage

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,19 @@ COPY --from=builder /build/renv /app/renv
7373
COPY --from=builder /build/.Rprofile /app/.Rprofile
7474
COPY --from=builder /build/renv.lock /app/renv.lock
7575

76+
# Copy the renv cache (symlinks in renv/library point to this cache)
77+
COPY --from=builder /root/.cache/R/renv /root/.cache/R/renv
78+
7679
# Copy application code
7780
COPY --from=builder /build/app.R /app/app.R
7881

7982
# Expose Shiny port
8083
EXPOSE 3838
8184

8285
# Run the application
83-
CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]
86+
# Note: Use --vanilla to skip .Rprofile and avoid renv activation at runtime
87+
# The renv library path is already in R's search path
88+
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)"]
8489

8590
# ============================================================================
8691
# Build and Run Commands:

Dockerfile.single-stage

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ RUN R -e "renv::restore()"
3939
EXPOSE 3838
4040

4141
# Run the application
42-
CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]
42+
# Note: Use --vanilla to skip .Rprofile and avoid renv activation at runtime
43+
# The renv library path is already in R's search path
44+
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)"]

Dockerfile.three-stage

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ COPY --from=base /base/renv /app/renv
108108
COPY --from=base /base/.Rprofile /app/.Rprofile
109109
COPY --from=base /base/renv.lock /app/renv.lock
110110

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+
111114
# Copy custom packages from builder stage (if any were installed)
112115
# COPY --from=builder /usr/local/lib/R/site-library/mypackage /usr/local/lib/R/site-library/mypackage
113116

@@ -118,7 +121,9 @@ COPY --from=builder /build/app.R /app/app.R
118121
EXPOSE 3838
119122

120123
# Run the application
121-
CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]
124+
# Note: Use --vanilla to skip .Rprofile and avoid renv activation at runtime
125+
# 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)"]
122127

123128
# ============================================================================
124129
# Layer Optimization Strategy:

0 commit comments

Comments
 (0)