From 6119ce19c884e084ead22a10c213ee15afb107da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=B0=91=E5=B9=B4?= <849317537@qq.com> Date: Thu, 31 Oct 2024 13:06:02 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0js=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quant.env | 2 +- readme.md | 17 +++++++++++------ test/service/client.py | 7 ++++++- test/service/handler.py | 12 ++++++++---- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/quant.env b/quant.env index 04e0e8e..0418c29 100644 --- a/quant.env +++ b/quant.env @@ -3,4 +3,4 @@ HOME=/home/rocker VIRTUAL_ENV=/home/rocker/pypy_env VIRTUAL_ENV_PROMPT=(pypy_env) -PATH=/home/rocker/go/go/bin:/home/rocker/pypy_env/bin:/home/rocker/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \ No newline at end of file +PATH=/home/rocker/node/bin:/home/rocker/go/go/bin:/home/rocker/pypy_env/bin:/home/rocker/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \ No newline at end of file diff --git a/readme.md b/readme.md index bbfbe8b..e5a7d25 100644 --- a/readme.md +++ b/readme.md @@ -6,6 +6,7 @@ $ apt update $ apt install sudo $ apt install vim $ apt install curl +$ apt install wget $ apt install build-essential # 安装 jupyter所需要的基础软件 $ apt install ca-certificates @@ -48,20 +49,24 @@ $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # rocker用户 安装g++ # 上面已经有了 +# 安装node +$ mkdir node && cd node +$ wget https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-x64.tar.xz +$ tar xvf node-v14.17.0-linux-x64.tar.xz && rm -rf node-v14.17.0-linux-x64.tar.xz +$ cp -rf node-v14.17.0-linux-x64/* ./ && rm -rf node-v14.17.0-linux-x64 + -# 清空root和rocker用户的 .viminfo -$ echo > ~/.viminfo +# 清空root和rocker用户的 .viminfo # 清空root和rocker用户的 history历史命令 -$ history -c && echo > ~/.bash_history +$ echo > ~/.viminfo && history -c && echo > ~/.bash_history # docker 导出 $ docker export CONTAINER > base_ubuntu_image.tar # 解压后的操作, 解压后检查 -$ tar -xvf base_ubuntu_image.tar -$ rm -rf base_ubuntu_image.tar +$ tar -xvf base_ubuntu_image.tar && rm -rf base_ubuntu_image.tar # vi 编辑 etc/resolv.conf, 添加 nameserver 8.8.8.8 $ echo "nameserver 8.8.8.8" > etc/resolv.conf @@ -70,7 +75,7 @@ $ echo "nameserver 8.8.8.8" > etc/resolv.conf $ echo "127.0.0.1 rocker" > etc/hosts # 删除多余文件 -$ rm -rf /.dockerenv +$ rm -rf .dockerenv # 删除需要编译的语言 测试用生成的可执行程序(比如 rust/go/cpp) $ rm -rf rust_project/target/rust_project diff --git a/test/service/client.py b/test/service/client.py index 3cb0e3e..4f24e35 100644 --- a/test/service/client.py +++ b/test/service/client.py @@ -48,13 +48,18 @@ fn main(){ } """ +javascript_code = """ +console.log("hello world~~") +""" + if __name__ == "__main__": import requests url = "http://127.0.0.1:8011" # resp = requests.post(url, json={"code": python_code, "language": "python"}) # resp = requests.post(url, json={"code": cpp_code, "language": "cpp"}) # resp = requests.post(url, json={"code": go_code, "language": "go"}) - resp = requests.post(url, json={"code": rust_code, "language": "rust"}) + # resp = requests.post(url, json={"code": rust_code, "language": "rust"}) + resp = requests.post(url, json={"code": javascript_code, "language": "javascript"}) print(resp.json()["msg"]) diff --git a/test/service/handler.py b/test/service/handler.py index 3482e37..00245d6 100644 --- a/test/service/handler.py +++ b/test/service/handler.py @@ -3,7 +3,7 @@ import sys import subprocess import traceback -TARGET_LANGUAGE = set(["python", "cpp", "go", "rust"]) +TARGET_LANGUAGE = set(["python", "cpp", "go", "rust", "node", "javascript"]) PROJECT_PATH = "/home/rocker/project" def go_handler(): @@ -27,7 +27,9 @@ def cpp_handler(): return "", main_path def node_handler(): - pass + main_path = f"{PROJECT_PATH}/node_project/main.js" + subprocess.run(["cp", "/tmp/code", main_path], capture_output=True) + return "", main_path def rust_handler(): source_path = f"{PROJECT_PATH}/rust_project/src/main.rs" @@ -65,12 +67,14 @@ def main(): err, main_path = go_handler() cmd.extend([main_path]) elif language == "node": - pass + err, main_path = node_handler() + cmd.extend(["node", main_path]) elif language == "rust": err, main_path = rust_handler() cmd.extend([main_path]) elif language == "javascript": - node_handler() + err, main_path = node_handler() + cmd.extend(["node", main_path]) else: ...