Skip to content

Commit

Permalink
Merge pull request #149 from M1saka10010/master
Browse files Browse the repository at this point in the history
feat: update judger and docker
  • Loading branch information
M1saka10010 authored Jan 24, 2024
2 parents f04e325 + 617ff20 commit faa943c
Show file tree
Hide file tree
Showing 15 changed files with 1,656 additions and 821 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build_judge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build judge Docker Image

on:
workflow_dispatch:

jobs:
build-judge:
runs-on: ubuntu-latest

steps:
- name: Check Out Repo
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}

- name: Set lowercase repository name
run: echo "REPOSITORY_LOWER=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Build judge and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.judge.alpine
push: true
tags: ghcr.io/${{ env.REPOSITORY_LOWER }}/judge:latest
platforms: linux/amd64
34 changes: 34 additions & 0 deletions .github/workflows/build_scnuoj.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build scnuoj Docker Image

on:
workflow_dispatch:

jobs:
build-scnuoj:
runs-on: ubuntu-latest

steps:
- name: Check Out Repo
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}

- name: Set lowercase repository name
run: echo "REPOSITORY_LOWER=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Build scnuoj and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ghcr.io/${{ env.REPOSITORY_LOWER }}/scnuoj:latest
platforms: linux/amd64
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- "8.0"
- "8.1"
- "8.2"
- "8.3"

steps:
- name: "Checkout"
Expand All @@ -30,13 +31,13 @@ jobs:
php-version: "${{ matrix.php-version }}"

- name: "Lint PHP files"
run: "find ./ ! -path \"./vendor/*\" -type f -name '*.php' -print0 | xargs -0 -L1 -P4 -- php -l -f"
run: 'find ./ ! -path "./vendor/*" -type f -name ''*.php'' -print0 | xargs -0 -L1 -P4 -- php -l -f'

phpstan:
name: phpstan

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -67,7 +68,7 @@ jobs:
autoload_file: vendor/yiisoft/yii2/Yii.php
memory_limit: 512M
level: "1"

build-judger:
name: build-judger

Expand Down Expand Up @@ -102,4 +103,3 @@ jobs:
steps:
- name: CI succeeded
run: exit 0

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ tests/_support/_generated

# generated by docker-compose
data
.vscode/settings.json
2 changes: 1 addition & 1 deletion Dockerfile.judge.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ RUN adduser -D -u 1536 judge

WORKDIR /judge
USER root
CMD ["sh", "-c","cp -f /build/judge/dispatcher /judge/judge/dispatcher && cp -f /build/judge/judge /judge/judge/judge && cp -f /build/polygon/polygon /judge/polygon/polygon && cp -f /build/polygon/judge /judge/polygon/judge && ./judge/dispatcher && ./polygon/polygon && tail -f /dev/null"]
CMD ["sh", "-c","cp -f /build/judge/dispatcher /judge/judge/dispatcher && cp -f /build/judge/judge /judge/judge/judge && cp -f /build/polygon/polygon /judge/polygon/polygon && cp -f /build/polygon/judge /judge/polygon/judge ; ./judge/dispatcher && ./polygon/polygon && tail -f /dev/null"]
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
restart: always
volumes:
- ./data/mysql/data:/var/lib/mysql
- ./data/mysql/conf.d:/etc/mysql/conf.d
- ./conf.d/init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
MYSQL_ROOT_PASSWORD: yourpassword
Expand All @@ -28,6 +29,7 @@ services:
caddy:
image: caddy:latest
container_name: caddy
restart: always
ports:
- 80:80
- 443:443
Expand All @@ -41,6 +43,7 @@ services:

php:
container_name: php
restart: always
build:
context: .
dockerfile: Dockerfile
Expand All @@ -53,6 +56,7 @@ services:

judge:
container_name: judge
restart: always
build:
context: .
dockerfile: Dockerfile.judge.alpine
Expand Down
34 changes: 24 additions & 10 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ git clone https://github.com/scnu-socoding/scnuoj.git

`password` 修改为 你刚才设置的密码

#### 2.2.3 修改 `/judge/src/judge.c`
#### 2.2.3 修改 `/judge/config.ini`

`use_ptrace` 的值修改为 `0`
`OJ_USE_PTRACE` 的值修改为 `0`

> Tips: 这里修改的原因是 P trace 机制和 Docker 存在兼容性问题导致。Docker 里的 system call 的值貌似不固定(?)
#### 2.2.4 修改 `/polygon/src/judge.c`
#### 2.2.4 修改 `/polygon/config.ini`

同上

Expand All @@ -66,6 +66,10 @@ git clone https://github.com/scnu-socoding/scnuoj.git

## 3. 安装

可以选择本地打包或者直接拉取镜像。

### 本地打包

首次运行需要安装 `scnuoj`

先在 `/scnuoj` 目录下运行:
Expand All @@ -76,19 +80,29 @@ docker-compose up -d --build

生成镜像需要时间,请耐心等待打包完成。

