|
1 | | -FROM ubuntu:18.04 |
2 | | -LABEL maintainer= "Edoardo Morassutto <[email protected]>" |
| 1 | +FROM ubuntu:24.04 |
3 | 2 |
|
4 | | -ARG UID=1000 |
5 | | -ARG GID=1000 |
| 3 | +# Example invocation of docker build |
| 4 | +# $ docker build \ |
| 5 | +# --build-arg TM_VERSION=X.Y.Z \ |
| 6 | +# --build-arg VCS_REF="$(git rev-parse HEAD)" \ |
| 7 | +# --build-arg BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ |
| 8 | +# -t <yourrepo>/task-maker-rust:X.Y.Z |
| 9 | +# . |
| 10 | + |
| 11 | +ARG TM_VERSION # task-maker-rust version (required) |
| 12 | +ARG VCS_REF # git commit SHA for v${TM_VERSION} |
| 13 | +ARG BUILD_DATE # e.g. 2025-09-04T12:34:56Z (RFC 3339 UTC) |
| 14 | +ARG IMAGE_URL |
| 15 | +ARG DOCS_URL='https://github.com/olimpiadi-informatica/task-maker-rust#readme' |
| 16 | +ARG VENDOR='Olimpiadi Italiane di Informatica' |
| 17 | +ARG BASE_NAME='ubuntu:24.04' |
| 18 | +ARG BASE_DIGEST='sha256:9cbed754112939e914291337b5e554b07ad7c392491dba6daf25eef1332a22e8' |
| 19 | + |
| 20 | +LABEL \ |
| 21 | + org.opencontainers.image.title="task-maker-rust" \ |
| 22 | + org.opencontainers.image.description="task-maker-rust server and worker to build programming tasks for CMS." \ |
| 23 | + org.opencontainers.image.version="${TM_VERSION}" \ |
| 24 | + org.opencontainers.image.revision="${VCS_REF}" \ |
| 25 | + org.opencontainers.image.created="${BUILD_DATE}" \ |
| 26 | + org.opencontainers.image.url="${IMAGE_URL}" \ |
| 27 | + org.opencontainers.image.documentation="${DOCS_URL}" \ |
| 28 | + org.opencontainers.image.source="https://github.com/olimpiadi-informatica/task-maker-rust" \ |
| 29 | + org.opencontainers.image.authors="task-maker-rust contributors" \ |
| 30 | + org.opencontainers.image.vendor="${VENDOR}" \ |
| 31 | + org.opencontainers.image.licenses="MPL-2.0" \ |
| 32 | + org.opencontainers.image.base.name="${BASE_NAME}" \ |
| 33 | + org.opencontainers.image.base.digest="${BASE_DIGEST}" |
| 34 | + |
| 35 | +ARG TM_UID=1000 |
| 36 | +ARG TM_GID=1000 |
| 37 | + |
| 38 | +ENV RUST_LOG='info' |
| 39 | +ENV RUST_BACKTRACE=1 |
| 40 | + |
| 41 | +# run the following as root |
| 42 | +USER root |
6 | 43 |
|
7 | 44 | # install dependencies |
8 | | -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -yy \ |
| 45 | +RUN apt-get update \ |
| 46 | + && DEBIAN_FRONTEND=noninteractive apt-get install -yy \ |
9 | 47 | asymptote \ |
10 | 48 | build-essential \ |
11 | 49 | fpc \ |
12 | 50 | latexmk \ |
13 | 51 | libseccomp-dev \ |
14 | | - python \ |
15 | | - python-sortedcontainers \ |
| 52 | + libssl-dev \ |
16 | 53 | python3 \ |
17 | 54 | python3-sortedcontainers \ |
18 | 55 | texlive \ |
19 | 56 | texlive-latex-extra \ |
20 | 57 | wget \ |
| 58 | + curl \ |
21 | 59 | && rm -rf /var/lib/apt/lists/* |
22 | 60 |
|
23 | | -# task-maker-rust version (required) |
24 | | -ARG TM_VERSION |
| 61 | +# delete default ubuntu user, this removes also the group |
| 62 | +RUN userdel --remove ubuntu |
| 63 | + |
| 64 | +# create a group and a user called taskmaker, create the home directory |
| 65 | +RUN groupadd ${TM_GID:+-g "${TM_GID}"} taskmaker |
| 66 | +RUN useradd -m -g taskmaker ${TM_UID:+-u "${TM_UID}"} taskmaker |
| 67 | + |
| 68 | +# use /opt/rustup for rustup |
| 69 | +RUN mkdir -p /opt/rustup && chown taskmaker:taskmaker /opt/rustup |
| 70 | + |
| 71 | +# use /opt/task-maker-rust as work directory |
| 72 | +RUN mkdir -p /opt/task-maker-rust && chown taskmaker:taskmaker /opt/task-maker-rust |
| 73 | + |
| 74 | +# install rust and build task-maker-rust as unprivileged user |
| 75 | +USER taskmaker |
| 76 | + |
| 77 | +# install rust and cargo |
| 78 | +WORKDIR /opt/rustup |
| 79 | +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init \ |
| 80 | + && chmod a+x ./rustup-init \ |
| 81 | + && ./rustup-init -y |
25 | 82 |
|
26 | 83 | # install task-maker-rust |
27 | | -RUN (test -n "$TM_VERSION" || (echo "Please use --build-arg TM_VERSION=0.3.X" >&2 && exit 1)) \ |
28 | | - && wget https://github.com/olimpiadi-informatica/task-maker-rust/releases/download/v${TM_VERSION}/task-maker-rust_${TM_VERSION}_amd64.deb \ |
29 | | - && dpkg -i task-maker-rust_${TM_VERSION}_amd64.deb \ |
30 | | - && rm task-maker-rust_${TM_VERSION}_amd64.deb |
| 84 | +WORKDIR /opt/task-maker-rust |
| 85 | +RUN (test -n "$TM_VERSION" || (echo "Please use --build-arg TM_VERSION=X.Y.Z" >&2 && exit 1)) \ |
| 86 | + && wget https://github.com/olimpiadi-informatica/task-maker-rust/archive/refs/tags/"v${TM_VERSION}.tar.gz" \ |
| 87 | + && tar -xvzf "v${TM_VERSION}.tar.gz" \ |
| 88 | + && rm "v${TM_VERSION}.tar.gz" |
31 | 89 |
|
32 | | -# drop root privileges |
33 | | -RUN groupadd -g $GID user \ |
34 | | - && useradd -m -g $GID -u $UID user |
35 | | -USER user |
| 90 | +# cargo build |
| 91 | +RUN . /home/taskmaker/.cargo/env \ |
| 92 | + && (cd /opt/task-maker-rust/"task-maker-rust-${TM_VERSION}" && cargo build --release) |
| 93 | + |
| 94 | +# symlink `task-maker` and `tusk-maker-tools` into /usr/local/bin/ |
| 95 | +USER root |
| 96 | +RUN ln -s /opt/task-maker-rust/"task-maker-rust-${TM_VERSION}"/target/release/task-maker /usr/local/bin/ \ |
| 97 | + && ln -s /opt/task-maker-rust/"task-maker-rust-${TM_VERSION}"/target/release/task-maker /usr/local/bin/task-maker-rust \ |
| 98 | + && ln -s /opt/task-maker-rust/"task-maker-rust-${TM_VERSION}"/target/release/task-maker-tools /usr/local/bin/ |
| 99 | + |
| 100 | +# run everything as a unprivileged user |
| 101 | +# (docker still needs --privileged to run because rask-maker-rust needs privileges to create a sandbox) |
| 102 | +USER taskmaker |
| 103 | +WORKDIR /home/taskmaker |
36 | 104 |
|
37 | 105 | # server-client port |
38 | 106 | EXPOSE 27182 |
39 | 107 | # server-worker port |
40 | 108 | EXPOSE 27183 |
41 | 109 |
|
42 | 110 | # start task-maker-rust server and worker |
43 | | -ADD entrypoint.sh healthcheck.sh / |
44 | | -CMD /entrypoint.sh |
| 111 | +ADD entrypoint.sh healthcheck.sh /home/taskmaker |
| 112 | + |
| 113 | +ENTRYPOINT ["/home/taskmaker/entrypoint.sh"] |
45 | 114 |
|
46 | 115 | # check the status of the server and the workers |
47 | | -HEALTHCHECK --interval=5s CMD /healthcheck.sh |
| 116 | +HEALTHCHECK --interval=5s \ |
| 117 | + CMD /home/taskmaker/healthcheck.sh || exit 1 |
0 commit comments