-
Notifications
You must be signed in to change notification settings - Fork 20
/
Dockerfile
301 lines (253 loc) · 9.04 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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# Ubuntu version
ARG RELEASE=24.04
# Build stage
FROM ubuntu:${RELEASE} as builder
# Build-time variables
ARG DEBIAN_FRONTEND=noninteractive
ARG BUILDARCH
# Stage-wide dependencies
RUN apt update && \
apt install --no-install-recommends --no-install-suggests --yes \
build-essential \
ca-certificates \
curl
# Install Java 23.x
# http://jdk.java.net/23/
RUN cd /tmp && \
if [ "$BUILDARCH" = "arm64" ]; then ARCH="aarch64"; else ARCH="x64"; fi && \
curl --remote-name https://download.java.net/java/GA/jdk23/3c5b90190c68498b986a97f276efd28a/37/GPL/openjdk-23_linux-${ARCH}_bin.tar.gz && \
tar xzf openjdk-23_linux-${ARCH}_bin.tar.gz && \
rm --force openjdk-23_linux-${ARCH}_bin.tar.gz && \
mv jdk-23 /opt/jdk && \
mkdir --parent /opt/bin && \
ln --symbolic /opt/jdk/bin/* /opt/bin/ && \
chmod a+rx /opt/bin/*
# Install Node.js 22.x
# https://nodejs.dev/en/download/
# https://github.com/tj/n#installation
RUN curl --location https://raw.githubusercontent.com/tj/n/master/bin/n --output /usr/local/bin/n && \
chmod a+x /usr/local/bin/n && \
n 22.6.0
# Install Node.js packages
RUN npm install --global \
http-server
# Patch index.js in http-server
COPY index.js.patch /tmp
RUN cd /usr/local/lib/node_modules/http-server/lib/core/show-dir && \
patch index.js < /tmp/index.js.patch && \
rm --force /tmp/index.js.patch
# Suggested build environment for Python, per pyenv, even though we're building ourselves
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
RUN apt update && \
apt install --no-install-recommends --no-install-suggests --yes \
build-essential ca-certificates curl git \
libssl-dev libbz2-dev libreadline-dev libsqlite3-dev \
llvm libncursesw5-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev \
make tk-dev unzip wget xz-utils zlib1g-dev
# Install Python 3.12.x
# https://www.python.org/downloads/
RUN cd /tmp && \
curl --remote-name https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tgz && \
tar xzf Python-3.12.7.tgz && \
rm --force Python-3.12.7.tgz && \
cd Python-3.12.7 && \
CFLAGS="-Os" ./configure --disable-static --enable-optimizations --enable-shared --with-lto --without-tests && \
./configure && \
make && \
make install && \
cd .. && \
rm --force --recursive Python-3.12.7 && \
ln --relative --symbolic /usr/local/bin/pip3 /usr/local/bin/pip && \
ln --relative --symbolic /usr/local/bin/python3 /usr/local/bin/python && \
pip3 install --no-cache-dir --upgrade pip
# Install Ruby 3.3.x
# https://www.ruby-lang.org/en/downloads/
# https://bugs.ruby-lang.org/issues/20085#note-5
RUN apt update && \
apt install --no-install-recommends --no-install-suggests --yes \
autoconf \
libyaml-dev && \
apt clean && \
rm --force --recursive /var/lib/apt/lists/* && \
cd /tmp && \
curl https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.5.tar.gz --output ruby-3.3.5.tar.gz && \
tar xzf ruby-3.3.5.tar.gz && \
rm --force ruby-3.3.5.tar.gz && \
cd ruby-3.3.5 && \
if [ "$BUILDARCH" = "arm64" ]; then ASFLAGS=-mbranch-protection=pac-ret; else ASFLAGS=; fi && \
ASFLAGS=${ASFLAGS} CFLAGS=-Os ./configure --disable-install-doc --enable-load-relative && \
make && \
make install && \
cd .. && \
rm --force --recursive ruby-3.3.5
# Install Ruby packages
RUN echo "gem: --no-document" > /etc/gemrc && \
gem install \
jekyll \
minitest `# So that Bundler needn't install` \
pygments.rb \
specific_install && \
gem specific_install https://github.com/cs50/jekyll-theme-cs50 develop && \
gem cleanup
# Install SQLite 3.4x
# https://www.sqlite.org/download.html
# https://www.sqlite.org/howtocompile.html#compiling_the_command_line_interface
COPY shell.c.patch /tmp
RUN cd /tmp && \
curl --remote-name https://www.sqlite.org/2024/sqlite-amalgamation-3460100.zip && \
unzip sqlite-amalgamation-3460100.zip && \
rm --force sqlite-amalgamation-3460100.zip && \
cd sqlite-amalgamation-3460100 && \
patch shell.c < /tmp/shell.c.patch && \
gcc -D HAVE_READLINE -D SQLITE_DEFAULT_FOREIGN_KEYS=1 -D SQLITE_OMIT_DYNAPROMPT=1 shell.c sqlite3.c -lpthread -ldl -lm -lreadline -lncurses -o /usr/local/bin/sqlite3 && \
cd .. && \
rm --force --recursive sqlite-amalgamation-3460100 && \
rm --force /tmp/shell.c.patch
# Final stage
FROM ubuntu:${RELEASE}
LABEL maintainer="sysadmins@cs50.harvard.edu"
ARG DEBIAN_FRONTEND=noninteractive
# Remove exisiting ubuntu user (if any) and home directory
RUN userdel --force --remove ubuntu && \
rm --force --recursive /home/ubuntu
# Copy files from builder
COPY --from=builder /opt /opt
COPY --from=builder /usr/local /usr/local
# Avoid "delaying package configuration, since apt-utils is not installed"
# Install locales
RUN apt update && \
apt install --no-install-recommends --no-install-suggests --yes \
apt-utils \
locales && \
locale-gen \
en_US.utf8 \
zh_CN.utf8 \
zh_TW.utf8 \
fr_FR.utf8 \
de_DE.utf8 \
it_IT.utf8 \
es_ES.utf8 \
ja_JP.utf8 \
ko_KR.utf8 \
ru_RU.utf8 \
pt_BR.utf8 \
tr_TR.utf8 \
pl_PL.utf8 \
cs_CZ.utf8 \
hu_HU.utf8 \
bg_BG.UTF-8
ENV LANG=C.UTF-8
# Install Ubuntu packages
RUN apt update && \
apt upgrade --yes && \
apt install --no-install-recommends --no-install-suggests --yes \
astyle \
bash-completion \
build-essential `# dpkg-dev, libc, gcc, g++, make, etc.`\
ca-certificates \
clang \
clang-format \
coreutils `# For fold` \
cowsay \
curl \
dos2unix \
dnsutils `# For nslookup` \
fonts-noto-color-emoji `# For render50` \
gdb \
git \
git-lfs \
jq \
less \
libclang-rt-18-dev `# For clang` \
liblapack3 `# For R` \
libmagic-dev `# For style50` \
libncurses-dev \
libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 `# For render50` \
libpangocairo-1.0-0 `# For R` \
libtiff6 `# For R` \
libxt6 `# For R` \
libgmp-dev `# For gem` \
libffi-dev `# For gem` \
libyaml-0-2 `# Runtime package for gem` \
man \
man-db \
nano \
openssh-client `# For ssh-keygen` \
psmisc `# For fuser` \
sudo \
tzdata `# For TZ` \
unzip \
valgrind \
vim \
wget \
zip \
zlib1g-dev `# For bundle` && \
apt clean
# Install CS50 library
RUN curl https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | bash && \
apt update && \
apt install --yes \
libcs50
# Install Docker CLI
# https://docs.docker.com/engine/install/ubuntu/
# https://docs.docker.com/engine/install/linux-postinstall/
RUN apt update && \
apt install --no-install-recommends --no-install-suggests --yes \
ca-certificates \
curl \
socat && \
install -d /etc/apt/keyrings -m 0755 && \
curl --fail --location --show-error --silent https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
chmod a+r /etc/apt/keyrings/docker.asc && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt update && \
sudo apt install --no-install-recommends --no-install-suggests --yes \
docker-ce-cli && \
groupadd docker
# Install Python packages
RUN pip3 install --no-cache-dir \
autopep8 \
cachelib \
"check50<4" \
cli50 \
compare50 \
cs50==9.4.0 \
Flask \
Flask-Session \
help50 \
pytest \
render50 \
setuptools \
"style50>2.10.0" \
"submit50<4"
# Copy files to image
COPY ./etc /etc
COPY ./opt /opt
RUN chmod a+rx /opt/cs50/bin/*
# Disable bracketed paste
# https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1926256
RUN echo >> /etc/inputrc && \
echo "# Disable bracketed paste" >> /etc/inputrc && \
echo "set enable-bracketed-paste off" >> /etc/inputrc
# Add user
RUN useradd --home-dir /home/ubuntu --shell /bin/bash ubuntu && \
umask 0077 && \
mkdir --parents /home/ubuntu && \
chown --recursive ubuntu:ubuntu /home/ubuntu && \
echo "\n# CS50 CLI" >> /etc/sudoers && \
echo "ubuntu ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
echo "Defaults umask_override" >> /etc/sudoers && \
echo "Defaults umask=0022" >> /etc/sudoers && \
sed --expression="s/^Defaults\tsecure_path=.*/Defaults\t!secure_path/" --in-place /etc/sudoers && \
usermod --append --groups docker ubuntu
# Version the image (and any descendants)
ARG VCS_REF
RUN echo "$VCS_REF" > /etc/issue
ONBUILD USER root
ONBUILD ARG VCS_REF
ONBUILD RUN echo "$VCS_REF" >> /etc/issue
ONBUILD USER ubuntu
# Set user
USER ubuntu
WORKDIR /home/ubuntu
ENV WORKDIR=/home/ubuntu