Skip to content

Commit

Permalink
change the marker side to have dockerfiles as uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush272002 committed Dec 9, 2024
1 parent 02bf0db commit dd5f802
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 26 deletions.
12 changes: 12 additions & 0 deletions MarkingScripts/multiply/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:alpine

RUN apk add --no-cache bash

WORKDIR /app

COPY sol.js ./
COPY mark.sh ./

RUN chmod +x mark.sh

CMD ["bash", "mark.sh"]
2 changes: 1 addition & 1 deletion MarkingScripts/mark.sh → MarkingScripts/multiply/mark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
echo "Running tests for the mul function..."

# Path to the student code file
STUDENT_CODE="/app/mul.js"
STUDENT_CODE="/app/sol.js"

# Check if the file exists
if [ ! -f "$STUDENT_CODE" ]; then
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions MarkingScripts/sum/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:alpine

RUN apk add --no-cache bash

WORKDIR /app

COPY sol.js ./
COPY mark.sh ./

RUN chmod +x mark.sh

CMD ["bash", "mark.sh"]
2 changes: 1 addition & 1 deletion MarkingScripts/mark1.sh → MarkingScripts/sum/mark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
echo "Running tests for the sum function..."

# Path to the student code file
STUDENT_CODE="/app/sum.js"
STUDENT_CODE="/app/sol.js"

# Check if the file exists
if [ ! -f "$STUDENT_CODE" ]; then
Expand Down
File renamed without changes.
16 changes: 12 additions & 4 deletions apps/backend/src/controllers/assignmentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const submitAssignment = async (req: Request, res: Response) => {
},
select: {
markingScript: true,
requiredFiles: true,
dockerFile: true,
},
},
},
Expand All @@ -260,7 +260,7 @@ const submitAssignment = async (req: Request, res: Response) => {
const assignmentZip = parsedData.data.assignmentZip;
const payload = {
markingScript: user.student.courses[0].assignments[0].markingScript,
requiredFiles: user.student.courses[0].assignments[0].requiredFiles,
dockerFile: user.student.courses[0].assignments[0].dockerFile,
userId: parsedData.data.userId,
assignmentId: parsedData.data.assignmentId,
uploadLink: parsedData.data.assignmentZip,
Expand Down Expand Up @@ -313,8 +313,15 @@ const submitAssignment = async (req: Request, res: Response) => {
};

const createAssignment = async (req: Request, res: Response) => {
const { title, description, dueDate, maxMarks, courseId, markingScript } =
req.body;
const {
title,
description,
dueDate,
maxMarks,
courseId,
markingScript,
dockerFile,
} = req.body;

if (!title || !dueDate || !maxMarks || !courseId) {
return res.status(400).json({
Expand All @@ -341,6 +348,7 @@ const createAssignment = async (req: Request, res: Response) => {
maxMarks: parseInt(maxMarks, 10),
courseId,
markingScript,
dockerFile,
},
});

Expand Down
64 changes: 45 additions & 19 deletions apps/frontend/app/marker/course/[courseId]/publish/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { motion } from 'framer-motion';
import { toast } from 'react-toastify';
import axios from 'axios';
import { UploadClient } from '@uploadcare/upload-client';
import { Loader2 } from 'lucide-react';

const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL;

Expand All @@ -16,20 +17,23 @@ export default function PublishAssignment() {
const [description, setDescription] = useState('');
const [dueDate, setDueDate] = useState('');
const [maxMarks, setMaxMarks] = useState('');
const [markingScript, setMarkingScript] = useState<string | null>(null);
const [markingScript, setMarkingScript] = useState<File | null>(null);
const [dockerFile, setDockerFile] = useState<File | null>(null);
const [uploading, setUploading] = useState(false);

const handleFileUpload = async (file: File) => {
const handleFileUpload = async (file: File): Promise<string | null> => {
const client = new UploadClient({
publicKey: process.env.NEXT_PUBLIC_UPLOADCARE_PUBLIC_KEY!,
});

try {
const result = await client.uploadFile(file);
setMarkingScript(result.cdnUrl);
toast.success('Marking script uploaded successfully!');
toast.success(`${file.name} uploaded successfully!`);
return result.cdnUrl;
} catch (error) {
console.error('File upload failed:', error);
toast.error('Failed to upload marking script.');
toast.error(`Failed to upload ${file.name}.`);
return null;
}
};

Expand All @@ -39,7 +43,21 @@ export default function PublishAssignment() {
return;
}

if (!markingScript || !dockerFile) {
toast.error('Please upload both the Marking Script and Docker File.');
return;
}

setUploading(true);
try {
const markingScriptUrl = await handleFileUpload(markingScript);
const dockerFileUrl = await handleFileUpload(dockerFile);

if (!markingScriptUrl || !dockerFileUrl) {
toast.error('File uploads failed. Please try again.');
return;
}

const response = await axios.post(
`${API_BASE_URL}/api/v1/assignments`,
{
Expand All @@ -48,7 +66,8 @@ export default function PublishAssignment() {
dueDate: new Date(dueDate).toISOString(),
maxMarks: parseInt(maxMarks, 10),
courseId,
markingScript,
markingScript: markingScriptUrl,
dockerFile: dockerFileUrl,
},
{
withCredentials: true,
Expand All @@ -62,6 +81,8 @@ export default function PublishAssignment() {
} catch (error) {
console.error('Assignment creation failed:', error);
toast.error('Failed to publish assignment.');
} finally {
setUploading(false);
}
};

Expand Down Expand Up @@ -105,29 +126,34 @@ export default function PublishAssignment() {
onChange={(e) => setMaxMarks(e.target.value)}
/>

<label className="block text-gray-400">
Marking Script (optional):
</label>
<label className="block text-gray-400">Marking Script :</label>
<input
type="file"
className="w-full p-2 rounded bg-gray-700 text-white"
onChange={(e) => {
if (e.target.files?.[0]) setMarkingScript(e.target.files[0]);
}}
/>

<label className="block text-gray-400">Docker File :</label>
<input
type="file"
className="w-full p-2 rounded bg-gray-700 text-white"
onChange={(e) => {
if (e.target.files?.[0]) handleFileUpload(e.target.files[0]);
if (e.target.files?.[0]) setDockerFile(e.target.files[0]);
}}
/>
{markingScript && (
<p className="text-sm text-green-400">
Uploaded successfully:{' '}
<a href={markingScript} target="_blank">
{markingScript}
</a>
</p>
)}

<button
className="w-full bg-blue-600 text-white py-2 rounded mt-4 hover:bg-blue-700"
className={`w-full bg-blue-600 text-white py-2 rounded mt-4 hover:bg-blue-700 ${
uploading ? 'cursor-not-allowed opacity-50' : ''
}`}
disabled={uploading}
onClick={handleSubmit}
>
{uploading ? (
<Loader2 className="animate-spin h-5 w-5 inline-block mr-2" />
) : null}
Publish Assignment
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:
- You are about to drop the column `requiredFiles` on the `Assignment` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Assignment" DROP COLUMN "requiredFiles",
ADD COLUMN "dockerFile" TEXT;
2 changes: 1 addition & 1 deletion packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ model Assignment {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
markingScript String?
requiredFiles String?
dockerFile String?
maxMarks Int
courseId String
course Course @relation(fields: [courseId], references: [id])
Expand Down

0 comments on commit dd5f802

Please sign in to comment.