-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
137 lines (121 loc) · 5.14 KB
/
Dockerfile
File metadata and controls
137 lines (121 loc) · 5.14 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
133
134
135
136
137
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# ============================================================
# STAGE 1: Install ALL system dependencies FIRST
# ============================================================
# This must happen before Conda to ensure R compiles against
# system libraries, not conda libraries
RUN set -eux; \
# retry apt-get update a few times in case mirrors are mid-sync
for i in 1 2 3; do \
apt-get update && break; \
echo "apt-get update failed, retrying ($i/3)..."; \
sleep 5; \
done; \
apt-get install -y --no-install-recommends \
# Basic utilities
wget ca-certificates gnupg software-properties-common \
dirmngr locales git \
# R compilation dependencies
build-essential gfortran \
libxml2-dev \
libglpk-dev \
libgmp-dev \
libblas-dev \
liblapack-dev \
libcurl4-openssl-dev \
libssl-dev \
libfontconfig1-dev \
libfreetype6-dev \
libharfbuzz-dev \
libfribidi-dev \
libpng-dev \
libtiff5-dev \
libjpeg-dev \
# Chrome dependencies (for Kaleido/plotly)
fonts-liberation \
libasound2t64 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatspi2.0-0 \
libcups2 \
libdbus-1-3 \
libgbm1 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libvulkan1 \
libxcomposite1 \
libxdamage1 \
libxkbcommon0 \
libxrandr2 \
xdg-utils && \
locale-gen en_GB.UTF-8 && \
rm -rf /var/lib/apt/lists/*
# Set locale environment variables for Python and other tools
ENV LANG=en_GB.UTF-8
ENV LC_ALL=en_GB.UTF-8
ENV PYTHONIOENCODING=utf-8
# ============================================================
# STAGE 2: Install R from CRAN
# ============================================================
RUN wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | \
gpg --dearmor -o /usr/share/keyrings/r-project.gpg && \
echo "deb [signed-by=/usr/share/keyrings/r-project.gpg] https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/" \
> /etc/apt/sources.list.d/r-project.list && \
apt-get update && \
apt-get install -y --no-install-recommends r-base r-base-dev && \
rm -rf /var/lib/apt/lists/*
# ============================================================
# STAGE 3: Install Quarto
# ============================================================
RUN wget -qO /tmp/quarto.deb https://quarto.org/download/latest/quarto-linux-amd64.deb && \
apt-get update && \
apt-get install -y /tmp/quarto.deb && \
rm /tmp/quarto.deb && \
rm -rf /var/lib/apt/lists/*
# ============================================================
# STAGE 4: Install Google Chrome (required by Kaleido for plotly)
# ============================================================
RUN wget -O /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt-get update && \
apt-get install -y --no-install-recommends /tmp/chrome.deb && \
rm /tmp/chrome.deb && \
rm -rf /var/lib/apt/lists/*
# ============================================================
# STAGE 5: Install Miniconda (use explicit paths, not PATH)
# ============================================================
ENV CONDA_DIR=/opt/conda
RUN wget -qO /tmp/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
bash /tmp/miniconda.sh -b -p "$CONDA_DIR" && \
rm /tmp/miniconda.sh
RUN $CONDA_DIR/bin/conda config --system --set always_yes yes && \
$CONDA_DIR/bin/conda config --system --set changeps1 no
# ============================================================
# STAGE 6: Set up project and create conda environment
# ============================================================
WORKDIR /workspace
COPY . /workspace
RUN rm -f /workspace/.Renviron
# Accept Anaconda ToS for required channels (non-interactive)
RUN $CONDA_DIR/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
$CONDA_DIR/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
# Create conda environment using explicit path (NOT in PATH yet)
RUN $CONDA_DIR/bin/conda env create -f environment.yaml
# ============================================================
# STAGE 7: Install R packages WITHOUT conda in PATH
# ============================================================
# CRITICAL: R package compilation must happen with system
# libraries, NOT conda libraries in PATH
ENV RENV_PATHS_LIBRARY=/workspace/renv/library
RUN Rscript -e "install.packages('renv', repos = 'https://cloud.r-project.org')" && \
Rscript -e "renv::restore()"
# ============================================================
# STAGE 8: Activate conda environment for RUNTIME only
# ============================================================
# Now that R packages are installed, it's safe to add conda to PATH
ENV CONDA_DEFAULT_ENV=des-rap-book
ENV PATH="/opt/conda/envs/des-rap-book/bin:${PATH}"
ENV RETICULATE_PYTHON=/opt/conda/envs/des-rap-book/bin/python
RUN echo "conda activate des-rap-book" >> /root/.bashrc
CMD ["/bin/bash"]