added deploy button
This commit is contained in:
parent
b6393a7bbf
commit
4b5c74c744
3 changed files with 41 additions and 7 deletions
|
|
@ -7,16 +7,17 @@ const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL;
|
||||||
const DEPLOY_API_URL = process.env.DEPLOY_API_URL || "http://localhost:3600";
|
const DEPLOY_API_URL = process.env.DEPLOY_API_URL || "http://localhost:3600";
|
||||||
|
|
||||||
studentRouter.post("/save", async (req, res) => {
|
studentRouter.post("/save", async (req, res) => {
|
||||||
//get the app name and code and save the latest jupiter file in s3 bucket
|
//get the app name and code and save the latest jupyter file in s3 bucket
|
||||||
const { appName, code } = req.body;
|
const { appName, code } = req.body;
|
||||||
|
|
||||||
//convert the code to jupyter file format
|
|
||||||
const notebook = {
|
const notebook = {
|
||||||
cells: [
|
cells: [
|
||||||
{
|
{
|
||||||
cell_type: "code",
|
cell_type: "code",
|
||||||
execution_count: null,
|
execution_count: null,
|
||||||
metadata: {},
|
metadata: {
|
||||||
|
language: "python"
|
||||||
|
},
|
||||||
outputs: [],
|
outputs: [],
|
||||||
source: code.split('\n').map(line => line + '\n')
|
source: code.split('\n').map(line => line + '\n')
|
||||||
}
|
}
|
||||||
|
|
@ -123,4 +124,18 @@ studentRouter.post("/verify", async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// post restart from deployment service /appname/restart endpoint
|
||||||
|
studentRouter.post("/restart", async (req, res) => {
|
||||||
|
const { appName } = req.body;
|
||||||
|
console.log("Received request to restart app:", appName);
|
||||||
|
try {
|
||||||
|
const response = await axios.post(`${DEPLOY_API_URL}/${appName}/restart`);
|
||||||
|
console.log("Restart response:", response.data);
|
||||||
|
res.status(response.status).json(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error restarting app:", error.message);
|
||||||
|
res.status(error.response?.status || 500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = studentRouter;
|
module.exports = studentRouter;
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,6 @@ primary_region = 'sea'
|
||||||
IMAGE_REF="registry.fly.io/snake-api-template:latest"
|
IMAGE_REF="registry.fly.io/snake-api-template:latest"
|
||||||
FLY_API_BASE_URL = "https://api.machines.dev/v1"
|
FLY_API_BASE_URL = "https://api.machines.dev/v1"
|
||||||
|
|
||||||
[services]
|
|
||||||
internal_only = true
|
|
||||||
|
|
||||||
[http_service]
|
[http_service]
|
||||||
internal_port = 3006
|
internal_port = 3006
|
||||||
force_https = true
|
force_https = true
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,28 @@ app.post("/:appName/upload", async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// restart a Fly app
|
||||||
|
app.post("/:appName/restart", async (req, res) => {
|
||||||
|
const { appName } = req.params;
|
||||||
|
try {
|
||||||
|
const fly = createFlyClient();
|
||||||
|
const { data: machines } = await fly.get(`/apps/${appName}/machines`);
|
||||||
|
if (!machines || !Array.isArray(machines) || machines.length === 0) {
|
||||||
|
return res.status(404).json({ error: "No machines found for this app" });
|
||||||
|
}
|
||||||
|
const results = await Promise.all(
|
||||||
|
machines.map(machine =>
|
||||||
|
fly.post(`/apps/${appName}/machines/${machine.id}/restart`)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
res.json({ status: "restarted", app: appName, count: results.length });
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Restart error:", err.response?.data || err.message);
|
||||||
|
res.status(500).json({ error: err.response?.data || err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Delete a Fly app
|
// Delete a Fly app
|
||||||
app.post("/:appName/delete", async (req, res) => {
|
app.post("/:appName/delete", async (req, res) => {
|
||||||
const { appName } = req.params;
|
const { appName } = req.params;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue