submit assignment now creates an fly machine
This commit is contained in:
parent
d326366448
commit
5ce01158ad
8 changed files with 215 additions and 128 deletions
|
|
@ -1,3 +1,3 @@
|
|||
#DB_ASSIGNMENT_SERVICE_URL = "http://localhost:3000"
|
||||
DB_ASSIGNMENT_SERVICE_URL = "http://db-assignment-service.internal:3000"
|
||||
DEPLOY_API_URL="http://localhost:3006"
|
||||
NODE_PORT = 8080
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
NODE_ENV=development
|
||||
#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000"
|
||||
DB_ASSIGNMENT_SERVICE_URL="http://localhost:3200"
|
||||
AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42"
|
||||
ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173
|
||||
DEPLOY_API_URL="http://127.0.0.1:3006"
|
||||
|
||||
AWS_ACCESS_KEY_ID='tid__NSmOVaGknqitaCySppZjqVTgJSdDFnFbWcQllkC_juHwkbQZO'
|
||||
AWS_ENDPOINT_URL_S3='https://fly.storage.tigris.dev'
|
||||
AWS_REGION='auto'
|
||||
AWS_SECRET_ACCESS_KEY='tsec_6Bz1aMbfYQftuq5WfIVEDZkHwskU4MMjVywdtxSP6uxetEBvkSC2VHI9HfTeDgHr4D6kiz'
|
||||
COMMON_BUCKET='snakeapi-deployment-test-bucket'
|
||||
|
||||
NODE_PORT=8082
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
NODE_ENV=development
|
||||
#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000"
|
||||
NODE_ENV=test
|
||||
DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200"
|
||||
AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42"
|
||||
ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173
|
||||
DEPLOY_API_URL="http://localhost:3006/deploy"
|
||||
NODE_PORT=8082
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000"
|
||||
DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200"
|
||||
AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42"
|
||||
ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173
|
||||
PORT=8082
|
||||
|
|
@ -1,45 +1,98 @@
|
|||
const intructorRouter = require("express").Router();
|
||||
const passport = require("passport");
|
||||
const axios = require("axios");
|
||||
const multer = require('multer');
|
||||
const FormData = require('form-data');
|
||||
const multer = require("multer");
|
||||
const FormData = require("form-data");
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const AWS = require('aws-sdk');
|
||||
|
||||
// const {
|
||||
// COMMON_BUCKET,
|
||||
// AWS_ACCESS_KEY_ID,
|
||||
// AWS_SECRET_ACCESS_KEY,
|
||||
// AWS_ENDPOINT_URL_S3,
|
||||
// AWS_REGION,
|
||||
// } = process.env;
|
||||
|
||||
// Log environment variables for debugging
|
||||
// console.log('--- ENV START ---');
|
||||
// console.log('COMMON_BUCKET: ', COMMON_BUCKET);
|
||||
// console.log('AWS_ACCESS_KEY_ID: ', AWS_ACCESS_KEY_ID ? '(found)' : '(NOT SET)');
|
||||
// console.log('AWS_SECRET_ACCESS_KEY:', AWS_SECRET_ACCESS_KEY ? '(found)' : '(NOT SET)');
|
||||
// console.log('AWS_ENDPOINT_URL_S3: ', AWS_ENDPOINT_URL_S3);
|
||||
// console.log('AWS_REGION: ', AWS_REGION);
|
||||
// console.log('--- ENV END ---');
|
||||
|
||||
const DB_ASSIGNMENT_SERVICE_URL =
|
||||
process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000";
|
||||
|
||||
const DEPLOY_API_URL = process.env.DEPLOY_API_URL || "http://localhost:3600";
|
||||
|
||||
console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL);
|
||||
console.log("DEPLOY_API_URL:", DEPLOY_API_URL);
|
||||
|
||||
|
||||
// const s3 = new AWS.S3({
|
||||
// endpoint: AWS_ENDPOINT_URL_S3,
|
||||
// region: AWS_REGION,
|
||||
// credentials: new AWS.Credentials(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY),
|
||||
// s3ForcePathStyle: true
|
||||
// });
|
||||
|
||||
// Use memory storage to keep file in RAM
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
|
||||
|
||||
// This endpoint is for instructors to create a new assignment
|
||||
intructorRouter.post("/create",
|
||||
upload.single('file'),
|
||||
// passport.authenticate("jwt", { session: false }),
|
||||
intructorRouter.post(
|
||||
"/create",
|
||||
upload.single("file"),
|
||||
// passport.authenticate("jwt", { session: false }),
|
||||
async (req, res) => {
|
||||
try {
|
||||
|
||||
const file = req.file;
|
||||
const assignmentData = req.body;
|
||||
|
||||
if (!file) {
|
||||
return res.status(400).send('No file uploaded.');
|
||||
return res.status(400).send("No file uploaded.");
|
||||
}
|
||||
|
||||
await axios.post('https://target-api.com/endpoint', {
|
||||
filename: file.originalname,
|
||||
mimetype: file.mimetype,
|
||||
content: file.buffer.toString('base64')
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Creating a new assignment with data:", req.body);
|
||||
const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body);
|
||||
const response = await axios.post(
|
||||
`${DB_ASSIGNMENT_SERVICE_URL}/assignments`,
|
||||
req.body
|
||||
);
|
||||
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
|
||||
|
||||
// Upload the file to the S3 bucket
|
||||
// console.log('Uploading notebook to S3');
|
||||
// const key = `${assignmentData.appname}/notebooks/${Date.now()}-notebook.ipynb`;
|
||||
// console.log('S3 key:', key);
|
||||
// await s3.putObject({
|
||||
// Bucket: COMMON_BUCKET,
|
||||
// Key: key,
|
||||
// Body: file.buffer,
|
||||
// ContentType: 'application/json'
|
||||
// }).promise();
|
||||
|
||||
// call upload api to upload the file to S3
|
||||
console.log("Uploading file to:", `${DEPLOY_API_URL}/${assignmentData.appname}/upload`);
|
||||
const uploadResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/upload`, {
|
||||
"appName": assignmentData.appname,
|
||||
"notebookName": file.originalname,
|
||||
"fileContentBase64": file.buffer.toString('base64'),
|
||||
});
|
||||
console.log('Response from DEPLOY_API_URL:', uploadResponse.data);
|
||||
|
||||
// Deploy a new Battlesnake API
|
||||
console.log('Deploying a new Battlesnake API');
|
||||
console.log("DEPLOY_API_URL:", DEPLOY_API_URL, assignmentData.appname);
|
||||
const deployResponse = await axios.post(`${DEPLOY_API_URL}/deploy`, {
|
||||
"appName": assignmentData.appname
|
||||
});
|
||||
console.log('Response from DEPLOY_API_URL:', deployResponse.data);
|
||||
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
console.error("Error creating assignment:", error.message);
|
||||
|
|
@ -56,7 +109,7 @@ intructorRouter.get("/details/:id", async (req, res) => {
|
|||
const response = await axios.get(
|
||||
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`
|
||||
);
|
||||
|
||||
|
||||
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,21 @@ studentRouter.post("/save", (req, res) => {});
|
|||
|
||||
studentRouter.post("/deploy", (req, res) => {});
|
||||
|
||||
studentRouter.get("/assignment/:id", (req, res) => {
|
||||
const assignmentId = req.params.id;
|
||||
console.log("Fetching details for assignmentId:", assignmentId);
|
||||
axios
|
||||
.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`)
|
||||
.then((response) => {
|
||||
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
|
||||
res.status(response.status).json(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching assignment details:", error.message);
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
});
|
||||
});
|
||||
|
||||
studentRouter.post("/verify", async (req, res) => {
|
||||
try {
|
||||
const assignmentId = req.body.assignmentId;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue