mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: add env setting
This commit is contained in:
1 parent
4052fa691e
commit
2232cf9ff5
5 files changed
+15
-8
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.6.4",
|
"version": "2.6.5",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -52,3 +52,10 @@ disable:
|
|||||||
name: disable
|
name: disable
|
||||||
desc: Disable builtin judge
|
desc: Disable builtin judge
|
||||||
default: false
|
default: false
|
||||||
|
env:
|
||||||
|
type: text
|
||||||
|
name: env
|
||||||
|
desc: Sandbox Env
|
||||||
|
default: |
|
||||||
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
HOME=/w
|
||||||
@@ -22,6 +22,9 @@ let config = {
|
|||||||
parallelism: 2,
|
parallelism: 2,
|
||||||
config: null,
|
config: null,
|
||||||
langs: null,
|
langs: null,
|
||||||
|
env: `\
|
||||||
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
HOME=/w`,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getConfig(key: string) {
|
export function getConfig(key: string) {
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import { getConfig } from './config';
|
|||||||
import { Logger } from './log';
|
import { Logger } from './log';
|
||||||
|
|
||||||
const logger = new Logger('sandbox');
|
const logger = new Logger('sandbox');
|
||||||
const env = ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME=/w'];
|
|
||||||
const axios = Axios.create({ baseURL: getConfig('sandbox_host') });
|
|
||||||
let callId = 0;
|
let callId = 0;
|
||||||
|
|
||||||
const statusMap = {
|
const statusMap = {
|
||||||
@@ -33,7 +31,7 @@ function proc({
|
|||||||
const size = parseMemoryMB(getConfig('stdio_size'));
|
const size = parseMemoryMB(getConfig('stdio_size'));
|
||||||
return {
|
return {
|
||||||
args: cmd(execute.replace(/\$\{dir\}/g, '/w')),
|
args: cmd(execute.replace(/\$\{dir\}/g, '/w')),
|
||||||
env,
|
env: getConfig('env').split('\n'),
|
||||||
files: [
|
files: [
|
||||||
stdin ? { src: stdin } : { content: '' },
|
stdin ? { src: stdin } : { content: '' },
|
||||||
{ name: 'stdout', max: 1024 * 1024 * size },
|
{ name: 'stdout', max: 1024 * 1024 * size },
|
||||||
@@ -93,7 +91,7 @@ export async function runMultiple(execute) {
|
|||||||
body.cmd[1].files[1] = null;
|
body.cmd[1].files[1] = null;
|
||||||
const id = callId++;
|
const id = callId++;
|
||||||
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
||||||
res = await axios.post('/run', body);
|
res = await Axios.create({ baseURL: getConfig('sandbox_host') }).post('/run', body);
|
||||||
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data));
|
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof FormatError) throw e;
|
if (e instanceof FormatError) throw e;
|
||||||
@@ -103,7 +101,7 @@ export async function runMultiple(execute) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function del(fileId) {
|
export async function del(fileId) {
|
||||||
const res = await axios.delete(`/file/${fileId}`);
|
const res = await Axios.create({ baseURL: getConfig('sandbox_host') }).delete(`/file/${fileId}`);
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +114,7 @@ export async function run(execute, params?) {
|
|||||||
const body = { cmd: [proc({ execute, ...params })] };
|
const body = { cmd: [proc({ execute, ...params })] };
|
||||||
const id = callId++;
|
const id = callId++;
|
||||||
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
||||||
const res = await axios.post('/run', body);
|
const res = await Axios.create({ baseURL: getConfig('sandbox_host') }).post('/run', body);
|
||||||
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data));
|
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data));
|
||||||
[result] = res.data;
|
[result] = res.data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import { getConfig } from './config';
|
|||||||
|
|
||||||
declare module 'hydrooj/dist/interface' {
|
declare module 'hydrooj/dist/interface' {
|
||||||
interface SystemKeys {
|
interface SystemKeys {
|
||||||
'hydrojudge.langs': string,
|
|
||||||
'hydrojudge.cache_dir': string,
|
'hydrojudge.cache_dir': string,
|
||||||
'hydrojudge.tmp_dir': string,
|
'hydrojudge.tmp_dir': string,
|
||||||
'hydrojudge.tmpfs_size': string,
|
'hydrojudge.tmpfs_size': string,
|
||||||
|
|||||||
Reference in new issue
Block a user