Skip to content

what is different #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
.DS_Store
.idea
backend/web

#### backend
node_modules
yarn.lock
package.json.lock
package-lock.json
data.db

#### client
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM node:18-alpine
WORKDIR /src

# Install Python, pip, and build tools in one RUN command
RUN apk add --no-cache python3 py3-pip build-base docker-cli
RUN apk add --no-cache python3 py3-pip build-base docker-cli ffmpeg

# Copy application files to the container
COPY ./backend /src/backend
Expand Down
4 changes: 3 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const path = require("path");
const { safeTerminal } = require("./backend/utilities/terminal");
const port = 3230;

global.container_env_variables = '';

async function app() {
console.clear();

Expand All @@ -23,4 +25,4 @@ async function app() {
await safeTerminal.serve(BACKEND);
}

app();
app();
5 changes: 0 additions & 5 deletions backend/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
### TODO: image post documentation
## Backend API

- Get a list of containers
Expand Down
19 changes: 18 additions & 1 deletion backend/controllers/ImageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,29 @@ exports.fetch = async (req, res) => {
};

exports.command = async (req, res, next) => {
console.log(req.query.env);
const imageID = req.query.image;
const command = req.query.command;
const env = req.query.env;
try {
const cmdData = await safeTerminal.singleImage(command, imageID);
const cmdData = await safeTerminal.singleImage(command, imageID, env);
res.json(cmdData.replace("\n", ""));
} catch (error) {
next(error);
}
};

exports.pull = async (req, res) => {
try {
const images = await safeTerminal.pull(req.query.name);
res.json(images.replace("\n", ""));
} catch (error) {
console.log(error)
}

// const imagesArray = images
// .split("\n")
// .filter((image) => image !== "")
// .map((image) => JSON.parse(image));
// res.json(imagesArray);
};
1 change: 1 addition & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ app.get("/api/container/stats", ContainerController.stats);

app.get("/api/image/fetch", ImageController.fetch);
app.get("/api/image/command", ImageController.command);
app.post("/api/image", ImageController.pull);
app.get("/api/cleanup/command", CleanUpController.command);

app.post("/api/groups", GroupController.create);
Expand Down
84 changes: 84 additions & 0 deletions backend/utilities/terminal copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const child_process = require("child_process");
console.log('Starting child process...');

const isValidId = (id) => /^[0-9a-zA-Z]+$/.test(id.trim());
const isValidString = (id) => /^[a-zA-Z]+$/.test(id.trim());

const Terminal = (command) =>
new Promise((resolve, reject) => {
child_process.exec(
command,
{ maxBuffer: 1500 * 1024 },
function (error, stdout, stderr) {
if (!!error) reject(error);
else resolve(stdout || stderr);
}
);
});

exports.safeTerminal = {
installModules: async (backendPath) => {
await Terminal(`cd ${backendPath} && npm install`);
},
serve: async (backendPath) => {
await Terminal(`cd ${backendPath} && node index.js`);
},
allContainers: () => Terminal(`docker ps -q -a`),
inspectContainer: async (id) => {
if (isValidId(id)) {
return Terminal(`docker container inspect ${id}`);
} else {
throw new Error("The container id is invalid");
}
},
generic: async (task, id) => {
if (!isValidString(task)) {
throw new Error("The task command is invalid.");
}
if (!isValidId(id)) {
throw new Error("The container id is invalid");
}
return Terminal(`docker container ${task} ${id}`);
},
pull: async (id) => {
if (!isValidId(id)) {
throw new Error("The container id is invalid");
}
return Terminal(`au9913/nostrdvm`);
// return Terminal(`docker pull ${id}`);
},
logs: async (id) => {
if (!isValidId(id)) {
throw new Error("The container id is invalid");
}
return Terminal(`docker container logs ${id} --tail 1500`);
},
stats: () =>
Terminal(
`docker container stats --no-stream --format '{"id": "{{.ID}}", "cpu_percentage": "{{.CPUPerc}}", "memory_usage": "{{.MemUsage}}", "network_io": "{{.NetIO}}"}'`
),
prune: (pruneType) => {
if (!isValidString(pruneType)) {
throw new Error("The entity type is not valid");
}
return Terminal(`docker ${pruneType} prune -f`);
},
containerLs: () => Terminal(`docker container ls --format '{{json .}}'`),
formattedImages: () =>
Terminal(
`docker images --format '{"ID": "{{.ID}}", "Tag": "{{.Tag}}", "CreatedSince": "{{.CreatedSince}}", "Size": "{{.Size}}", "VirtualSize": "{{.VirtualSize}}", "Repository": "{{.Repository}}"}'`
),
singleImage: (task, id) => {
if (!isValidString(task)) {
throw new Error("The task command is invalid.");
}
if (!isValidId(id)) {
throw new Error("The image id is invalid");
}
if (task == "run") {
return Terminal(`docker ${task} ${id}`);
} else {
return Terminal(`docker image ${task} ${id}`);
}
},
};
42 changes: 35 additions & 7 deletions backend/utilities/terminal.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
const child_process = require("child_process");
console.log('Starting child process...');

const isValidId = (id) => /^[0-9a-zA-Z]+$/.test(id.trim());
const isValidId = (id) => /^[0-9a-zA-Z\/\.\:\-]+$/.test(id.trim());
const isValidString = (id) => /^[a-zA-Z]+$/.test(id.trim());

const Terminal = (command) =>
new Promise((resolve, reject) => {
child_process.exec(
console.log(`Executing command: ${command}`);
const child = child_process.exec(
command,
{ maxBuffer: 1500 * 1024 },
function (error, stdout, stderr) {
if (!!error) reject(error);
else resolve(stdout || stderr);
if (error) {
console.error(`Error: ${error.message}`);
return reject(error);
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
}
console.log(`Stdout: ${stdout}`);
resolve(stdout || stderr);
}
);

child.stdout.on('data', (data) => {
console.log(`Child stdout: ${data}`);
});

child.stderr.on('data', (data) => {
console.error(`Child stderr: ${data}`);
});
});

exports.safeTerminal = {
Expand All @@ -39,6 +56,13 @@ exports.safeTerminal = {
}
return Terminal(`docker container ${task} ${id}`);
},
pull: async (id) => {
if (!isValidId(id)) {
throw new Error("The container id is invalid");
}
Terminal(`echo pulling ${id}`);
return Terminal(`docker pull ${id}`);
},
logs: async (id) => {
if (!isValidId(id)) {
throw new Error("The container id is invalid");
Expand All @@ -60,17 +84,21 @@ exports.safeTerminal = {
Terminal(
`docker images --format '{"ID": "{{.ID}}", "Tag": "{{.Tag}}", "CreatedSince": "{{.CreatedSince}}", "Size": "{{.Size}}", "VirtualSize": "{{.VirtualSize}}", "Repository": "{{.Repository}}"}'`
),
singleImage: (task, id) => {
singleImage: (task, id, env) => {
if (!isValidString(task)) {
throw new Error("The task command is invalid.");
}
if (!isValidId(id)) {
throw new Error("The image id is invalid");
}
if (task == "run") {
return Terminal(`docker ${task} ${id}`);
const envs = env.replace(/\n/g, ' -e ')
Terminal(`echo ==========================`)
Terminal(`echo ${envs}`)
Terminal(`echo docker ${task} -e ${envs} ${id}`)
return Terminal(`docker ${task} -e ${envs} ${id}`);
} else {
return Terminal(`docker image ${task} ${id}`);
}
},
};
};
15 changes: 0 additions & 15 deletions backend/web/asset-manifest.json

This file was deleted.

Binary file removed backend/web/docker-icon.png
Binary file not shown.
Binary file removed backend/web/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion backend/web/index.html

This file was deleted.

Binary file removed backend/web/logo192.png
Binary file not shown.
Binary file removed backend/web/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions backend/web/manifest.json

This file was deleted.

22 changes: 0 additions & 22 deletions backend/web/precache-manifest.adb95cf9ceba078f9a2aef310d78b377.js

This file was deleted.

2 changes: 0 additions & 2 deletions backend/web/robots.txt

This file was deleted.

39 changes: 0 additions & 39 deletions backend/web/service-worker.js

This file was deleted.

2 changes: 0 additions & 2 deletions backend/web/static/css/main.ab6a2c25.chunk.css

This file was deleted.

1 change: 0 additions & 1 deletion backend/web/static/css/main.ab6a2c25.chunk.css.map

This file was deleted.

2 changes: 0 additions & 2 deletions backend/web/static/js/2.f3d6def3.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion backend/web/static/js/2.f3d6def3.chunk.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions backend/web/static/js/main.5147f23d.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion backend/web/static/js/main.5147f23d.chunk.js.map

This file was deleted.

Loading