diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9089a19 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +target/ +.git/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index b497eff..5fa0561 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /target /.env -/service-account-cafecoder.json \ No newline at end of file +/service-account-cafecoder.json +.DS_Store +/.vscode \ No newline at end of file diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 0000000..3f3ff3a --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,4 @@ +ignored: + - DL3008 + - DL3003 + - DL4006 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b8b1982..e8cc972 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,163 +1,177 @@ -# Ubuntu:20.04(amd64) -# m1 mac だとハッシュを指定しないと arm64 で build してしまうので・・。 -FROM ubuntu@sha256:e3d7ff9efd8431d9ef39a144c45992df5502c995b9ba3c53ff70c5b52a848d9c +FROM rust:1.57.0 AS build + +WORKDIR /work +COPY . /work +RUN cargo build --release + +FROM ubuntu:20.04 ENV TZ Asia/Tokyo ENV DEBIAN_FRONTEND=noninteractive -SHELL ["/bin/bash", "-c"] +RUN sed -i -e 's/archive.ubuntu.com/jp.archive.ubuntu.com/g' /etc/apt/sources.list -# install compilers RUN \ - apt update && apt install -y \ + apt-get update && apt-get install -y --no-install-recommends \ software-properties-common \ apt-transport-https \ dirmngr \ curl \ - wget \ time \ iproute2 \ build-essential \ + apt-utils \ sudo \ unzip \ - git + git \ + gnupg \ + libssl-dev \ + ca-certificates \ + && apt-get clean && rm -rf /var/lib/apt/lists/* # Raku install -RUN apt-get install -y rakudo +RUN \ + apt-get update && apt-get install -y --no-install-recommends \ + rakudo \ + && apt-get clean && rm -rf /var/lib/apt/lists/* # C#(mono) install -RUN apt install gnupg ca-certificates -y && \ - yes | apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \ - echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \ - apt update && \ - apt install mono-devel -y +RUN \ + yes | apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \ + && echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list \ + && apt-get update && apt-get install -y --no-install-recommends \ + mono-devel \ + && apt-get clean && rm -rf /var/lib/apt/lists/* # C#(.NET) install -RUN wget https://download.visualstudio.microsoft.com/download/pr/820db713-c9a5-466e-b72a-16f2f5ed00e2/628aa2a75f6aa270e77f4a83b3742fb8/dotnet-sdk-5.0.100-linux-x64.tar.gz && \ - mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-5.0.100-linux-x64.tar.gz -C $HOME/dotnet && \ - echo 'export DOTNET_ROOT=$HOME/dotnet' >> ~/.profile && \ - echo 'export PATH=$PATH:$HOME/dotnet' >> ~/.profile +RUN \ + curl -OL https://download.visualstudio.microsoft.com/download/pr/820db713-c9a5-466e-b72a-16f2f5ed00e2/628aa2a75f6aa270e77f4a83b3742fb8/dotnet-sdk-5.0.100-linux-x64.tar.gz \ + && mkdir -p "$HOME/dotnet" \ + && tar zxf dotnet-sdk-5.0.100-linux-x64.tar.gz -C "$HOME/dotnet" \ + && rm dotnet-sdk-5.0.100-linux-x64.tar.gz +ENV DOTNET_ROOT="/root/dotnet" +ENV PATH="${PATH}:/root/dotnet" # C/C++ install -RUN apt-get install g++-10 gcc-10 -y +RUN \ + apt-get update && apt-get install -y --no-install-recommends \ + g++-10 \ + gcc-10 \ + && apt-get clean && rm -rf /var/lib/apt/lists/* # Java11 install -RUN apt install default-jdk -y +RUN \ + apt-get update && apt-get install -y --no-install-recommends \ + default-jdk \ + && apt-get clean && rm -rf /var/lib/apt/lists/* # Python3 install -RUN apt install python3.9 -y +RUN \ + apt-get update && apt-get install -y --no-install-recommends \ + python3.9 \ + && apt-get clean && rm -rf /var/lib/apt/lists/* # Pypy3 install -RUN cd /opt && \ - wget https://downloads.python.org/pypy/pypy3.7-v7.3.3-linux64.tar.bz2 && \ - tar xf pypy3.7-v7.3.3-linux64.tar.bz2 && \ - cd /bin && \ - ln -s /opt/pypy3.7-v7.3.3-linux64/bin/pypy3 pypy3 +RUN \ + cd /opt \ + && curl -OL https://downloads.python.org/pypy/pypy3.7-v7.3.3-linux64.tar.bz2 \ + && tar xf pypy3.7-v7.3.3-linux64.tar.bz2 \ + && cd /bin \ + && ln -s /opt/pypy3.7-v7.3.3-linux64/bin/pypy3 pypy3 \ + && cd /opt \ + && rm pypy3.7-v7.3.3-linux64.tar.bz2 # go install -RUN wget https://golang.org/dl/go1.15.5.linux-amd64.tar.gz && \ - tar -C /usr/local -xzf go1.15.5.linux-amd64.tar.gz && \ - echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile - -ENV USER=$USER +RUN \ + curl -OL https://golang.org/dl/go1.15.5.linux-amd64.tar.gz \ + && tar -C /usr/local -xzf go1.15.5.linux-amd64.tar.gz \ + && rm go1.15.5.linux-amd64.tar.gz +ENV PATH="${PATH}:/usr/local/go/bin" # Rust install -RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ - source $HOME/.cargo/env && \ - cargo new rust_workspace && \ - cd rust_workspace &&\ - wget https://raw.githubusercontent.com/cafecoder-dev/language-update/20.10/Rust/Cargo.toml -O Cargo.toml && \ - cargo build --release && \ - cd / +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y +ENV PATH="${PATH}:/root/.cargo/bin" + +RUN \ + mkdir -p /judge \ + && cd judge \ + && cargo new --bin rust_workspace && cd rust_workspace \ + && curl -OL https://raw.githubusercontent.com/cafecoder-dev/language-update/20.10/Rust/Cargo.toml \ + && cargo build --release # Nim install -RUN curl https://nim-lang.org/choosenim/init.sh -sSf | sh -s -- -y && \ - echo 'export PATH=/root/.nimble/bin:$PATH' >> ~/.profile +RUN curl https://nim-lang.org/choosenim/init.sh -sSf | sh -s -- -y \ +ENV PATH="/root/.nimble/bin:${PATH}" -# Ruby install -RUN apt install make libffi-dev openssl libssl-dev zlib1g-dev -y && \ - git clone https://github.com/sstephenson/rbenv.git ~/.rbenv && \ - echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile && \ - echo 'eval "$(rbenv init -)"' >> ~/.profile && \ - bash -c exec $SHELL -l && \ - git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build && \ - export PATH="$HOME/.rbenv/bin:$PATH" && rbenv install 2.7.2 && rbenv global 2.7.2 +RUN \ + curl -OL https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.gz \ + && tar xvf ruby-2.7.2.tar.gz \ + && cd ruby-2.7.2 \ + && ./configure \ + && make \ + && make install \ + && cd / \ + && rm ruby-2.7.2.tar.gz && rm -rf ruby-2.7.2 # Kotlin install -RUN apt install zip unzip -y && \ - curl -s https://get.sdkman.io | bash && \ - bash && \ - echo 'source "/root/.sdkman/bin/sdkman-init.sh"' >> ~/.profile && \ - source ~/.profile && \ - sdk install kotlin +RUN \ + curl -OL https://github.com/JetBrains/kotlin/releases/download/v1.4.10/kotlin-compiler-1.4.10.zip \ + && unzip kotlin-compiler-1.4.10.zip -d /root \ + && rm kotlin-compiler-1.4.10.zip +ENV PATH="/root/kotlinc/bin:${PATH}" # Fortran install -RUN apt install gfortran-10 -y - +RUN \ + apt-get update && apt-get install -y --no-install-recommends \ + gfortran-10 \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + # crystal -RUN curl -sSL https://dist.crystal-lang.org/apt/setup.sh | bash && \ - apt install crystal -y +RUN \ + curl -sSL https://dist.crystal-lang.org/apt/setup.sh | bash \ + && apt-get update && apt-get install -y --no-install-recommends \ + crystal \ + && apt-get clean && rm -rf /var/lib/apt/lists/* # Perl install -RUN wget https://www.cpan.org/src/5.0/perl-5.32.0.tar.gz && \ - tar -xzf perl-5.32.0.tar.gz && \ - cd perl-5.32.0 && \ - ./Configure -Dprefix=$HOME/perl -Dscriptdir=$HOME/perl/bin -des -Dman1dir=none -Dman3dir=none -DDEBUGGING=-g && \ - make --jobs=8 install +RUN \ + curl -OL https://www.cpan.org/src/5.0/perl-5.32.0.tar.gz \ + && tar -xzf perl-5.32.0.tar.gz && cd perl-5.32.0 \ + && ./Configure -Dprefix="/root/perl" -Dscriptdir="/root/perl/bin" -des -Dman1dir=none -Dman3dir=none -DDEBUGGING=-g \ + && make --jobs=8 install \ + && rm ../perl-5.32.0.tar.gz # install external libraries RUN \ - wget https://raw.githubusercontent.com/MikeMirzayanov/testlib/master/testlib.h && \ - wget https://github.com/atcoder/ac-library/releases/download/v1.0/ac-library.zip && unzip ac-library.zip + curl -OL https://raw.githubusercontent.com/MikeMirzayanov/testlib/master/testlib.h \ + && curl -OL https://github.com/atcoder/ac-library/releases/download/v1.0/ac-library.zip \ + && unzip ac-library.zip \ + && rm ac-library.zip RUN \ - apt install libcap-dev && \ - git clone https://github.com/ioi/isolate.git /isolate + apt-get update && apt-get install -y --no-install-recommends \ + libcap-dev \ + && apt-get clean && rm -rf /var/lib/apt/lists/* \ + && git clone https://github.com/ioi/isolate.git /isolate COPY ./default.cf /isolate/default.cf RUN cd /isolate && make install -RUN apt-get clean && rm -rf /var/lib/apt/lists/* - ENV DOWNLOAD_ROOT=/download -ENV DOTNET_ROOT=$HOME/dotnet -ENV PATH $PATH:$HOME/dotnet -ENV PATH $PATH:/usr/local/go/bin -ENV PATH $PATH:$HOME/.cargo/bin -ENV PATH $PATH:/root/.nimble/bin -ENV PATH $PATH:$HOME/.rbenv/bin -ENV PATH $PATH:/root/.sdkman/candidates/kotlin/current/bin - -RUN mkdir /judge -RUN mkdir /download -RUN mkdir /box -RUN mv /rust_workspace /judge -RUN mkdir -p /judge/Main && chmod -R 777 /judge -RUN chmod 777 /root -RUN cp /testlib.h /judge/testlib.h - -#RUN mkdir -p /cafecoder-docker-rust/src -#COPY dummy.rs /cafecoder-docker-rust/src/main.rs -#COPY Cargo.toml /cafecoder-docker-rust -#COPY Cargo.lock /cafecoder-docker-rust -#COPY .env /cafecoder-docker-rust -#COPY service-account-cafecoder.json /cafecoder-docker-rust -#COPY default.cf /cafecoder-docker-rust -#COPY service-account-cafecoder.json /cafecoder-docker-rust -#RUN cd cafecoder-docker-rust && source $HOME/.cargo/env && cargo build --release - -#COPY src/ /cafecoder-docker-rust/src -COPY . /cafecoder-docker-rust -RUN cd cafecoder-docker-rust && \ - source $HOME/.cargo/env && \ - cargo build --release && \ - cp target/release/cafecoder-docker-rs / && \ - cp .env / && \ - cp service-account-cafecoder.json / && \ - cp default.cf / && \ - mkdir /temp - -WORKDIR / - -RUN source $HOME/.profile && dotnet -v ; exit 0 - -ENTRYPOINT ["./cafecoder-docker-rs"] + +RUN \ + mkdir /download \ + && mkdir /box \ + && mkdir -p /judge/Main && chmod -R 777 /judge \ + && chmod 777 /root \ + && cp /testlib.h /judge/testlib.h + +WORKDIR / +COPY --from=build /work/target/release/cafecoder-docker-rs app +COPY --from=build /work/.env .env +COPY --from=build /work/default.cf default.cf +COPY --from=build /work/service-account-cafecoder.json service-account-cafecoder.json + +RUN \ + dotnet -v ; exit 0 + +ENTRYPOINT ["./app"] diff --git a/src/api.rs b/src/api.rs index b17cb3e..ac08ae5 100644 --- a/src/api.rs +++ b/src/api.rs @@ -18,7 +18,7 @@ pub struct ApiResponse { impl<'r> Responder<'r, 'static> for ApiResponse { fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> { - Response::build_from(self.json.respond_to(&req).unwrap()) + Response::build_from(self.json.respond_to(req).unwrap()) .status(self.status) .header(ContentType::JSON) .ok() diff --git a/src/api/judge.rs b/src/api/judge.rs index 15bae00..960e965 100644 --- a/src/api/judge.rs +++ b/src/api/judge.rs @@ -156,7 +156,6 @@ fn update_result(submit_result: &mut JudgeResponse, testcase_result: &TestcaseRe updated } -#[allow(clippy::clippy::unnecessary_wraps, unused_variables)] fn judging( cmd_result: &CmdResult, time_limit: i32, diff --git a/src/models.rs b/src/models.rs index 14f2a1f..6cb0f92 100644 --- a/src/models.rs +++ b/src/models.rs @@ -79,7 +79,7 @@ pub struct JudgeResponse { pub testcase_result_map: HashMap, } -#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::upper_case_acronyms)] #[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq)] pub enum Status { AC, @@ -110,9 +110,8 @@ impl fmt::Display for Status { } impl Status { - #[allow(dead_code)] - pub fn to_priority(&self) -> i32 { - match *self { + pub fn to_priority(self) -> i32 { + match self { Status::AC => 1, Status::TLE => 2, Status::MLE => 3, diff --git a/compile_request.json b/tests/compile_request.json similarity index 100% rename from compile_request.json rename to tests/compile_request.json diff --git a/download_request.json b/tests/download_request.json similarity index 100% rename from download_request.json rename to tests/download_request.json diff --git a/judge_request.json b/tests/judge_request.json similarity index 100% rename from judge_request.json rename to tests/judge_request.json diff --git a/test.sh b/tests/test.sh similarity index 100% rename from test.sh rename to tests/test.sh