Skip to content

Commit

Permalink
fix: fix sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
fly3949 committed Nov 8, 2023
1 parent 2656789 commit ef6c00b
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 31 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

6 changes: 3 additions & 3 deletions docker-compose-build-with-mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
# DO NOT EXPOSE THIS SERVICE TO THE PUBLIC.
oj-mongo:
image: mongo:4
container_name: oj-mongo
container_name: hydrooj-mongo
restart: always
volumes:
- ./data/mongo:/data/db
Expand All @@ -13,7 +13,7 @@ services:
context: ./backend
args:
- USE_MIRROR=1
container_name: oj-backend
container_name: hydrooj-backend
restart: always
depends_on:
- oj-mongo
Expand All @@ -33,7 +33,7 @@ services:
args:
- USE_MIRROR=1
- NIX_INSTALLER_URL=https://mirrors.bfsu.edu.cn/nix/latest/install
- GO_JUDGE_URL=https://ghproxy.com/https://github.com/criyle/go-judge/releases/download/v1.6.10/executorserver_1.6.10_linux_amd64
container_name: hydrooj-judge
restart: always
privileged: true
shm_size: '2gb'
Expand Down
9 changes: 5 additions & 4 deletions docker-compose-prebuild-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ services:
# DO NOT EXPOSE THIS SERVICE TO THE PUBLIC.
oj-mongo:
image: mongo:4
container_name: oj-mongo
container_name: hydrooj-mongo
restart: always
volumes:
- ./data/mongo:/data/db

oj-backend:
image: hydrooj/backend
container_name: oj-backend
image: ghcr.io/tgu-csdn/hydrooj-backend
container_name: hydrooj-backend
depends_on:
- oj-mongo
volumes:
Expand All @@ -24,7 +24,8 @@ services:
- "80:8888"

oj-judge:
image: hydrooj/judge
image: ghcr.io/tgu-csdn/hydrooj-judge
container_name: hydrooj-judge
privileged: true
shm_size: '2gb'
depends_on:
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ services:
# DO NOT EXPOSE THIS SERVICE TO THE PUBLIC.
oj-mongo:
image: mongo:4
container_name: oj-mongo
container_name: hydrooj-mongo
restart: always
volumes:
- ./data/mongo:/data/db

oj-backend:
build: ./backend
container_name: oj-backend
container_name: hydrooj-backend
restart: always
depends_on:
- oj-mongo
Expand All @@ -26,6 +26,7 @@ services:

oj-judge:
build: ./judge
container_name: hydrooj-judge
restart: always
privileged: true
shm_size: '2gb'
Expand Down
22 changes: 8 additions & 14 deletions judge/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1

FROM node:20

SHELL [ "/bin/bash", "-c" ]
Expand All @@ -9,10 +11,8 @@ ARG USE_MIRROR
# Set https://mirrors.bfsu.edu.cn/nix/latest/install if you are in China
ARG NIX_INSTALLER_URL=https://nixos.org/nix/install

# Set https://ghproxy.com/https://github.com/criyle/go-judge/releases/download/v1.6.10/executorserver_1.6.10_linux_amd64 if you are in China
ARG GO_JUDGE_URL=https://github.com/criyle/go-judge/releases/download/v1.6.10/executorserver_1.6.10_linux_amd64

# Set up environment
ADD ./runtime/config/nix /tmp/nix_config
ADD ${NIX_INSTALLER_URL} /tmp/install_nix

RUN if [[ -n "$USE_MIRROR" ]] ; then \
Expand All @@ -24,33 +24,27 @@ RUN if [[ -n "$USE_MIRROR" ]] ; then \
ENV PATH="$PATH:/root/.nix-profile/bin"
ENV NIXPKGS_ALLOW_INSECURE=1

RUN if [[ -n "$USE_MIRROR" ]] ; then echo 'substituters = https://mirrors.bfsu.edu.cn/nix-channels/store https://mirrors.ustc.edu.cn/nix-channels/store https://cache.nixos.org/' > /etc/nix/nix.conf ; fi
RUN if [[ -n "$USE_MIRROR" ]] ; then mv /tmp/nix_config/nix.cn.conf /etc/nix/nix.conf ; else mv /tmp/nix_config/nix.conf /etc/nix/nix.conf ; fi
RUN if [[ -n "$USE_MIRROR" ]] ; then nix-channel --add https://mirrors.bfsu.edu.cn/nix-channels/nixpkgs-unstable nixpkgs ; fi

