feat(判题机): 自建镜像升级工具链,语言收敛到 C / C++ / Python
Deploy / deploy (push) Waiting to run

上游 QingdaoU/JudgeServer 停更在 2024-04(registry 上的 latest 和 1.6.1 是同一份
镜像,编译器停在 gcc-13),没有新版可拉,所以自己重编。docker/judge/ 是只改工具链
的 Dockerfile 分叉,server/ 和 Judger/ 从上游固定 commit b28aa56 拉,一行没动。

镜像 oj2-judge-2(不在任何 registry 上:本机 build.sh --save → scp → docker load)
- gcc/g++ 13 → 14.2,Python 3.12 → 3.13.5,都是 trixie 默认
- Go / JDK / Node 整套删掉:前端的题目语言复选框从来只给 C / C++ / Python / SQL,
  12 万条提交里 Java 44 条、Golang 15、JavaScript 3,全是很早以前的
- 体积 1.1GB → 433MB;默认走清华源,构建 12 分钟 → 40 秒(--no-mirror 换回官方)
- deploy.sh 加一道自检:镜像不在本机就中止,并打印该跑的三条命令

C 的编译参数加三个 -Wno-error(implicit-function-declaration / int-conversion /
incompatible-pointer-types):gcc-14 把它们从 warning 提成了 error,而 -w 压不住。

语言值统一成 Python(迁移 0019 / 0020)
- 0019:Python3(104527 条提交)与 Python2(3 条)并成 Python,一并改掉 937 道题的
  languages、75 个 template 键、15 个 ast_rules 键、257 条 answers、1235 个用户的
  成就指标 _languages(languages_used 重算,总和 1928 → 1925,少的 3 个是同时用过
  两种 Python 的人)
- 0020:把 Java / JavaScript / Golang 从 84 道题的可选语言里摘掉 —— 不摘的话那些题
  的语言下拉还能选 Java,提交必 SYSTEM_ERROR
- 契约新增 normalizeLanguage() 别名表,判题侧一律走 judgeConfigFor():旧客户端
  localStorage 里的 Python3、迁移前排进队列的任务都还能判;协作的语言归一也走它,
  否则上线那一刻学生页面里的 Python3 会静默落到 C
- 回滚要连数据一起回,只滚代码会让所有 Python 提交变 SYSTEM_ERROR

实跑
- 判题冒烟 docker/judge/smoke.ts 13 条全过:三种语言、六种状态码、gcc 宽松度
- 拿备份里的真实代码逐文件比对新旧镜像的编译结果,0 差异:C 提交 1951 份
  (1725 过 / 226 CE)、C++ 882 份、Python 2000 份、20 篇 C 教程的 93 个代码块。
  不加那三个 -Wno-error 的话,C 有 26 份会从能过变成 CE
- 迁移在灌了 12.4 万行真实数据的一次性库里跑过:0 残留、没有题目被清空;
  dev 库用真正的执行器跑通
- check:ast 56 个 target 全过,前后端 typecheck 均 0

