-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
68 lines (52 loc) · 1.62 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Stage 1: Build base image and install dependencies
FROM rocker/r-ver:4.4.1 AS base
# Set environment variables
ENV WORKDIR=/project
ENV RENV_VERSION=1.0.7
ENV RENV_PATHS_LIBRARY=${WORKDIR}/renv/library
ENV RENV_PATHS_CACHE=${WORKDIR}/renv/.cache
# Install system dependencies
RUN apt-get update && apt-get install -y \
cmake \
libcurl4-openssl-dev \
libmbedtls-dev \
libssl-dev \
libxml2-dev \
tree \
xz-utils \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR ${WORKDIR}
FROM base as builder
# Install specific version of renv
RUN R -e "install.packages('renv', repos='https://cloud.r-project.org', type='source', version='${RENV_VERSION}')"
# Copy renv files
# https://rstudio.github.io/renv/articles/docker.html
COPY renv.lock renv.lock
COPY .Rprofile .Rprofile
RUN mkdir -p renv
COPY renv/activate.R renv/activate.R
COPY renv/settings.json renv/settings.json
# Change default location of cache to project folder
RUN mkdir ${RENV_PATHS_CACHE}
RUN mkdir ${RENV_PATHS_LIBRARY}
# Restore R packages using renv
RUN R -e "renv::restore()"
# Stage 2: final image with application code
FROM base as runner
# Set the working directory
WORKDIR ${WORKDIR}
# Copy files from builder stage
COPY --from=builder ${WORKDIR} .
# Copy project files
COPY _targets.R _targets.R
COPY R R
COPY run.R run.R
RUN mkdir -p data
# Mount the _targets directory as a volume
VOLUME ${WORKDIR}/_targets
# Restore R packages from the builder stage's cache
# TODO renv would install again within the runner stage?
# RUN R -e "renv::restore()"
# Command to run the targets pipeline
CMD ["Rscript", "--verbose", "run.R"]