Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
260 lines (230 loc) · 8.75 KB
/
Copy pathDockerfile
File metadata and controls
260 lines (230 loc) · 8.75 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
FROM rocker/ml-verse:4.3.2
LABEL maintainer="John Flournoy <jcflournoyphd@pm.me>"
ENV CMDSTANVER="2.35.0" \
DEBIAN_FRONTEND="noninteractive" \
NVIDIA_VISIBLE_DEVICES="all" \
NVIDIA_DRIVER_CAPABILITIES="compute,utility"
WORKDIR /cmdstan
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common \
&& add-apt-repository -y universe \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
wget ca-certificates perl xz-utils tar make g++ htop \
libudunits2-dev libproj-dev libgdal-dev \
ocl-icd-libopencl1 opencl-headers ocl-icd-opencl-dev clinfo \
fonts-dejavu-core fonts-dejavu-extra fonts-firacode \
liblapacke-dev libopenblas-dev \
curl gnupg fontconfig gettext-base \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Use bash for all subsequent RUNs (safer for && chains and pipefail)
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# ========================================
# Node.js Installation (LTS version 22.x)
# ========================================
# Remove old Node.js packages from base image to avoid conflicts
RUN apt-get update \
&& apt-get remove -y nodejs libnode-dev libnode72 || true \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Node.js 22.x from NodeSource
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
&& apt-get install -y nodejs \
&& node --version \
&& npm --version \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install global npm packages for development
RUN npm install -g \
npm@latest \
eslint \
typescript \
ts-node \
&& npm cache clean --force
# Ensure rstudio user can use npm global packages
ENV NPM_CONFIG_PREFIX=/home/rstudio/.npm-global
ENV PATH="/home/rstudio/.npm-global/bin:${PATH}"
# Create npm-global directory with proper permissions
RUN mkdir -p /home/rstudio/.npm-global \
&& chown -R rstudio:rstudio /home/rstudio/.npm-global
# ========================================
# VS Code Server / code-server (optional)
# ========================================
# Uncomment if you want code-server bundled in the image
# ENV CODE_SERVER_VERSION="4.96.2"
# RUN curl -fsSL https://code-server.dev/install.sh | sh \
# && code-server --version
# ========================================
# TeX Live Configuration
# ========================================
ENV TL_YEAR=2026
ENV TL_ROOT="/usr/local/texlive/${TL_YEAR}"
ENV PATH="${TL_ROOT}/bin/x86_64-linux:${PATH}"
# Provide the TeX Live profile as a tracked file
# (Create this file in your repo next to the Dockerfile)
COPY texlive.profile /tmp/texlive.profile.in
# Install upstream TeX Live and core packages via tlmgr
RUN set -eux \
&& wget -qO /tmp/install-tl-unx.tar.gz https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz \
&& mkdir -p /tmp/install-tl \
&& tar -xzf /tmp/install-tl-unx.tar.gz -C /tmp/install-tl --strip-components=1 \
&& envsubst < /tmp/texlive.profile.in > /tmp/texlive.profile \
&& /tmp/install-tl/install-tl -profile /tmp/texlive.profile \
&& rm -rf /tmp/install-tl* /tmp/install-tl-unx.tar.gz \
&& ln -sf ${TL_ROOT}/bin/x86_64-linux/* /usr/local/bin/ \
&& tlmgr install \
latexmk csquotes \
standalone \
siunitx physics \
adjustbox collectbox \
titlesec tabu \
libertinus-fonts inconsolata newtx \
&& mktexlsr
# Give rstudio permission to update the system TeX Live tree
RUN groupadd -r texlive \
&& usermod -a -G texlive rstudio \
&& chgrp -R texlive ${TL_ROOT} \
&& find ${TL_ROOT} -type d -exec chmod 2775 {} + \
&& find ${TL_ROOT} -type f -exec chmod g+rw {} +
# ========================================
# CmdStan Installation
# ========================================
RUN mkdir -p /etc/OpenCL/vendors && \
echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd
RUN Rscript -e "if (!requireNamespace('remotes')) { \
install.packages('remotes') \
}; \
cpp_options <- list( \
\"STAN_CPP_OPTIMS=true\", \
\"CXXFLAGS+= -O3 -march=native -mtune=native\", \
\"CXXFLAGS+= -DEIGEN_USE_BLAS -DEIGEN_USE_LAPACKE\", \
\"LDLIBS += -lblas -llapack -llapacke\" \
); \
install.packages(\"cmdstanr\", repos = c(\"https://mc-stan.org/r-packages/\", getOption(\"repos\"))); \
cmdstanr::install_cmdstan(\"/cmdstan\", version = \"${CMDSTANVER}\", cores = 4, cpp_options = cpp_options); \
cmdstanr::cmdstan_path(); \
"
ENV CMDSTAN /cmdstan/cmdstan-${CMDSTANVER}
COPY make_local ${CMDSTAN}/make/local
RUN chmod a+w -R ${CMDSTAN}
RUN Rscript -e "remotes::install_github('paul-buerkner/brms'); \
install.packages(\"posterior\"); \
file <- file.path(cmdstanr::cmdstan_path(), \"examples\", \"bernoulli\", \"bernoulli.stan\"); \
mod <- cmdstanr::cmdstan_model(file); \
mod <- cmdstanr::cmdstan_model(file, threads = TRUE); \
mod <- cmdstanr::cmdstan_model(file, cpp_options = list(stan_opencl = TRUE)); \
"
# ========================================
# Quarto Installation
# ========================================
ENV QUARTO_VERSION="1.5.57"
RUN wget --no-check-certificate https://github.com/rocker-org/rocker-versioned2/raw/refs/heads/master/scripts/install_quarto.sh && \
bash install_quarto.sh && \
rm ./install_quarto.sh
# Install Chromium for Quarto (diagram rendering, etc.) and its dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libxcomposite1 \
libxrandr2 \
libxdamage1 \
libxkbcommon0 \
libasound2 \
libpangocairo-1.0-0 \
libpango-1.0-0 \
libgbm1 \
libnss3 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& quarto install chromium
# ========================================
# Git LFS
# ========================================
RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \
apt-get update && \
apt-get install -qq git-lfs && \
git lfs install && \
rm -rf /var/lib/apt/lists/*
# ========================================
# GitHub CLI
# ========================================
RUN 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" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt-get update \
&& apt-get install -y gh \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# ========================================
# Additional R packages for development
# ========================================
RUN Rscript -e "\
install.packages(c( \
'testthat', \
'devtools', \
'covr', \
'lintr', \
'styler', \
'usethis' \
)); \
"
# ========================================
# Additional R packages for analysis
# ========================================
RUN Rscript -e "\
install.packages(c( \
'marginaleffects', \
'data.table', \
'lme4', \
'glmmTMB', \
'ggseg', \
'ggsegGlasser' \
)); \
"
# ========================================
# Environment & Path Setup
# ========================================
ENV NAME cmdstan-docker
# Ensure git is configured for safe directory access
# (Useful when mounting volumes)
RUN git config --system --add safe.directory '*'
# Set up workspace directory
RUN mkdir -p /home/rstudio/code \
&& chown -R rstudio:rstudio /home/rstudio/code
WORKDIR /home/rstudio
# ========================================
# VS Code Extensions (via CLI if needed)
# ========================================
# Note: Claude Code extension must be installed manually or via
# your VS Code settings sync. The extension ID is:
# anthropic.claude-code
#
# If using Remote-SSH, these will be installed on first connect.
# You can also use a .vscode/extensions.json in your project:
# {
# "recommendations": [
# "anthropic.claude-code",
# "reditorsupport.r",
# "quarto.quarto",
# "ms-python.python"
# ]
# }
# ========================================
# Healthcheck & Metadata
# ========================================
LABEL org.opencontainers.image.title="RStudio + CmdStan + Node.js Dev Environment"
LABEL org.opencontainers.image.description="R statistical computing with Stan, Quarto, Node.js, and VS Code development tools"
LABEL org.opencontainers.image.version="1.0.0"
# Final check that everything is installed
RUN echo "=== Environment Check ===" \
&& echo "R version: $(R --version | head -1)" \
&& echo "Node version: $(node --version)" \
&& echo "npm version: $(npm --version)" \
&& echo "Quarto version: $(quarto --version)" \
&& echo "GitHub CLI version: $(gh --version | head -1)" \
&& echo "CmdStan path: ${CMDSTAN}" \
&& echo "========================="