Skip to content

Commit 8d500d3

Browse files
prandlawil93
authored andcommitted
Refactor dockerfile to allow building on debian
* Removed cgroup-lite (seems useless? and not present on debian) * changed openjdk-8-jdk-headless to default-jdk-headless (17 on debian, 21 on ubuntu) * changed python3.12 to python3 (uses 3.11 on debian) * use correct version of isolate (previously we were installing the debian package on ubuntu... why does that even work??) * added .venv (used by uv) to dockerignore as (when using uv) it's pretty big and useless inside the container
1 parent a7dca91 commit 8d500d3

File tree

2 files changed

+76
-47
lines changed

2 files changed

+76
-47
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Dockerfile
33
.vagrant/
44
codecov/
55
.dev/
6+
.venv/

Dockerfile

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,75 @@
11
# syntax=docker/dockerfile:1
2-
FROM ubuntu:24.04
2+
# Supported combinations: ubuntu:noble, debian:bookworm.
3+
ARG BASE_IMAGE=ubuntu:noble
4+
FROM ${BASE_IMAGE}
35

4-
RUN \
5-
export DEBIAN_FRONTEND=noninteractive ; \
6-
apt update && \
7-
apt upgrade -y && \
8-
apt install -y \
9-
build-essential \
10-
cgroup-lite \
11-
cppreference-doc-en-html \
12-
curl \
13-
fp-compiler \
14-
git \
15-
ghc \
16-
libcap-dev \
17-
libcups2-dev \
18-
libffi-dev \
19-
libpq-dev \
20-
libyaml-dev \
21-
mono-mcs \
22-
openjdk-8-jdk-headless \
23-
php-cli \
24-
postgresql-client \
25-
pypy3 \
26-
python3-pip \
27-
python3-venv \
28-
python3.12 \
29-
python3.12-dev \
30-
rustc \
31-
shared-mime-info \
32-
sudo \
33-
wait-for-it \
6+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
7+
--mount=type=cache,target=/var/lib/apt,sharing=locked <<EOF
8+
#!/bin/bash -ex
9+
export DEBIAN_FRONTEND=noninteractive
10+
# Don't delete all the .deb files after install, as that would make the
11+
# cache useless.
12+
rm -f /etc/apt/apt.conf.d/docker-clean
13+
# Note that we use apt-get here instead of plain apt, because plain apt
14+
# also deletes .deb files after successful install.
15+
apt-get update
16+
apt-get upgrade -y
17+
PACKAGES=(
18+
build-essential
19+
cppreference-doc-en-html
20+
curl
21+
default-jdk-headless
22+
fp-compiler
23+
ghc
24+
git
25+
libcap-dev
26+
libcups2-dev
27+
libffi-dev
28+
libpq-dev
29+
libyaml-dev
30+
mono-mcs
31+
php-cli
32+
postgresql-client
33+
pypy3
34+
python3
35+
python3-dev
36+
python3-pip
37+
python3-venv
38+
rustc
39+
shared-mime-info
40+
sudo
41+
wait-for-it
3442
zip
43+
)
44+
apt-get install -y "${PACKAGES[@]}"
45+
EOF
3546

36-
RUN \
37-
export DEBIAN_FRONTEND=noninteractive ; \
38-
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/isolate.asc] http://www.ucw.cz/isolate/debian/ bookworm-isolate main" >/etc/apt/sources.list.d/isolate.list && \
39-
curl https://www.ucw.cz/isolate/debian/signing-key.asc >/etc/apt/keyrings/isolate.asc && \
40-
apt update && \
41-
apt install -y isolate && \
47+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
48+
--mount=type=cache,target=/var/lib/apt,sharing=locked <<EOF
49+
#!/bin/bash -ex
50+
export DEBIAN_FRONTEND=noninteractive
51+
CODENAME=$(source /etc/os-release; echo $VERSION_CODENAME)
52+
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/isolate.asc]" \
53+
"http://www.ucw.cz/isolate/debian/ ${CODENAME}-isolate main" \
54+
>/etc/apt/sources.list.d/isolate.list
55+
curl https://www.ucw.cz/isolate/debian/signing-key.asc \
56+
>/etc/apt/keyrings/isolate.asc
57+
apt-get update
58+
apt-get install -y isolate
4259
sed -i 's@^cg_root .*@cg_root = /sys/fs/cgroup@' /etc/isolate
60+
EOF
4361

4462
# Create cmsuser user with sudo privileges and access to isolate
45-
RUN \
46-
useradd -ms /bin/bash cmsuser && \
47-
usermod -aG sudo cmsuser && \
48-
usermod -aG isolate cmsuser && \
49-
# Disable sudo password \
63+
RUN <<EOF
64+
#!/bin/bash -ex
65+
# Need to set user ID manually: otherwise it'd be 1000 on debian
66+
# and 1001 on ubuntu.
67+
useradd -ms /bin/bash -u 1001 cmsuser
68+
usermod -aG sudo cmsuser
69+
usermod -aG isolate cmsuser
70+
# Disable sudo password
5071
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
72+
EOF
5173

5274
# Set cmsuser as default user
5375
USER cmsuser
@@ -58,15 +80,21 @@ COPY --chown=cmsuser:cmsuser install.py constraints.txt /home/cmsuser/src/
5880

5981
WORKDIR /home/cmsuser/src
6082

61-
RUN ./install.py venv
83+
RUN --mount=type=cache,target=/home/cmsuser/.cache/pip,uid=1001 ./install.py venv
6284
ENV PATH="/home/cmsuser/cms/bin:$PATH"
6385

6486
COPY --chown=cmsuser:cmsuser . /home/cmsuser/src
6587

66-
RUN ./install.py cms --devel
88+
RUN --mount=type=cache,target=/home/cmsuser/.cache/pip,uid=1001 ./install.py cms --devel
6789

68-
RUN sed 's|/cmsuser:your_password_here@localhost:5432/cmsdb"|/postgres@testdb:5432/cmsdbfortesting"|' ./config/cms.sample.toml >../cms/etc/cms-testdb.toml
69-
RUN sed -e 's|/cmsuser:your_password_here@localhost:5432/cmsdb"|/postgres@devdb:5432/cmsdb"|' -e 's/127.0.0.1/0.0.0.0/' ./config/cms.sample.toml >../cms/etc/cms-devdb.toml
70-
RUN sed -i 's/127.0.0.1/0.0.0.0/' ../cms/etc/cms_ranking.toml
90+
RUN <<EOF
91+
#!/bin/bash -ex
92+
sed 's|/cmsuser:your_password_here@localhost:5432/cmsdb"|/postgres@testdb:5432/cmsdbfortesting"|' \
93+
./config/cms.sample.toml >../cms/etc/cms-testdb.toml
94+
sed -e 's|/cmsuser:your_password_here@localhost:5432/cmsdb"|/postgres@devdb:5432/cmsdb"|' \
95+
-e 's/127.0.0.1/0.0.0.0/' \
96+
./config/cms.sample.toml >../cms/etc/cms-devdb.toml
97+
sed -i 's/127.0.0.1/0.0.0.0/' ../cms/etc/cms_ranking.toml
98+
EOF
7199

72100
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)