-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
131 lines (120 loc) · 6.22 KB
/
Dockerfile
File metadata and controls
131 lines (120 loc) · 6.22 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
# This recipe allows choosing specific versions of python, R, and NodeJS in one ubuntu based image
FROM ubuntu AS base
# Essentials for installing everything else
RUN set -x \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends \
curl tar bash ca-certificates sudo \
&& rm -rf /var/lib/apt/lists/*
# This entrypoint sources all entrypoints at /opt/*/entrypoint.sh
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# This install.sh sources all installs at /opt/*/install.sh
ADD install.sh /install.sh
RUN chmod +x /install.sh
# This sources the entrypoint whenever bash runs (interactive or not)
WORKDIR /home/ubuntu
RUN chown -R ubuntu /home/ubuntu
USER ubuntu
ENV BASH_ENV=/home/ubuntu/.bash_env
RUN set -x \
&& echo 'shopt -s expand_aliases' >> ~/.bash_env \
&& echo '. /entrypoint.sh' >> ~/.bash_env \
&& echo '. "/home/ubuntu/.bash_env"' >> ~/.bashrc \
&& touch /home/ubuntu/.sudo_as_admin_successful
SHELL ["/bin/bash", "-c"]
ENTRYPOINT [ "/bin/bash", "-c", "exec \"$@\"", "--" ]
FROM base AS node_base
# The node base uses nvm to install the specific version of nodejs specified later
USER root
RUN mkdir -p /opt/node && touch /opt/node/entrypoint.sh
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | NVM_DIR=/opt/node PROFILE=/dev/null bash
RUN echo "if [[ ! -z \"\$NODE_VERSION\" ]]; then" > /opt/node/install.sh \
&& echo " echo \"export NVM_DIR=~/.nvm\" >> ~/.bash_env" >> /opt/node/install.sh \
&& echo " echo \"export npm_config_cache=~/.npm\" >> ~/.bash_env" >> /opt/node/install.sh \
&& echo " echo \". /opt/node/nvm.sh\" >> ~/.bash_env" >> /opt/node/install.sh \
&& echo " . ~/.bash_env" >> /opt/node/install.sh \
&& echo " nvm install \$NODE_VERSION || exit 1" >> /opt/node/install.sh \
&& echo " nvm use \$NODE_VERSION || exit 1" >> /opt/node/install.sh \
&& echo " if [[ -f package.json ]]; then" >> /opt/node/install.sh \
&& echo " npm i || exit 1" >> /opt/node/install.sh \
&& echo " fi" >> /opt/node/install.sh \
&& echo "fi" >> /opt/node/install.sh
FROM base AS python_base
# The python base uses uv to install the specific version of python specified later
USER root
RUN mkdir -p /opt/python/bin
RUN curl -LsSf https://astral.sh/uv/install.sh | UV_INSTALL_DIR=/opt/python/bin sh
RUN set -x \
&& echo "export UV_INSTALL_DIR=/opt/python/bin" > /opt/python/entrypoint.sh \
&& echo "export PATH=\$PATH:\$UV_INSTALL_DIR" >> /opt/python/entrypoint.sh \
&& echo "if [[ ! -z \"\$PYTHON_VERSION\" ]]; then" > /opt/python/install.sh \
&& echo " uv venv --python \$PYTHON_VERSION || exit 1" >> /opt/python/install.sh \
&& echo " echo \"[ -f ~/.venv/bin/activate ] && . ~/.venv/bin/activate\" >> ~/.bash_env" >> /opt/python/install.sh \
&& echo " echo \"alias pip='uv pip'\" >> ~/.bash_env" >> /opt/python/install.sh \
&& echo " if [[ -f uv.lock ]]; then" >> /opt/python/install.sh \
&& echo " uv sync --frozen || exit 1" >> /opt/python/install.sh \
&& echo " elif [[ -f requirements.txt ]]; then" >> /opt/python/install.sh \
&& echo " uv pip install -r requirements.txt || exit 1" >> /opt/python/install.sh \
&& echo " fi" >> /opt/python/install.sh \
&& echo "fi" >> /opt/python/install.sh
FROM base AS r_base
# The R base uses rig to install the specific version of R specified later
# unfortunately rig doesn't support installing with unprivileged users,
# so we make the install script run with root permissions using a sudoers rule.
USER root
RUN mkdir -p /opt/R
RUN curl -Ls https://github.com/r-lib/rig/releases/download/latest/rig-linux-$(arch)-latest.tar.gz | tar xz -C /opt/R
RUN set -x \
&& echo "ubuntu ALL=(root) NOPASSWD: /opt/R/install.sh" > /etc/sudoers.d/R \
&& echo "export PATH=\$PATH:/opt/R/bin" > /opt/R/entrypoint.sh \
&& echo "#!/bin/bash" > /opt/R/install.sh \
&& echo "if [[ \$EUID -ne 0 ]]; then" >> /opt/R/install.sh \
&& echo " (sudo /opt/R/install.sh \$R_VERSION) || exit 1" >> /opt/R/install.sh \
&& echo " if [[ -f setup.R ]]; then" >> /opt/R/install.sh \
&& echo " R -e \"source('setup.R')\" || exit 1" >> /opt/R/install.sh \
&& echo " fi" >> /opt/R/install.sh \
&& echo "else" >> /opt/R/install.sh \
&& echo " export PATH=\$PATH:/opt/R/bin" >> /opt/R/install.sh \
&& echo " export R_VERSION=\$1" >> /opt/R/install.sh \
&& echo " if [[ ! -z \"\$R_VERSION\" ]]; then" >> /opt/R/install.sh \
&& echo " (rig install \$R_VERSION \\" >> /opt/R/install.sh \
&& echo " && rig default \$R_VERSION \\" >> /opt/R/install.sh \
&& echo " && rm -rf /var/lib/apt/lists/*) || exit 1" >> /opt/R/install.sh \
&& echo " fi" >> /opt/R/install.sh \
&& echo "fi" >> /opt/R/install.sh \
&& chmod +x /opt/R/install.sh
FROM base AS ubuntu_base
# The ubuntu base installs deps in deps.txt
USER root
RUN mkdir -p /opt/ubuntu
RUN set -x \
&& echo "ubuntu ALL=(root) NOPASSWD: /opt/ubuntu/install.sh" > /etc/sudoers.d/ubuntu \
&& echo "export PATH=\$PATH:/opt/ubuntu/bin" > /opt/ubuntu/entrypoint.sh \
&& echo "#!/bin/bash" > /opt/ubuntu/install.sh \
&& echo "if [[ \$EUID -ne 0 ]]; then" >> /opt/ubuntu/install.sh \
&& echo " sudo /opt/ubuntu/install.sh" >> /opt/ubuntu/install.sh \
&& echo "else" >> /opt/ubuntu/install.sh \
&& echo " if [[ -f deps.txt ]]; then" >> /opt/ubuntu/install.sh \
&& echo " ( apt-get -y update \\" >> /opt/ubuntu/install.sh \
&& echo " && apt-get -y install \$(grep -v '^#' deps.txt) \\" >> /opt/ubuntu/install.sh \
&& echo " && rm -rf /var/lib/apt/lists/*) || exit 1" >> /opt/ubuntu/install.sh \
&& echo " fi" >> /opt/ubuntu/install.sh \
&& echo " chown -R ubuntu /home/ubuntu" >> /opt/ubuntu/install.sh \
&& echo "fi" >> /opt/ubuntu/install.sh \
&& chmod +x /opt/ubuntu/install.sh
FROM base AS pre_installed
# grab prepared directories
COPY --from=ubuntu_base /opt/ubuntu /opt/ubuntu
COPY --from=ubuntu_base /etc/sudoers.d/ubuntu /etc/sudoers.d/ubuntu
COPY --from=python_base /opt/python /opt/python
COPY --from=node_base /opt/node /opt/node
COPY --from=r_base /opt/R /opt/R
COPY --from=r_base /etc/sudoers.d/R /etc/sudoers.d/R
FROM pre_installed AS python
RUN echo "git" >> deps.txt
RUN PYTHON_VERSION=3.11 /install.sh
CMD ["python"]
FROM pre_installed AS basic
# specify versions of everything
RUN NODE_VERSION=20 PYTHON_VERSION=3.11 R_VERSION=4.5.3 /install.sh