From 71ad8020116c1bc557246e90c7de2b454464a39b Mon Sep 17 00:00:00 2001 From: Steven Ewald Date: Sat, 5 Oct 2024 16:32:32 -0500 Subject: [PATCH] Updated to enable sandbox --- docker/dev/docker-compose.yml | 2 +- docker/prod/docker-compose.yml | 71 ------------------ docker/prod/nginx.conf | 43 ----------- exchange/docker/dev/grafana_data/grafana.db | Bin 1589248 -> 1589248 bytes exchange/src/exchange/sandbox_server/crow.cpp | 12 ++- exchange/src/linter/crow/crow.cpp | 6 +- .../api/protected/db/user/createAlgo/route.ts | 8 +- web/app/dash/submissions/[id]/page.tsx | 17 ++--- web/app/dash/submit/form.tsx | 31 ++++---- webserver/{WebserverDockerfile => Dockerfile} | 2 +- webserver/src/main.rs | 28 +++---- 11 files changed, 56 insertions(+), 164 deletions(-) delete mode 100644 docker/prod/docker-compose.yml delete mode 100644 docker/prod/nginx.conf rename webserver/{WebserverDockerfile => Dockerfile} (91%) diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index a2013f35..a35d127c 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -20,7 +20,7 @@ services: image: nutc-webserver build: context: ../.. - dockerfile: webserver/WebserverDockerfile + dockerfile: webserver/Dockerfile restart: unless-stopped linter: diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml deleted file mode 100644 index 9b092074..00000000 --- a/docker/prod/docker-compose.yml +++ /dev/null @@ -1,71 +0,0 @@ -# Full stack docker compose -# Remove web/firebase components for prod - -version: '3' -services: - sandbox: - image: nutc-exchange - build: - context: .. - dockerfile: exchange/docker/sandbox/Dockerfile - args: - firebase_emulator: "false" - restart: unless-stopped - environment: - - NUTC_EXPOSE_METRICS=1 - command: ["--bots-only"] - - #port: 16124 - webserver: - image: nutc-webserver - build: - context: .. - dockerfile: webserver/WebserverDockerfile - restart: unless-stopped - - linter: - image: nutc-linter - restart: unless-stopped - build: - context: .. - dockerfile: linter/LinterDockerfile - args: - firebase_emulator: "false" - - # Exposed on port 9000 - prometheus: - image: prom/prometheus - volumes: - - ../exchange/docker/sandbox/prometheus.yml:/etc/prometheus/prometheus.yml - command: - - '--config.file=/etc/prometheus/prometheus.yml' - - '--storage.tsdb.retention.time=12h' - restart: unless-stopped - - reverse-proxy: - image: nginx:latest - ports: - - "26389:80" - volumes: - - ./nginx.conf:/etc/nginx/nginx.conf - restart: unless-stopped - depends_on: - - webserver - - grafana - - grafana: - image: grafana/grafana - restart: unless-stopped - user: "${UID}:${GID}" - ports: - - "3001:3001" - environment: - - GF_SECURITY_ALLOW_EMBEDDING=true - - GF_AUTH_ANONYMOUS_ENABLED=true - - GF_AUTH_ANONYMOUS_ORG_NAME=MAIN - - GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer - volumes: - - ../exchange/docker/sandbox/grafana_data:/var/lib/grafana - # - /var/lib/grafana/grafana.db - # - /var/lib/grafana/alerting - diff --git a/docker/prod/nginx.conf b/docker/prod/nginx.conf deleted file mode 100644 index e5a98e58..00000000 --- a/docker/prod/nginx.conf +++ /dev/null @@ -1,43 +0,0 @@ -user nginx; -worker_processes 1; - -events { - worker_connections 1024; -} - - -http { - sendfile on; - keepalive_timeout 65; - - map $http_upgrade $connection_upgrade { - default upgrade; - '' close; - } - - server { - listen 80; - - location /webserver/ { - rewrite ^/webserver(/.*)$ $1 break; - proxy_pass http://webserver:16124; - proxy_set_header Host $host; - # proxy_http_version 1.1; - # proxy_set_header Upgrade $http_upgrade; - # proxy_set_header Connection "upgrade"; - } - - location / { - proxy_pass http://grafana:3000; - proxy_set_header Host $host; - } - - location /api/live/ { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - proxy_set_header Host $host; - proxy_pass http://grafana:3000; - } - } -} diff --git a/exchange/docker/dev/grafana_data/grafana.db b/exchange/docker/dev/grafana_data/grafana.db index 0d3083a08be613302867ef320ecabcdd177df1ab..8ae6c2208e6089013edc8feee276d029806a0abb 100644 GIT binary patch delta 521 zcmbu6Jxd%>6ozNkkGZ?!%&f*JqG+LD5nSiqJ9}rxO3+%aKR~!&bNvI`yIP!}DPjs4 zwn-r*WkeJgQm2hgAPUyPcKQQ^bqYHx@f=S3yyxNVbY!O^k7wPJZ*v>&$+WXH%wSA&9XDla zamutZQtLELsA9@0-J)0#OSR1t6E{hV*hIz#GesG;IHx+Zl*J}yw3QH>n^@+=XvK0< z#%MCZY;3L8#xz-)<)*1*alI2R72iX&So{sp7}|Bu{*+d-_b)`u^?pa~upjnIhug5| z&!d~|_kJAI9LK3dZ6|6+B|U1tup8)R{cSd{Wj+s9QF+zgV6`?_C_4dO1MUMK10Dbm Zfk(jWz{i140RI4d68J~pQ$P9i<1_sbqzM23 delta 528 zcmbu6J4?hs6or%Zk?h7K>l;zDQ0$B|lSwAA64X{kdu1juv$n!^7Ooao77Mis3%1&d z2rk&$+6XH61Kdvk!5YERM!bj9T)2nxaT^WUXvnikegAxFMc=;>*9&^{w(51TiRe;* zmMA?EAaoEV5IrDzLG*#>zZ1sEY2SQJ-=5CTK8)4UrfNTb7>};r%rCo!th{UXyYptX ztk&(|a?@(JEOWhdaJXkzweq1|Xkxb9Ta2k96%kCN%qS%)BUyl{pDL8%OyNL9m?4%V zI8GCcaEJqmaHN { - const LINES = str.split("\n"); - return LINES.map((line: string, index: number) => ( - -