RUN nix-channel --add https://nix-channel.hydro.ac/ hydro

RUN nix-channel --update

RUN if [[ -n "$USE_MIRROR" ]] ; then yarn config set registry https://registry.npmmirror.com/ ; fi

# syntax=docker/dockerfile:1

# Build rootfs
WORKDIR /nix_build

COPY hydro-nix-channel .

RUN nix-build --attr judge
RUN nix build --file /tmp/nix_config/judge-env.nix

# Init Judge
RUN mkdir -p /root/.hydro
ADD ./runtime/scripts/entrypoint.sh /root/entrypoint.sh
ADD ./runtime/scripts/run-sandbox.sh /root/run-sandbox.sh
ADD ./runtime/config/judge.yaml /tmp/.hydro/judge.yaml
ADD ./runtime/config/mount.yaml /tmp/.hydro/mount.yaml
RUN chmod +x /root/run-sandbox.sh
ADD ./runtime/config/pm2.json /root/pm2.json
RUN chmod +x /root/entrypoint.sh

RUN yarn global add pm2 @hydrooj/hydrojudge
RUN wget ${GO_JUDGE_URL} -O /usr/bin/sandbox && \
chmod +x /usr/bin/sandbox

ENTRYPOINT /root/entrypoint.sh
1 change: 0 additions & 1 deletion judge/hydro-nix-channel
Submodule hydro-nix-channel deleted from bf62fd
1 change: 1 addition & 0 deletions judge/runtime/config/judge.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
hosts:
localhost:
host: oj-backend
type: hydro
server_url: http://oj-backend:8888/
uname: root
Expand Down
13 changes: 13 additions & 0 deletions judge/runtime/config/nix/judge-env.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
system ? builtins.currentSystem,
pkgs ? import <nixpkgs> { inherit system; },
hydro ? import <hydro> { inherit system; }
}:

let
inherit (pkgs) buildEnv;

in buildEnv {
name = "judge-env";
paths = [ hydro.judge hydro.sandbox ];
}
4 changes: 4 additions & 0 deletions judge/runtime/config/nix/nix.cn.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
substituters = https://mirrors.bfsu.edu.cn/nix-channels/store https://mirrors.ustc.edu.cn/nix-channels/store https://nix-bin.hydro.ac/
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydro.ac:EytfvyReWHFwhY9MCGimCIn46KQNfmv9y8E2NqlNfxQ=
connect-timeout = 10
experimental-features = nix-command flakes
4 changes: 4 additions & 0 deletions judge/runtime/config/nix/nix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
substituters = https://cache.nixos.org/ https://nix-bin.hydro.ac/
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydro.ac:EytfvyReWHFwhY9MCGimCIn46KQNfmv9y8E2NqlNfxQ=
connect-timeout = 10
experimental-features = nix-command flakes
15 changes: 15 additions & 0 deletions judge/runtime/config/pm2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"apps": [
{
"name": "hydro-sandbox",
"script": "bash",
"args": ["-c", "ulimit -s unlimited && /nix_build/result/bin/hydro-sandbox -mount-conf /root/.hydro/mount.yaml -http-addr=localhost:5050"],
"autorestart": true
},
{
"name": "hydro-judge",
"script": "hydrojudge",
"autorestart": true
}
]
}
11 changes: 9 additions & 2 deletions judge/runtime/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
CONFIG_FILE=/root/.hydro/judge.yaml
CONFIG_FILE_DEFAULT=/tmp/.hydro/judge.yaml

MOUNT_FILE=/root/.hydro/mount.yaml
MOUNT_FILE_DEFAULT=/tmp/.hydro/mount.yaml

if [ ! -f "$CONFIG_FILE" ]; then
cp $CONFIG_FILE_DEFAULT $CONFIG_FILE
echo 'Default judge file has been created'
fi

pm2 start /root/run-sandbox.sh
pm2-runtime start hydrojudge
if [ ! -f "$MOUNT_FILE" ]; then
cp $MOUNT_FILE_DEFAULT $MOUNT_FILE
echo 'Mount config file has been created'
fi

pm2-runtime start /root/pm2.json
2 changes: 0 additions & 2 deletions judge/runtime/scripts/run-sandbox.sh

This file was deleted.

0 comments on commit ef6c00b

Please sign in to comment.