From fc2244bf31ebf0610ff7a021585b77056ea959b6 Mon Sep 17 00:00:00 2001 From: Gregory Bell Date: Wed, 3 Jul 2024 18:25:12 -0600 Subject: [PATCH] Finally get it working in docker --- Dockerfile | 2 ++ src/gradescope_assignment_uploader.ts | 29 +++++++++++++++++++++++++++ src/run.ts | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5c95bcc..6e3332a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,8 @@ USER root RUN apt-get update && \ apt-get install -y libgbm-dev xvfb +USER pptruser + COPY --from=builder /app/dist /dist ADD --chmod=777 entrypoint.sh /entrypoint.sh diff --git a/src/gradescope_assignment_uploader.ts b/src/gradescope_assignment_uploader.ts index 0f8e93e..2130b22 100644 --- a/src/gradescope_assignment_uploader.ts +++ b/src/gradescope_assignment_uploader.ts @@ -3,6 +3,7 @@ import * as puppeteer from "puppeteer"; const GRADESCOPE_AUTOGRADER_SUBMIT_BUTTON_CLASS = ".js-submitAutograder"; const GRADESCOPE_AUTOGRADER_FILE_UPLOAD = "input[type='file']"; const GRADESCOPE_AUTOGRADER_ERRORS_CLASS = ".js-autograderZipErrors"; +const GRADESCOPE_PLATFORM_ERROR_CLASS = ".alert-error"; export async function navigate_to_uploader_page( page: puppeteer.Page, @@ -34,21 +35,31 @@ export async function upload_zip_file( return false; } + console.log(`Uploading ${path_to_zip}...`); + await upload_input.uploadFile(path_to_zip); const uploader_errors = await upload_form.$( GRADESCOPE_AUTOGRADER_ERRORS_CLASS, ); + if (uploader_errors === null) { console.error("Failed to check for errors!"); return false; } if (await uploader_errors.isVisible()) { + console.error("Failed to upload autograder!"); console.error(await uploader_errors.evaluate((el) => el.textContent)); return false; } + const uploaded_file = await ( + await upload_form.$(".js-fileUploadPrompt") + )?.evaluate((el) => el.textContent); + + console.log(`${uploaded_file} was uploaded`); + const upload_btn = await upload_form.$( GRADESCOPE_AUTOGRADER_SUBMIT_BUTTON_CLASS, ); @@ -61,7 +72,25 @@ export async function upload_zip_file( return false; } + // @ts-ignore + if (await upload_btn.evaluate((el) => el.disabled)) { + console.error( + "Submit button is disabled! Unable to commit autograder zip.", + ); + return false; + } + await upload_btn.click(); + await page.waitForNavigation({ waitUntil: "networkidle2" }); + + const submit_errors = await page.$(GRADESCOPE_PLATFORM_ERROR_CLASS); + + if (submit_errors !== null) { + console.error("Failed to submit autograder."); + console.error(await submit_errors.evaluate((el) => el.textContent)); + return false; + } + return true; } diff --git a/src/run.ts b/src/run.ts index a1a86dc..5324793 100644 --- a/src/run.ts +++ b/src/run.ts @@ -22,9 +22,9 @@ export async function run( headless: false, executablePath: chrome_path, args: [ - `--no-sandbox`, + // `--no-sandbox`, // `--headless` - `--disable-setuid-sandbox`, + // `--disable-setuid-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`, ],