{line}

- {index < LINES.length - 1 &&
} -
- )); + function formatNewLines(str: string): TrustedHTML { + return str.replace(/\\n/g, "
"); }; const lintFailureMessage = algo?.lintFailureMessage; @@ -69,6 +63,11 @@ export default async function SubmissionPage(props: { ); } else { - return formatNewLines(stringToRender); + return
+

Error Log

+
+
+
+
} } diff --git a/web/app/dash/submit/form.tsx b/web/app/dash/submit/form.tsx index b2449402..5bf4ffc3 100644 --- a/web/app/dash/submit/form.tsx +++ b/web/app/dash/submit/form.tsx @@ -61,8 +61,8 @@ export default function SubmissionForm(props: { user: any }) { }); const onSubmit: SubmitHandler = async data => { - Swal.fire({ title: "Submissions not yet open", text: "Check back October 6th" }); - return; + // Swal.fire({ title: "Submissions not yet open", text: "Check back October 6th" }); + // return; const responsePromise = fetch("/api/protected/db/user/createAlgo", { method: "POST", body: JSON.stringify(data), @@ -78,24 +78,21 @@ export default function SubmissionForm(props: { user: any }) { Swal.showLoading(); const response = await responsePromise; - Swal.close(); if (!response.ok) { + Swal.fire({ title: "Error", icon: "error", text: "Server error. Please contact the nuft team in the piazza" }); + return; + } + Swal.close(); + var { success, message } = await response.json(); + message = message.replace(/\\n/g, "
"); + if (!success) { Swal.fire({ - title: "Error", + title: "Compilation/Linting Error", icon: "error", - text: "An error occurred", - toast: true, - position: "top-end", - showConfirmButton: false, - timer: 4000, - timerProgressBar: true, - didOpen: toast => { - toast.addEventListener("mouseenter", Swal.stopTimer); - toast.addEventListener("mouseleave", Swal.resumeTimer); - }, + html: message, + width: 800, + showConfirmButton: true, }); - const errMsg = await response.text(); - alert(errMsg); } else { Swal.fire({ title: "Linting complete!", @@ -179,8 +176,6 @@ export default function SubmissionForm(props: { user: any }) { handleAlgoChange(files[0]); }; - console.log("key", algoFileS3Key); - return (
diff --git a/webserver/WebserverDockerfile b/webserver/Dockerfile similarity index 91% rename from webserver/WebserverDockerfile rename to webserver/Dockerfile index b99b09f0..f0358fb9 100644 --- a/webserver/WebserverDockerfile +++ b/webserver/Dockerfile @@ -12,7 +12,7 @@ COPY webserver/src src RUN cargo build --release -COPY web/.env .env +COPY webserver/.env .env EXPOSE 16124 diff --git a/webserver/src/main.rs b/webserver/src/main.rs index afe792d0..65ee670f 100644 --- a/webserver/src/main.rs +++ b/webserver/src/main.rs @@ -17,7 +17,7 @@ pub struct LinterResponse { #[derive(Deserialize, Debug)] struct LintResult { - lint_success: bool, + success: bool, message: String, } @@ -62,8 +62,8 @@ async fn handle_algo_submission( let (algo_id, language) = data.into_inner(); - let s3_endpoint = std::env::var("INTERNAL_S3_ENDPOINT") - .expect("env variable `INTERNAL_S3_ENDPOINT` should be set"); + let s3_endpoint = + std::env::var("S3_ENDPOINT").expect("env variable `S3_ENDPOINT` should be set"); let algo_url = format!("{}/nutc/{}", s3_endpoint, algo_id); let linter_url = format!( @@ -94,14 +94,14 @@ async fn handle_algo_submission( tracing::error!("failed to update linter status in database, {:?}", e); return HttpResponse::BadGateway().finish(); } - if linter_response.lint_success { - tracing::info!("linting success now requesting sandbox"); + if linter_response.success { + tracing::info!("Linting succeeded, now requesting sandbox"); } else { // forward the error message from the linter, and add something in the response // to indicate that the linter Failed tracing::error!("linting failed: {}", linter_response.message); return HttpResponse::Ok() - .json(json!({"status": "lint failure", "message": linter_response.message})); + .json(json!({"success": false, "message": linter_response.message})); } // todo: this function shouldnt return a http request @@ -132,17 +132,19 @@ async fn request_sandbox(algo_id: String, algo_url: String, language: String) -> match sandbox_response { Ok(response) => { - let body = response.text().await; - tracing::info!( - "sandbox response: {}", - body.unwrap_or("failed to decode sandbox response".into()) - ); - return HttpResponse::Ok().finish(); + let text_body = response.text().await; + let text = text_body.unwrap(); + tracing::info!("sandbox response: {}", text); + return HttpResponse::Ok() + .content_type("application/json") + .body(text); } Err(err) => { tracing::error!("failed to request sandbox {:#?}", err); tracing::error!("someting went wrong requesting to sandbox"); - return HttpResponse::BadGateway().finish(); + return HttpResponse::BadGateway() + .content_type("application/json") + .body("{\"success\": false}"); } } }