mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
judge: use new config path by default
This commit is contained in:
1 parent
f80c3426fc
commit
489a374445
4 files changed
+71
-20
No files matched your search
+1
-1
@@ -23,5 +23,5 @@ cat >/tmp/install.b64 << EOF123
|
|||||||
%PLACEHOLDER%
|
%PLACEHOLDER%
|
||||||
EOF123
|
EOF123
|
||||||
cat /tmp/install.b64 | base64 -d >>/tmp/install.js
|
cat /tmp/install.b64 | base64 -d >>/tmp/install.js
|
||||||
node /tmp/install.js
|
node /tmp/install.js "$@"
|
||||||
set +e
|
set +e
|
||||||
+65
-17
@@ -34,6 +34,7 @@ const locales = {
|
|||||||
'install.hydro': '正在安装 Hydro...',
|
'install.hydro': '正在安装 Hydro...',
|
||||||
'install.done': 'Hydro 安装成功!',
|
'install.done': 'Hydro 安装成功!',
|
||||||
'install.alldone': '安装已全部完成。',
|
'install.alldone': '安装已全部完成。',
|
||||||
|
'install.editJudgeConfigAndStart': '请编辑 ~/.hydro/judge.yaml 后使用 pm2 start hydrojudge && pm2 save 启动。',
|
||||||
'extra.dbUser': '数据库用户名: hydro',
|
'extra.dbUser': '数据库用户名: hydro',
|
||||||
'extra.dbPassword': '数据库密码: %s',
|
'extra.dbPassword': '数据库密码: %s',
|
||||||
'info.skip': '步骤已跳过。',
|
'info.skip': '步骤已跳过。',
|
||||||
@@ -51,11 +52,20 @@ const locales = {
|
|||||||
'install.compiler': 'Installing compiler...',
|
'install.compiler': 'Installing compiler...',
|
||||||
'install.hydro': 'Installing Hydro...',
|
'install.hydro': 'Installing Hydro...',
|
||||||
'install.done': 'Hydro installation completed!',
|
'install.done': 'Hydro installation completed!',
|
||||||
|
'install.editJudgeConfigAndStart': 'Please edit config at ~/.hydro/judge.yaml than start hydrojudge with:\npm2 start hydrojudge && pm2 save.',
|
||||||
'extra.dbUser': 'Database username: hydro',
|
'extra.dbUser': 'Database username: hydro',
|
||||||
'extra.dbPassword': 'Database password: %s',
|
'extra.dbPassword': 'Database password: %s',
|
||||||
'info.skip': 'Step skipped.',
|
'info.skip': 'Step skipped.',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const installAsJudge = process.argv.includes('--judge');
|
||||||
|
const noCaddy = process.argv.includes('--no-caddy');
|
||||||
|
const installTarget = installAsJudge
|
||||||
|
? '@hydrooj/hydrojudge'
|
||||||
|
: 'hydrooj @hydrooj/hydrojudge @hydrooj/ui-default @hydrooj/fps-importer';
|
||||||
|
const addons = ['@hydrooj/ui-default', '@hydrooj/hydrojudge', '@hydrooj/fps-importer'];
|
||||||
|
|
||||||
let locale = process.env.LANG?.includes('zh') ? 'zh' : 'en';
|
let locale = process.env.LANG?.includes('zh') ? 'zh' : 'en';
|
||||||
if (process.env.TERM === 'linux') locale = 'en';
|
if (process.env.TERM === 'linux') locale = 'en';
|
||||||
const processLog = (orig) => (str, ...args) => (orig(locales[locale][str] || str, ...args), 0);
|
const processLog = (orig) => (str, ...args) => (orig(locales[locale][str] || str, ...args), 0);
|
||||||
@@ -76,12 +86,12 @@ const values = {};
|
|||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!line.trim()) continue;
|
if (!line.trim()) continue;
|
||||||
const d = line.split('=');
|
const d = line.split('=');
|
||||||
if (d[1].startsWith('"')) values[d[0].toLowerCase()] = d[1].substr(1, d[1].length - 2);
|
if (d[1].startsWith('"')) values[d[0].toLowerCase()] = d[1].substring(1, d[1].length - 2);
|
||||||
else values[d[0].toLowerCase()] = d[1];
|
else values[d[0].toLowerCase()] = d[1];
|
||||||
}
|
}
|
||||||
let avx2 = true;
|
let avx2 = true;
|
||||||
const cpuInfoFile = readFileSync('/proc/cpuinfo', 'utf-8');
|
const cpuInfoFile = readFileSync('/proc/cpuinfo', 'utf-8');
|
||||||
if (!cpuInfoFile.includes('avx2')) {
|
if (!cpuInfoFile.includes('avx2') && !installAsJudge) {
|
||||||
avx2 = false;
|
avx2 = false;
|
||||||
log.warn('warn.avx2');
|
log.warn('warn.avx2');
|
||||||
}
|
}
|
||||||
@@ -139,6 +149,31 @@ const Caddyfile = `\
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const judgeYaml = `\
|
||||||
|
hosts:
|
||||||
|
local:
|
||||||
|
host: localhost
|
||||||
|
type: hydro
|
||||||
|
server_url: https://hydro.ac/
|
||||||
|
uname: judge
|
||||||
|
password: examplepassword
|
||||||
|
detail: true
|
||||||
|
tmpfs_size: 512m
|
||||||
|
stdio_size: 256m
|
||||||
|
memoryMax: 1024m
|
||||||
|
processLimit: 128
|
||||||
|
testcases_max: 60
|
||||||
|
total_time_limit: 300
|
||||||
|
retry_delay_sec: 3
|
||||||
|
parallelism: 10
|
||||||
|
rate: 1.00
|
||||||
|
rerun: 0
|
||||||
|
secret: examplesecret
|
||||||
|
env: |
|
||||||
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/nodejs/bin
|
||||||
|
HOME=/w
|
||||||
|
`;
|
||||||
|
|
||||||
const isPortFree = async (port: number) => {
|
const isPortFree = async (port: number) => {
|
||||||
const server = net.createServer();
|
const server = net.createServer();
|
||||||
const res = await new Promise((resolve) => {
|
const res = await new Promise((resolve) => {
|
||||||
@@ -216,6 +251,8 @@ connect-timeout = 10`);
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
init: 'install.mongodb',
|
init: 'install.mongodb',
|
||||||
|
skip: () => installAsJudge,
|
||||||
|
hidden: installAsJudge,
|
||||||
operations: [
|
operations: [
|
||||||
`nix-env -iA hydro.mongodb${avx2 ? 5 : 4}${CN ? '-cn' : ''} hydro.mongosh${avx2 ? 5 : 4}${CN ? '-cn' : ''} nixpkgs.mongodb-tools`,
|
`nix-env -iA hydro.mongodb${avx2 ? 5 : 4}${CN ? '-cn' : ''} hydro.mongosh${avx2 ? 5 : 4}${CN ? '-cn' : ''} nixpkgs.mongodb-tools`,
|
||||||
],
|
],
|
||||||
@@ -235,7 +272,8 @@ connect-timeout = 10`);
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
init: 'install.caddy',
|
init: 'install.caddy',
|
||||||
skip: () => !exec('caddy version').code,
|
skip: () => !exec('caddy version').code || installAsJudge || noCaddy,
|
||||||
|
hidden: installAsJudge,
|
||||||
operations: [
|
operations: [
|
||||||
'nix-env -iA nixpkgs.caddy',
|
'nix-env -iA nixpkgs.caddy',
|
||||||
() => writeFileSync(`${process.env.HOME}/.hydro/Caddyfile`, Caddyfile),
|
() => writeFileSync(`${process.env.HOME}/.hydro/Caddyfile`, Caddyfile),
|
||||||
@@ -249,27 +287,31 @@ connect-timeout = 10`);
|
|||||||
let res: any = null;
|
let res: any = null;
|
||||||
try {
|
try {
|
||||||
exec('yarn config set registry https://registry.npmmirror.com/', { stdio: 'inherit' });
|
exec('yarn config set registry https://registry.npmmirror.com/', { stdio: 'inherit' });
|
||||||
res = exec('yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge', { stdio: 'inherit' });
|
res = exec(`yarn global add ${installTarget}`, { stdio: 'inherit' });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Failed to install from npmmirror, fallback to yarnpkg');
|
console.log('Failed to install from npmmirror, fallback to yarnpkg');
|
||||||
} finally {
|
} finally {
|
||||||
exec('yarn config set registry https://registry.yarnpkg.com', { stdio: 'inherit' });
|
exec('yarn config set registry https://registry.yarnpkg.com', { stdio: 'inherit' });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
exec('yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge', { timeout: 60000 });
|
exec(`yarn global add ${installTarget}`, { timeout: 60000 });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to check update from yarnpkg');
|
console.warn('Failed to check update from yarnpkg');
|
||||||
if (res?.code !== 0) return 'retry';
|
if (res?.code !== 0) return 'retry';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} : ['yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge', { retry: true }]),
|
} : [`yarn global add ${installTarget}`, { retry: true }]),
|
||||||
() => writeFileSync(`${process.env.HOME}/.hydro/addon.json`, '["@hydrooj/ui-default","@hydrooj/hydrojudge"]'),
|
() => {
|
||||||
|
if (installAsJudge) writeFileSync(`${process.env.HOME}/.hydro/judge.yaml`, judgeYaml);
|
||||||
|
else writeFileSync(`${process.env.HOME}/.hydro/addon.json`, JSON.stringify(addons));
|
||||||
|
},
|
||||||
() => rollbackResolveField(),
|
() => rollbackResolveField(),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
init: 'install.createDatabaseUser',
|
init: 'install.createDatabaseUser',
|
||||||
skip: () => existsSync(`${process.env.HOME}/.hydro/config.json`),
|
skip: () => existsSync(`${process.env.HOME}/.hydro/config.json`) || installAsJudge,
|
||||||
|
hidden: installAsJudge,
|
||||||
operations: [
|
operations: [
|
||||||
'pm2 start mongod',
|
'pm2 start mongod',
|
||||||
() => sleep(3000),
|
() => sleep(3000),
|
||||||
@@ -295,16 +337,19 @@ connect-timeout = 10`);
|
|||||||
operations: [
|
operations: [
|
||||||
['pm2 stop all', { ignore: true }],
|
['pm2 stop all', { ignore: true }],
|
||||||
() => writeFileSync(`${process.env.HOME}/.hydro/mount.yaml`, mount),
|
() => writeFileSync(`${process.env.HOME}/.hydro/mount.yaml`, mount),
|
||||||
'pm2 start mongod --name mongodb -- --auth --bind_ip 0.0.0.0',
|
|
||||||
() => sleep(1000),
|
|
||||||
`pm2 start bash --name hydro-sandbox -- -c "ulimit -s unlimited && hydro-sandbox -mount-conf ${process.env.HOME}/.hydro/mount.yaml"`,
|
`pm2 start bash --name hydro-sandbox -- -c "ulimit -s unlimited && hydro-sandbox -mount-conf ${process.env.HOME}/.hydro/mount.yaml"`,
|
||||||
'pm2 start hydrooj',
|
...installAsJudge ? [] : [
|
||||||
async () => {
|
'pm2 start mongod --name mongodb -- --auth --bind_ip 0.0.0.0',
|
||||||
if (!await isPortFree(80)) log.warn('port.80');
|
() => sleep(1000),
|
||||||
exec('pm2 start caddy -- run', { cwd: `${process.env.HOME}/.hydro` });
|
'pm2 start hydrooj',
|
||||||
exec('hydrooj cli system set server.xff x-forwarded-for');
|
async () => {
|
||||||
exec('hydrooj cli system set server.xhost x-forwarded-host');
|
if (noCaddy) return;
|
||||||
},
|
if (!await isPortFree(80)) log.warn('port.80');
|
||||||
|
exec('pm2 start caddy -- run', { cwd: `${process.env.HOME}/.hydro` });
|
||||||
|
exec('hydrooj cli system set server.xff x-forwarded-for');
|
||||||
|
exec('hydrooj cli system set server.xhost x-forwarded-host');
|
||||||
|
},
|
||||||
|
],
|
||||||
'pm2 startup',
|
'pm2 startup',
|
||||||
'pm2 save',
|
'pm2 save',
|
||||||
],
|
],
|
||||||
@@ -334,6 +379,7 @@ connect-timeout = 10`);
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
init: 'install.done',
|
init: 'install.done',
|
||||||
|
skip: () => installAsJudge,
|
||||||
operations: [
|
operations: [
|
||||||
() => {
|
() => {
|
||||||
password = require(`${process.env.HOME}/.hydro/config.json`).password;
|
password = require(`${process.env.HOME}/.hydro/config.json`).password;
|
||||||
@@ -345,6 +391,7 @@ connect-timeout = 10`);
|
|||||||
{
|
{
|
||||||
init: 'install.postinstall',
|
init: 'install.postinstall',
|
||||||
operations: [
|
operations: [
|
||||||
|
...installAsJudge ? [] : ['hydrooj install https://hydro.ac/language-server-0.0.1.tgz'],
|
||||||
['pm2 install pm2-logrotate', { retry: true }],
|
['pm2 install pm2-logrotate', { retry: true }],
|
||||||
'pm2 set pm2-logrotate:max_size 64M',
|
'pm2 set pm2-logrotate:max_size 64M',
|
||||||
],
|
],
|
||||||
@@ -353,6 +400,7 @@ connect-timeout = 10`);
|
|||||||
init: 'install.alldone',
|
init: 'install.alldone',
|
||||||
operations: [
|
operations: [
|
||||||
() => log.info('install.alldone'),
|
() => log.info('install.alldone'),
|
||||||
|
() => installAsJudge && log.info('install.editJudgeConfigAndStart'),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "3.1.4",
|
"version": "3.1.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",
|
||||||
|
|||||||
@@ -29,13 +29,16 @@ const JudgeSettings = Schema.object({
|
|||||||
detail: Schema.boolean().description('Show diff detail').default(true),
|
detail: Schema.boolean().description('Show diff detail').default(true),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const oldPath = path.resolve(os.homedir(), '.config', 'hydro', 'judge.yaml');
|
||||||
|
const newPath = path.resolve(os.homedir(), '.hydro', 'judge.yaml');
|
||||||
|
|
||||||
const config = global.Hydro
|
const config = global.Hydro
|
||||||
? JudgeSettings({})
|
? JudgeSettings({})
|
||||||
: (() => {
|
: (() => {
|
||||||
const cfg = JudgeSettings({});
|
const cfg = JudgeSettings({});
|
||||||
const configFilePath = (process.env.CONFIG_FILE || argv.options.config)
|
const configFilePath = (process.env.CONFIG_FILE || argv.options.config)
|
||||||
? path.resolve(process.env.CONFIG_FILE || argv.options.config)
|
? path.resolve(process.env.CONFIG_FILE || argv.options.config)
|
||||||
: path.resolve(os.homedir(), '.config', 'hydro', 'judge.yaml');
|
: fs.existsSync(oldPath) ? oldPath : newPath;
|
||||||
|
|
||||||
if (process.env.TEMP_DIR || argv.options.tmp) {
|
if (process.env.TEMP_DIR || argv.options.tmp) {
|
||||||
cfg.tmp_dir = path.resolve(process.env.TEMP_DIR || argv.options.tmp);
|
cfg.tmp_dir = path.resolve(process.env.TEMP_DIR || argv.options.tmp);
|
||||||
|
|||||||
Reference in new issue
Block a user