-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDockerfile
More file actions
132 lines (112 loc) · 4.91 KB
/
Dockerfile
File metadata and controls
132 lines (112 loc) · 4.91 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Build with docker buildx build -t book-image .
#### Stage 1: Linux, R, python, LaTeX, Java ####################################
FROM rocker/r-ver:4.5 AS bookbase
ENV DEBIAN_FRONTEND=noninteractive
ENV RENV_PATHS_CACHE=/root/.cache/R/renv
ENV PIP_CACHE_DIR=/root/.cache/pip
ENV RETICULATE_PYTHON_ENV=venv
# --- Layer 1: OS deps (cacheable with BuildKit) and GH CLI
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
apt-get update \
&& apt-get install -y --no-install-recommends \
libgit2-dev libx11-dev pandoc \
# python
python3 python3-pip python3-venv python3-dev \
# curl/xml
libcurl4-openssl-dev libssl-dev libxml2-dev curl gnupg ca-certificates \
# java
default-jdk default-jre r-cran-rjava \
# odbc
unixodbc unixodbc-dev \
# fonts
libharfbuzz-dev libfribidi-dev \
# s2
libabsl-dev cmake \
# tesseract
libtesseract-dev libpoppler-cpp-dev tesseract-ocr \
# graphics
libleptonica-dev libpng-dev libjpeg-dev libtiff-dev imagemagick libfontconfig1-dev\
# gdal
gdal-bin libgdal-dev \
# secrets
libsecret-1-dev \
# units
libglpk-dev libudunits2-dev \
# R pkgs
&& install2.r --error --deps TRUE \
RJDBC odbc devtools digest tinytex quarto rmarkdown yaml rstudioapi renv reticulate \
# GH CLI
&& curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
| dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
> /etc/apt/sources.list.d/github-cli.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends gh \
&& rm -rf /var/lib/apt/lists/* \
# Quarto CLI
&& curl -fsSL https://quarto.org/download/latest/quarto-linux-amd64.deb -o /tmp/quarto.deb \
&& apt-get update \
&& apt-get install -y --no-install-recommends /tmp/quarto.deb \
&& rm -f /tmp/quarto.deb \
&& rm -rf /var/lib/apt/lists/* \
# Tinytex
&& Rscript -e "tinytex::install_tinytex(force=T)" \
# Ensure cache dirs exist
&& mkdir -p ${RENV_PATHS_CACHE} ${PIP_CACHE_DIR} /root/.virtualenvs
ENV JAVA_HOME=/usr/lib/jvm/default-java/
ENV PATH="${JAVA_HOME}/bin:${PATH}"
ENV LD_LIBRARY_PATH="${JAVA_HOME}/lib/server"
#### Stage 2: Python packages ##################################################
FROM bookbase AS bookpy
# Install python packages into venv
# Copy requirements from project root to tmp
COPY setup/requirements.txt /tmp/requirements.txt
# Add venv to path
ENV VENV_PATH=/opt/venv
# Register venv globally for R/reticulate and Quarto
ENV PATH="$VENV_PATH/bin:$PATH"
ENV RETICULATE_PYTHON=$VENV_PATH/bin/python
ENV QUARTO_PYTHON=$VENV_PATH/bin/python
#echo "=== Checking pip cache path ===" \
# && ls -lah ${PIP_CACHE_DIR} || echo "pip cache dir not found" \
# && echo "=== Restoring Python packages into baked-in venv ===" \
# Create venv
RUN python3 -m $RETICULATE_PYTHON_ENV $VENV_PATH \
# Make sure pip is up to date and install common build tools
&& $VENV_PATH/bin/pip install --upgrade pip setuptools wheel ipykernel \
&& $VENV_PATH/bin/python -m ipykernel install --prefix=/usr/local --name=$RETICULATE_PYTHON_ENV --display-name "(${RETICULATE_PYTHON_ENV})" \
&& $VENV_PATH/bin/pip install --cache-dir ${PIP_CACHE_DIR} -r /tmp/requirements.txt
#### Stage 3: R packages #######################################################
FROM bookpy AS bookrpy
# Install R packages from renv cache
# Copy renv lockfile from project root to tmp
ENV RENV_PATH=/opt/renv
ENV RENV_PATHS_CACHE=/root/.local/share/renv
COPY renv.lock /tmp/renv.lock
COPY .Rprofile /tmp/.Rprofile
# install R packages
RUN Rscript -e "renv::restore(lockfile = '/tmp/renv.lock', library=Sys.getenv('RENV_PATH'), prompt = FALSE)"
#echo "=== Checking renv cache path ===" \
# && ls -lah ${RENV_PATHS_CACHE} || echo "renv cache dir not found" \
# # Check packages in cache
# && echo "=== Package count in renv cache after restore ===" \
# && Rscript -e \'cat(length(list.files(Sys.getenv("RENV_PATHS_CACHE"), recursive=TRUE)), "packages in cache\n")\'
#### Stage 4: R + Py + Base ###################################################
FROM bookrpy AS bookbuild
ENV JAVA_HOME=/usr/lib/jvm/default-java/
ENV PATH="${JAVA_HOME}/bin:${PATH}"
ENV LD_LIBRARY_PATH="${JAVA_HOME}/lib/server"
# Add venv to path
ENV VENV_PATH=/opt/venv
ENV PIP_CACHE_DIR=/root/.cache/pip
ENV RENV_PATH=/opt/renv
ENV RENV_PATHS_CACHE=/root/.local/share/renv
# Register venv globally for R/reticulate and Quarto
ENV PATH="$VENV_PATH/bin:$PATH"
ENV RETICULATE_PYTHON=$VENV_PATH/bin/python
ENV QUARTO_PYTHON=$VENV_PATH/bin/python
WORKDIR /project
# Default command: render and publish
CMD ["/bin/sh","-c","quarto publish --no-browser --no-prompt"]