顺带记下一个升级之前就有的坑(现在随 Go 一起消失,写在 README 里):GOCACHE 指向
容器的 tmpfs,判题机重启后第一次 Go 提交是冷构建,Go 1.22 要 5.6 秒 CPU、超过 3 秒
的编译预算,于是重启后第一个交 Go 的学生必吃一次 CE,后面的人缓存热了又都正常。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 06:24:05 -06:00
co-authored by Claude Opus 5
parent a872e8365b
commit 8b4d8899f9
42 changed files with 8881 additions and 128 deletions
@@ -16,7 +16,7 @@ const emit = defineEmits<{
(e: "update:modelValue", value: AstRules | null): void
}>()
// 判题机只认 C / Python3,别的语言配了规则也一条都不会跑(judge/ast.ts 的
// 判题机只认 C / Python,别的语言配了规则也一条都不会跑(judge/ast.ts 的
// loadLanguage 返回 null 就直接放行)。原来这里按题目的全部语言开 tab,老师给
// C++ 配的规则存得下、题目页也照常显示成「要求」,判题却从不检查。
const supportedLanguages = computed(() =>
@@ -26,7 +26,7 @@ const unsupportedLanguages = computed(() =>
props.languages.filter((lang) => !AST_SUPPORTED_LANGUAGES.includes(lang)),
)
const activeTab = ref(supportedLanguages.value[0] || "Python3")
const activeTab = ref(supportedLanguages.value[0] || "Python")
const ENGINE_OPTIONS: SelectOption[] = [
{
@@ -47,7 +47,7 @@ function makeInitialFiles(): FileEntry[] {
const files = ref<FileEntry[]>(makeInitialFiles())
const selectedLanguage = ref<LANGUAGE>("Python3")
const selectedLanguage = ref<LANGUAGE>("Python")
// 始终显示所有语言,不管有没有答案代码
const availableLanguages = computed(() =>
+8 -8
View File
@@ -63,7 +63,7 @@ const problem = useLocalStorage<BlankProblem>(STORAGE_KEY.ADMIN_PROBLEM, {
difficulty: "Low",
visible: false,
tags: [],
languages: ["Python3", "C"] as LANGUAGE[],
languages: ["Python", "C"] as LANGUAGE[],
template: {} as { [key in LANGUAGE]?: string },
samples: [
{ input: "", output: "" },
@@ -153,8 +153,8 @@ function validateNewTags(v: string[]) {
// 这几个用的少,就不缓存本地了
const [needTemplate, toggleNeedTemplate] = useToggle(false)
const template = reactive(JSON.parse(JSON.stringify(CODE_TEMPLATES)))
const currentActiveTemplate = ref<LANGUAGE>("Python3")
const currentActiveAnswer = ref<LANGUAGE>("Python3")
const currentActiveTemplate = ref<LANGUAGE>("Python")
const currentActiveAnswer = ref<LANGUAGE>("Python")
// 给 TextEditor 用
const [ready, toggleReady] = useToggle(false)
@@ -169,7 +169,7 @@ const difficultyOptions: SelectOption[] = [
]
const languageOptions = [
{ label: LANGUAGE_SHOW_VALUE["Python3"], value: "Python3" },
{ label: LANGUAGE_SHOW_VALUE["Python"], value: "Python" },
{ label: LANGUAGE_SHOW_VALUE["C"], value: "C" },
{ label: LANGUAGE_SHOW_VALUE["C++"], value: "C++" },
{ label: LANGUAGE_SHOW_VALUE["SQL"], value: "SQL" },
@@ -511,7 +511,7 @@ async function generateMermaid() {
isAIGenerating.value = true
try {
const res = await generateFlowchartFromPythonCode(
problem.value.answers.filter((a) => a.language === "Python3")[0].code,
problem.value.answers.filter((a) => a.language === "Python")[0].code,
)
problem.value.mermaidCode = res.flowchart
message.warning("如果渲染不成功,请复制到外部 AI 网站检查语法")
@@ -736,7 +736,7 @@ watch(
>
<n-tabs
type="segment"
default-value="Python3"
default-value="Python"
v-model:value="currentActiveAnswer"
>
<n-tab-pane
@@ -760,7 +760,7 @@ watch(
<n-form-item label="编写预制代码">
<n-tabs
type="segment"
default-value="Python3"
default-value="Python"
v-model:value="currentActiveTemplate"
>
<n-tab-pane
@@ -878,7 +878,7 @@ watch(
type="primary"
size="small"
:disabled="
!problem.answers.filter((a) => a.language === 'Python3')[0]?.code
!problem.answers.filter((a) => a.language === 'Python')[0]?.code
.length
"
:loading="isAIGenerating"
+1 -1
View File
@@ -107,7 +107,7 @@ onMounted(init)
<n-tab-pane name="code" tab="示例代码">
<CodeEditor
v-model:value="tutorial.code"
:language="tutorial.type === 'python' ? 'Python3' : 'C'"
:language="tutorial.type === 'python' ? 'Python' : 'C'"
height="400px"
/>
</n-tab-pane>
+1 -1
View File
@@ -131,7 +131,7 @@ export function submitCode(data: SubmitCodePayload) {
export function formatCode(data: { code: string; language: string }) {
const languages: Record<string, string> = {
Python3: "python",
Python: "python",
C: "c",
"C++": "cpp",
SQL: "sql",
+1 -1
View File
@@ -137,7 +137,7 @@ const tutorial = ref<Partial<Tutorial>>({
})
const editorLanguage = computed<LANGUAGE>(() =>
tutorial.value.type === "c" ? "C" : "Python3",
tutorial.value.type === "c" ? "C" : "Python",
)
const titles = ref<{ id: number; title: string }[]>([])
const progress = ref<Record<number, TutorialProgress>>({})
+2 -2
View File
@@ -254,8 +254,8 @@ const goEdit = () => {
onMounted(() => {
if (!languages.value.includes(codeStore.code.language)) {
// 回退到题目支持的第一种语言(如 SQL 题只有 "SQL",硬编码 Python3 会被后端拒绝)
codeStore.code.language = languages.value[0] ?? "Python3"
// 回退到题目支持的第一种语言(如 SQL 题只有 "SQL",硬编码 Python 会被后端拒绝)
codeStore.code.language = languages.value[0] ?? "Python"
}
})
</script>
@@ -56,11 +56,11 @@ const isFormatting = ref(false)
const isSubmittingRequest = ref(false)
// ==================== Python 语法检测器预取 ====================
// 选中 Python3 时就把 Skulpt 拉下来,避免点提交时才开始下载
// 选中 Python 时就把 Skulpt 拉下来,避免点提交时才开始下载
watch(
() => codeStore.code.language,
(language) => {
if (language === "Python3") prefetchPythonSyntaxChecker()
if (language === "Python") prefetchPythonSyntaxChecker()
},
{ immediate: true },
)
@@ -114,8 +114,8 @@ const buttonState = computed(() =>
async function submit() {
if (buttonState.value.disabled) return
// 0. Python3 语法检测
if (codeStore.code.language === "Python3") {
// 0. Python 语法检测
if (codeStore.code.language === "Python") {
const syntaxError = await checkPythonSyntax(codeStore.code.value)
if (syntaxError) {
message.warning(`${syntaxError.line} 行存在语法错误,请修正后再提交`)
@@ -123,7 +123,7 @@ async function submit() {
}
}
// 0.5 提交前自动格式化(Python3 用 ruffC/C++ 用 clang-formatSQL 用 sqlparse
// 0.5 提交前自动格式化(Python 用 ruffC/C++ 用 clang-formatSQL 用 sqlparse
const formatLang = LANGUAGE_FORMAT_VALUE[codeStore.code.language]
if (["python", "c", "cpp", "sql"].includes(formatLang)) {
isFormatting.value = true
@@ -135,7 +135,7 @@ async function submit() {
codeStore.setCode(res.code)
} catch (e: any) {
if (e?.error === "format-error") {
// 仅 Python3 会出现:代码本身存在语法错误
// 仅 Python 会出现:代码本身存在语法错误
message.warning(`代码格式化失败:${e.data},请检查代码后重试`)
return
}
@@ -5,7 +5,7 @@ export interface PythonSyntaxError {
let skulptPromise: Promise<any> | null = null
/**
* 按需加载 Skulpt(约 233KB gzip),只在提交 Python3 代码时才下载。
* 按需加载 Skulpt(约 233KB gzip),只在提交 Python 代码时才下载。
* 结果缓存,同一页面只加载一次。
*/
function loadSkulpt(): Promise<any> {
+4 -1
View File
@@ -1,3 +1,4 @@
import { normalizeLanguage } from "@oj2/contract"
import { defineStore } from "pinia"
import { STORAGE_KEY } from "utils/constants"
import storage from "utils/storage"
@@ -11,7 +12,9 @@ export const useCodeStore = defineStore("code", () => {
// ==================== 状态 ====================
const code = reactive<Code>({
value: "",
language: storage.get(STORAGE_KEY.LANGUAGE) || "Python3",
// 过一道 normalizeLanguage:上线那一刻学生浏览器的 localStorage 里存的还是
// 旧值 Python3,直接拿来用会被后端的契约挡掉(而且报错看不出是这个原因)
language: normalizeLanguage(storage.get(STORAGE_KEY.LANGUAGE)) ?? "Python",
})
const input = ref("")
+1 -1
View File
@@ -147,7 +147,7 @@ const gradeOptions: SelectOption[] = [
const languageOptions: SelectOption[] = [
{ label: "流程图", value: "Flowchart" },
{ label: "全部语言", value: "" },
{ label: "Python", value: "Python3" },
{ label: "Python", value: "Python" },
{ label: "C语言", value: "C" },
{ label: "C++", value: "C++" },
]
@@ -27,7 +27,7 @@ interface Props {
}
const {
language = "Python3",
language = "Python",
fontSize = 20,
height = "100%",
readonly = false,
@@ -41,7 +41,7 @@ const isDark = useDark()
const langExtension = computed(() => {
if (language === "SQL")
return sql({ dialect: SQLite, upperCaseKeywords: true })
return ["Python2", "Python3"].includes(language) ? python() : cpp()
return language === "Python" ? python() : cpp()
})
const extensions = computed(() => [
@@ -41,7 +41,7 @@ interface Props {
}
const {
language = "Python3",
language = "Python",
fontSize = 20,
height = "100%",
readonly = false,
+1 -1
View File
@@ -13,5 +13,5 @@ import type { LANGUAGE } from "utils/types"
export function languageExtension(language: LANGUAGE): Extension {
if (language === "SQL")
return sql({ dialect: SQLite, upperCaseKeywords: true })
return ["Python2", "Python3"].includes(language) ? python() : cpp()
return language === "Python" ? python() : cpp()
}
+5 -10
View File
@@ -177,8 +177,7 @@ export const SOURCES = {
C: cSource,
"C++": cppSource,
Java: javaSource,
Python3: pythonSource,
Python2: "",
Python: pythonSource,
JavaScript: "",
Golang: "",
Flowchart: "",
@@ -189,8 +188,7 @@ export const LANGUAGE_FORMAT_VALUE = {
C: "c",
"C++": "cpp",
Java: "java",
Python2: "python",
Python3: "python",
Python: "python",
JavaScript: "javascript",
Golang: "go",
Flowchart: "flowchart",
@@ -202,8 +200,7 @@ export const LANGUAGE_SHOW_VALUE = {
C: "C语言",
"C++": "C++",
Java: "Java",
Python2: "Python",
Python3: "Python",
Python: "Python",
JavaScript: "JS",
Golang: "Go",
SQL: "SQL",
@@ -211,8 +208,7 @@ export const LANGUAGE_SHOW_VALUE = {
export const ICON_SET = {
Flowchart: "vscode-icons:file-type-drawio",
Python2: "devicon:python",
Python3: "devicon:python",
Python: "devicon:python",
C: "devicon:c",
"C++": "devicon:cplusplus",
Java: "devicon:java",
@@ -250,8 +246,7 @@ const blankTemplate = `//PREPEND BEGIN
export const CODE_TEMPLATES = {
C: cTemplate,
"C++": cppTemplate,
Python2: blankTemplate,
Python3: blankTemplate,
Python: blankTemplate,
Java: blankTemplate,
JavaScript: blankTemplate,
Golang: blankTemplate,
+1 -2
View File
@@ -12,8 +12,7 @@ const JUDGE0_LANGUAGE_ID: Partial<Record<LANGUAGE, number>> = {
Java: 62,
Golang: 60,
JavaScript: 63,
Python2: 70,
Python3: 71,
Python: 71,
}
export async function createTestSubmission(code: Code, input: string) {