Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: criyle/go-judge
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: knife-fish/go-judge-grpc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 8 commits
  • 13 files changed
  • 4 contributors

Commits on Mar 28, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    kianenigma Kian Paimani
    Copy the full SHA
    4367a76 View commit details

Commits on Jun 12, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b0fe8e3 View commit details

Commits on Sep 22, 2024

  1. build(deps): bump google.golang.org/grpc from 1.64.0 to 1.64.1 (#110)

    (cherry picked from commit 646f024)
    dependabot[bot] authored and evil0th committed Sep 22, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    kianenigma Kian Paimani
    Copy the full SHA
    5f3ccd9 View commit details
  2. doc: deprecate centOS 7

    (cherry picked from commit 12fca4b)
    criyle authored and evil0th committed Sep 22, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    kianenigma Kian Paimani
    Copy the full SHA
    69ae0ec View commit details
  3. build: go 1.23

    (cherry picked from commit bcc3bcf)
    criyle authored and evil0th committed Sep 22, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    kianenigma Kian Paimani
    Copy the full SHA
    d56dd3a View commit details
  4. goreleaser: deprecate snapshot.name_template

    (cherry picked from commit fdf64f4)
    criyle authored and evil0th committed Sep 22, 2024
    Copy the full SHA
    9d6f5f0 View commit details
  5. doc: fix wrong directory path (#116)

    (cherry picked from commit 205ec8b)
    tobiichi3227 authored and evil0th committed Sep 22, 2024
    Copy the full SHA
    b9e42d3 View commit details
  6. Copy the full SHA
    a5df329 View commit details
Showing with 8,864 additions and 190 deletions.
  1. +1 −1 .dockerignore
  2. +16 −16 .github/workflows/build.yml
  3. +4 −0 .gitignore
  4. +3 −79 .goreleaser.yaml
  5. +11 −0 Dockerfile
  6. +3 −11 README.cn.md
  7. +7 −15 README.md
  8. +4 −0 cmd/go-judge/config/config.go
  9. +87 −0 cmd/go-judge/main.go
  10. +47 −26 go.mod
  11. +2,732 −42 go.sum
  12. +5 −0 polaris.yaml
  13. +5,944 −0 testlib.h
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -29,4 +29,4 @@ node_modules
package*.json

example.js
/go-judge*
#/go-judge*
32 changes: 16 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -16,21 +16,21 @@ jobs:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --force --tags
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
if: ${{ contains(github.ref, 'v') }}
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
@@ -40,7 +40,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test GoReleaser
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
if: ${{ ! contains(github.ref, 'v') }}
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
@@ -53,9 +53,9 @@ jobs:
strategy:
matrix:
os:
- windows-latest
# - windows-latest
- ubuntu-latest
- macos-latest
# - macos-latest
GOARCH:
- amd64
include:
@@ -72,10 +72,10 @@ jobs:
steps:
- name: Check out
uses: actions/checkout@v4
- name: Set up Go 1.22
- name: Set up Go 1.23
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"
- name: Get git tag ref
run: git fetch --prune --unshallow --tags
- name: Download dependencies
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -36,3 +36,7 @@ cmd/go-judge/version/version.txt

dist/
.vscode

# IDE
.idea/
polaris/
82 changes: 3 additions & 79 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
project_name: go-judge
version: 2
before:
hooks:
# You may remove this if you don't use go modules.
@@ -13,8 +14,6 @@ builds:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- "386"
- amd64
@@ -60,85 +59,10 @@ nfpms:
# nix:
# - name: go-judge
# license: "mit"
dockers:
- image_templates:
- "criyle/go-judge:{{ .Tag }}-amd64"
use: buildx
dockerfile: "Dockerfile.goreleaser"
goarch: amd64
extra_files:
- "mount.yaml"
build_flag_templates:
- "--platform=linux/amd64"
- image_templates:
- "criyle/go-judge:{{ .Tag }}-arm64"
use: buildx
goarch: "arm64"
dockerfile: "Dockerfile.goreleaser"
extra_files:
- "mount.yaml"
build_flag_templates:
- "--platform=linux/arm64"
- image_templates:
- "criyle/go-judge:{{ .Tag }}-arm"
use: buildx
goarch: "arm"
goarm: "7"
dockerfile: "Dockerfile.goreleaser"
extra_files:
- "mount.yaml"
build_flag_templates:
- "--platform=linux/arm/v7"
- image_templates:
- "criyle/go-judge:{{ .Tag }}-ppc64le"
use: buildx
dockerfile: "Dockerfile.goreleaser"
goarch: ppc64le
extra_files:
- "mount.yaml"
build_flag_templates:
- "--platform=linux/ppc64le"
- image_templates:
- "criyle/go-judge:{{ .Tag }}-s390x"
use: buildx
dockerfile: "Dockerfile.goreleaser"
goarch: s390x
extra_files:
- "mount.yaml"
build_flag_templates:
- "--platform=linux/s390x"
# Debian is not supporting riscv64 on stable branch, skip it first
# - image_templates:
# - "criyle/go-judge:{{ .Tag }}-riscv64"
# use: buildx
# dockerfile: "Dockerfile.goreleaser"
# goarch: riscv64
# extra_files:
# - "mount.yaml"
# build_flag_templates:
# - "--platform=linux/riscv64"
docker_manifests:
- name_template: "criyle/go-judge:{{ .Tag }}"
image_templates:
- "criyle/go-judge:{{ .Tag }}-amd64"
- "criyle/go-judge:{{ .Tag }}-arm64"
- "criyle/go-judge:{{ .Tag }}-arm"
- "criyle/go-judge:{{ .Tag }}-ppc64le"
- "criyle/go-judge:{{ .Tag }}-s390x"
# - "criyle/go-judge:{{ .Tag }}-riscv64"
- name_template: "criyle/go-judge:latest"
image_templates:
- "criyle/go-judge:{{ .Tag }}-amd64"
- "criyle/go-judge:{{ .Tag }}-arm64"
- "criyle/go-judge:{{ .Tag }}-arm"
- "criyle/go-judge:{{ .Tag }}-ppc64le"
- "criyle/go-judge:{{ .Tag }}-s390x"
# - "criyle/go-judge:{{ .Tag }}-riscv64"
skip_push: auto
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
@@ -147,5 +71,5 @@ changelog:
- "^test:"
release:
github:
owner: criyle
owner: knife-fish
name: go-judge
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:latest

ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN sed -i "s@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list && \
sed -i "s@http://.*security.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list
RUN apt-get -y update && apt-get -y install vim curl gcc g++ python3 python3-pip

WORKDIR /opt
ENTRYPOINT [ "/opt/go-judge" ]
COPY go-judge mount.yaml polaris.yaml /opt/
14 changes: 3 additions & 11 deletions README.cn.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@

```bash
docker run -it --rm --privileged --shm-size=256m -p 5050:5050 --name=go-judge criyle/go-judge

# 本地:gRPC注册到polaris
docker run -it --rm --privileged --shm-size=256m -p 5050:5050 -p 5051:5051 --name=go-judge --env ES_ENABLE_GRPC=true --env ES_GRPC_ADDR=:5051 --env ES_SERVE_ADDR=指定提供服务的IP --add-host="host.docker.internal:host-gateway" go-judge
```

### REST API 接口
@@ -537,17 +540,6 @@ interface Output {

`systemd``init` 的发行版中运行时,`go-judge` 会使用 `dbus` 通知 `systemd` 来创建一个临时 `scope` 作为 `cgroup` 的根。

#### CentOS 7

需要开启 user 命名空间来使用 [stack overflow](https://superuser.com/questions/1294215/is-it-safe-to-enable-user-namespaces-in-centos-7-4-and-how-to-do-it/1294246#1294246)

```bash
echo user.max_user_namespaces=10000 >> /etc/sysctl.d/98-userns.conf
sysctl -p
# 重启生效
reboot
```

#### 内存使用

控制进程通常会使用 `20M` 内存,每个容器进程最大会使用 `20M` 内存,每个请求最大会使用 `2 * 16M` + 总 copy out max 限制 * 2 内存。请注意,缓存文件会存储在宿主机的共享内存中 (`/dev/shm`),请保证其大小足够存储运行时最大可能文件。
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ Or, by docker

```bash
docker run -it --rm --privileged --shm-size=256m -p 5050:5050 --name=go-judge criyle/go-judge

# gRPC with polaris
docker run -it --rm --privileged --shm-size=256m -p 5050:5050 -p 5051:5051 --name=go-judge --env ES_ENABLE_GRPC=true --env ES_GRPC_ADDR=:5051 --env ES_SERVE_ADDR=your server IP --add-host="host.docker.internal:host-gateway" go-judge
```

### REST API
@@ -670,11 +673,11 @@ For cgroup v2, systemd dbus will be used to create a transient scope for cgroup

Build container init `cinit`:

`go build -o cinit ./cmd/cinit`
`go build -o cinit ./cmd/go-judge-init`

Build `go_judge.so`:

`go build -buildmode=c-shared -o go_judge.so ./cmd/ffi/`
`go build -buildmode=c-shared -o go_judge.so ./cmd/go-judge-ffi/`

For example, in JavaScript, run with `ffi-napi` (seems node 14 is not supported yet):

@@ -732,7 +735,7 @@ If a bind mount is specifying a target within the previous mounted one, please e
### Windows Support

- Build `go-judge` by: `go build ./cmd/go-judge/`
- Build `go_judge.dll`: (need to install `gcc` as well) `go build -buildmode=c-shared -o go_judge.so ./cmd/ffi/`
- Build `go_judge.dll`: (need to install `gcc` as well) `go build -buildmode=c-shared -o go_judge.so ./cmd/go-judge-ffi/`
- Run: `./go-judge`

#### Windows Security
@@ -744,7 +747,7 @@ If a bind mount is specifying a target within the previous mounted one, please e
### MacOS Support

- Build `go-judge` by: `go build ./cmd/go-judge/`
- Build `go_judge.dylib`: (need to install `XCode`) `go build -buildmode=c-shared -o go_judge.dylib ./cmd/ffi/`
- Build `go_judge.dylib`: (need to install `XCode`) `go build -buildmode=c-shared -o go_judge.dylib ./cmd/go-judge-ffi/`
- Run: `./go-judge`

#### MacOS Security
@@ -761,17 +764,6 @@ When running in containers, the `go-judge` will migrate all processed into `/api

When running in Linux distributions powered by `systemd`, the `go-judge` will contact `systemd` via `dbus` to create a transient scope as cgroup root.

#### CentOS 7

By default, user namespace is disabled and it can be enabled following [stack overflow](https://superuser.com/questions/1294215/is-it-safe-to-enable-user-namespaces-in-centos-7-4-and-how-to-do-it/1294246#1294246)

```bash
echo user.max_user_namespaces=10000 >> /etc/sysctl.d/98-userns.conf
sysctl -p
# reboot make the config effective
reboot
```

#### Memory Usage

The controller will consume `20M` memory and each container will consume `20M` + size of tmpfs `2 * 128M`. For each request, it consumes as much as user program limit + extra limit (`16k`) + total copy out max. Notice that the cached file stores in the shared memory (`/dev/shm`) of the host, so please ensure enough size allocated.
4 changes: 4 additions & 0 deletions cmd/go-judge/config/config.go
Original file line number Diff line number Diff line change
@@ -57,6 +57,10 @@ type Config struct {

// show version and exit
Version bool `flagUsage:"show version and exit"`

// polaris
ServeAddr string `flagUsage:"serve instance address for polaris"`
ServeName string `flagUsage:"serve name register to polaris" default:"judge.server"`
}

// Load loads config from flag & environment variables
Loading