运行成功后,进入 `php` 容器。
### 拉取镜像

首先,先使用 `docker container ls` 命令获取 `php` 容器的 `CONTAINER ID`
docker-compose.yaml 中的 build 改为对应的在线 image,然后运行

然后,输入 `docker exec -it 刚才获取的ID sh` 进入容器。
```shell
docker-compose up -d
```

运行 `./yii install` 进行安装。根据提示输入管理员账号、密码和邮箱即可
运行成功后,进入 `php` 容器进行安装

> 如果提示权限不足则先执行 `chmod +x yii`
步骤如下:

输入 `exit` 退出容器。此时 `scnuoj` 已经搭建完成。
> 首先,先使用 `docker container ls` 命令获取 `php` 容器的 `CONTAINER ID`
>
> 然后,输入 `docker exec -it 刚才获取的ID sh` 进入容器。
>
> 运行 `./yii install` 进行安装。根据提示输入管理员账号、密码和邮箱即可。
>
> > 如果提示权限不足则先执行 `chmod +x yii`
>
> 输入 `exit` 退出容器。此时 `scnuoj` 已经搭建完成。
输入:
接下来输入:

```shell
docker-compose down; docker-compose up -d
Expand Down
1 change: 1 addition & 0 deletions judge/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ OJ_SIM_ENABLE=0
OJ_SHM_RUN=1 #是否使用/dev/shm的共享内存虚拟磁盘来运行答案,如果启用能提高判题速度,但需要较多内存
OJ_LANG_SET=0,1,2,3
OJ_COMPILE_CHROOT=0
OJ_USE_PTRACE=1
72 changes: 54 additions & 18 deletions judge/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,49 @@

#define LENGTH 256

#define OJ_WT0 0 // Pending
#define OJ_WT1 1 // Pending_Rejudging
#define OJ_CI 2 // Compiling
#define OJ_RI 3 // Running_Judging
#define OJ_AC 4 // Accepted
#define OJ_PE 5 // Presentation Error
#define OJ_WA 6 // Wrong Answer
#define OJ_TL 7 // Time Limit Exceeded
#define OJ_ML 8 // Memory Limit Exceeded
#define OJ_OL 9 // Output Limit Exceeded
#define OJ_RE 10 // Runtime Error
#define OJ_CE 11 // Compilation Error
#define OJ_WT0 0 // Pending
#define OJ_WT1 1 // Pending_Rejudging
#define OJ_CI 2 // Compiling
#define OJ_RI 3 // Running_Judging
#define OJ_AC 4 // Accepted
#define OJ_PE 5 // Presentation Error
#define OJ_WA 6 // Wrong Answer
#define OJ_TL 7 // Time Limit Exceeded
#define OJ_ML 8 // Memory Limit Exceeded
#define OJ_OL 9 // Output Limit Exceeded
#define OJ_RE 10 // Runtime Error
#define OJ_CE 11 // Compilation Error
#define OJ_SE 12 // System Error
#define OJ_NT 13 // No Testdata

int DEBUG = 0;

struct database {
struct database
{
char host_name[LENGTH];
char user_name[LENGTH];
char password[LENGTH];
char db_name[LENGTH];
char mysql_unix_port[LENGTH]; //连接 mysql sock文件路径
char mysql_unix_port[LENGTH]; // 连接 mysql sock文件路径
int port_number;
} db;

//读取配置文件时寻找等号
int after_equal(char * c)
typedef struct
{
char key[50];
char value[LENGTH];
} kvPair;

// 读取配置文件时寻找等号
int after_equal(char *c)
{
int i = 0;
for (; c[i] != '\0' && c[i] != '='; i++)
;
return ++i;
}

//读取配置文件时去除空格
// 读取配置文件时去除空格
void trim(char *c)
{
char buf[LENGTH];
Expand All @@ -60,7 +67,8 @@ void trim(char *c)

bool read_buf(char *buf, const char *key, char *value)
{
if (strncmp(buf, key, strlen(key)) == 0) {
if (strncmp(buf, key, strlen(key)) == 0)
{
strcpy(value, buf + after_equal(buf));
trim(value);
if (DEBUG)
Expand All @@ -77,4 +85,32 @@ void read_int(char *buf, const char *key, int *value)
sscanf(buf2, "%d", value);
}

void parseLine(char *line, kvPair *kv)
{
char *equals = strchr(line, '=');
if (equals)
{
*equals = '\0';
trim(equals + 1);
strcpy(kv->key, line);
strcpy(kv->value, equals + 1);
}
}

void read_kv(kvPair *kv, const char *key, char *value)
{
if (strncmp(kv->key, key, strlen(key)) == 0)
{
strcpy(value, kv->value);
}
}

void read_kv_int(kvPair *kv, const char *key, int *value)
{
if (strncmp(kv->key, key, strlen(key)) == 0)
{
sscanf(kv->value, "%d", value);
}
}

#endif
Loading

0 comments on commit faa943c

Please sign in to comment.