Skip to content

Commit

Permalink
build: polish Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangt2333 committed Mar 30, 2024
1 parent 5355676 commit 50edea1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
62 changes: 31 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
FROM ubuntu:18.04 as basic
MAINTAINER SDUOJ-Team
LABEL maintainer="SDUOJ-Team"

# fix encoding
ENV LANG C.UTF-8
ENV LANG=C.UTF-8 \
# fix timezone issue
ENV TZ Asia/Shanghai
TZ=Asia/Shanghai \
# suppress the interactive prompt from tzdata
ENV DEBIAN_FRONTEND=noninteractive
DEBIAN_FRONTEND=noninteractive \
# prevent Python from writing pyc files
PYTHONDONTWRITEBYTECODE=1

# install runtime dependencies
RUN apt-get update -qq \
RUN --mount=type=bind,source=docker/substitute-apt-sources.sh,target=substitute-apt-sources.sh \
apt-get update -qq \
&& apt-get install -y -qq --no-install-recommends \
ca-certificates tzdata

# substitute apt sources
# COPY docker/sources.list /etc/apt/sources.list

# install OS softwares
RUN apt-get update -qq \
ca-certificates tzdata \
# substitute apt sources (optional)
# && bash substitute-apt-sources.sh \
# && apt-get update -qq \
# install OS software
&& apt-get install -y -qq --no-install-recommends \
make=4.1-9.1ubuntu1 dosbox=0.74-4.3 \
cmake sudo git unzip wget curl host dos2unix vim \
Expand All @@ -35,23 +36,20 @@ RUN for PYTHON_VERSION in 3.6 3.11; do \
&& /opt/python/${PYTHON_VERSION}/bin/python -m pip install --upgrade pip \
; done

COPY docker/install-pypy.sh install-pypy.sh
RUN bash install-pypy.sh \
RUN --mount=type=bind,source=docker/install-pypy.sh,target=install-pypy.sh \
bash install-pypy.sh \
&& rm -rf /opt/conda \
&& ls -l /opt

# ---------------------------------------------
FROM basic

# copy sduoj-judger
COPY sduoj-judger-service/build/libs/ /sduoj/
# copy testlib.h
COPY docker/testlib /testlib.h
# copy checkers
COPY docker/checkers/ /checkers/

# download docker-compose-wait
COPY --from=sduoj/docker-compose-wait:latest /wait /wait
# install JDK(s)
ENV JAVA_HOME=/opt/java/openjdk
COPY --from=eclipse-temurin:8 $JAVA_HOME ${JAVA_HOME}8
COPY --from=eclipse-temurin:17 $JAVA_HOME ${JAVA_HOME}17
# set the default JDK to JDK17
ENV JAVA_HOME=/opt/java/openjdk17
ENV PATH="${JAVA_HOME}/bin:${PATH}"

# install Python(s)
COPY --from=py-builder /opt/ /opt/
Expand All @@ -61,13 +59,8 @@ RUN ln -s /opt/python/3.11/bin/python /usr/bin/python3 \
&& ln -s /opt/pypy/3.10/bin/pypy /usr/bin/pypy3 \
&& ln -s /opt/pypy/3.10/bin/pypy /usr/bin/pypy3.10

# install JDK(s)
ENV JAVA_HOME=/opt/java/openjdk
COPY --from=eclipse-temurin:8 $JAVA_HOME ${JAVA_HOME}8
COPY --from=eclipse-temurin:17 $JAVA_HOME ${JAVA_HOME}17
# set the default JDK to JDK17
ENV JAVA_HOME=/opt/java/openjdk17
ENV PATH="${JAVA_HOME}/bin:${PATH}"
# download docker-compose-wait
COPY --from=sduoj/docker-compose-wait:latest /wait /wait

# compile and install sduoj-sandbox
RUN wget -q -O /sduoj/sandbox.zip https://codeload.github.com/SDUOJ/sduoj-sandbox/zip/master \
Expand All @@ -77,6 +70,13 @@ RUN wget -q -O /sduoj/sandbox.zip https://codeload.github.com/SDUOJ/sduoj-sandbo
&& make \
&& make install

# copy sduoj-judger
COPY sduoj-judger-service/build/libs/ /sduoj/
# copy testlib.h
COPY docker/testlib /testlib.h
# copy checkers
COPY docker/checkers/ /checkers/

ENV NACOS_ADDR=127.0.0.1:8848
ENV ACTIVE=prod
ENV CPU_PER_JUDGER=1
Expand Down
7 changes: 7 additions & 0 deletions docker/sources.list → docker/substitute-apt-sources.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#!/bin/bash

set -eux

cat << "EOF" > /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void initializeWorkspace() throws SystemErrorException {
ShellUtils.deleteWorkspaceDir(workspaceDir);
FileUtils.createDir(workspaceDir);
FileUtils.createDir(userOutputDir);
ShellUtils.chown(workspaceDir, "nobody");
ShellUtils.chown(workspaceDir, "nobody:nogroup");
ShellUtils.chmod(workspaceDir, "777");
} catch (Exception e) {
throw new SystemErrorException("Can not initialize workspace:\n" + e);
Expand Down

0 comments on commit 50edea1

Please sign in to comment.