From 757a2a16424696878ccfb4d306d8072908455639 Mon Sep 17 00:00:00 2001 From: Abhijna Raghavendra Date: Fri, 16 Feb 2024 17:08:00 +0530 Subject: [PATCH] fix: fix copy bug --- src/backend/db.ts | 3 -- src/backend/main.ts | 2 +- src/backend/scripts.ts | 43 ++++++++++--------- .../{utils => shell_scripts}/automate.sh | 0 .../{utils => shell_scripts}/container.sh | 2 - .../{utils => shell_scripts}/delete.sh | 0 src/backend/utils/container.ts | 17 ++------ 7 files changed, 27 insertions(+), 40 deletions(-) rename src/backend/{utils => shell_scripts}/automate.sh (100%) mode change 100755 => 100644 rename src/backend/{utils => shell_scripts}/container.sh (98%) mode change 100755 => 100644 rename src/backend/{utils => shell_scripts}/delete.sh (100%) diff --git a/src/backend/db.ts b/src/backend/db.ts index 450b8a5..b127480 100644 --- a/src/backend/db.ts +++ b/src/backend/db.ts @@ -1,7 +1,4 @@ import getGithubUser from "./utils/github-user.ts"; -import { Context, exec, Sentry } from "./dependencies.ts"; -import dockerize from "./utils/container.ts"; -import { checkJWT } from "./utils/jwt.ts"; import DfContentMap from "./types/maps_interface.ts"; const DATA_API_KEY = Deno.env.get("MONGO_API_KEY")!; diff --git a/src/backend/main.ts b/src/backend/main.ts index a30fd08..d741412 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -25,7 +25,7 @@ async function addSubdomain(ctx: Context) { } catch (e) { document = body; } - const copy = document; + const copy = { ...document }; const token = document.token; delete document.token; delete document.port; diff --git a/src/backend/scripts.ts b/src/backend/scripts.ts index d3933a8..4bf4fdb 100644 --- a/src/backend/scripts.ts +++ b/src/backend/scripts.ts @@ -10,31 +10,32 @@ async function addScript( port: string, build_cmds: string, ) { - if (document.resource_type === "URL") { - await exec( - `bash -c "echo 'bash ../../src/backend/utils/automate.sh -u ${document.resource} ${document.subdomain}' > /hostpipe/pipe"`, - ); - } else if (document.resource_type === "PORT") { - await exec( - `bash -c "echo 'bash ../../src/backend/utils/automate.sh -p ${document.resource} ${document.subdomain}' > /hostpipe/pipe"`, - ); - } else if (document.resource_type === "GITHUB" && static_content == "Yes") { - Deno.writeTextFile(`/hostpipe/.env`,env_content) - await exec( - `bash -c "echo 'bash ../../src/backend/utils/container.sh -s ${document.subdomain} ${document.resource}' > /hostpipe/pipe"`, - ); - } else if (document.resource_type === "GITHUB" && static_content == "No") { - let dockerfile = dockerize(stack, port, build_cmds); - Deno.writeTextFile(`/hostpipe/Dockerfile`,dockerfile) - Deno.writeTextFile(`/hostpipe/.env`,env_content) - await exec( - `bash -c "echo 'bash ../../src/backend/utils/container.sh -g ${document.subdomain} ${document.resource} ${port}' > /hostpipe/pipe"`); - } + if (document.resource_type === "URL") { + await exec( + `bash -c "echo 'bash ../../src/backend/shell_scripts/automate.sh -u ${document.resource} ${document.subdomain}' > /hostpipe/pipe"`, + ); + } else if (document.resource_type === "PORT") { + await exec( + `bash -c "echo 'bash ../../src/backend/shell_scripts/automate.sh -p ${document.resource} ${document.subdomain}' > /hostpipe/pipe"`, + ); + } else if (document.resource_type === "GITHUB" && static_content == "Yes") { + Deno.writeTextFile(`/hostpipe/.env`, env_content); + await exec( + `bash -c "echo 'bash ../../src/backend/shell_scripts/container.sh -s ${document.subdomain} ${document.resource}' > /hostpipe/pipe"`, + ); + } else if (document.resource_type === "GITHUB" && static_content == "No") { + const dockerfile = dockerize(stack, port, build_cmds); + Deno.writeTextFile(`/hostpipe/Dockerfile`, dockerfile); + Deno.writeTextFile(`/hostpipe/.env`, env_content); + await exec( + `bash -c "echo 'bash ../../src/backend/shell_scripts/container.sh -g ${document.subdomain} ${document.resource} ${port}' > /hostpipe/pipe"`, + ); + } } async function deleteScript(document: DfContentMap) { await exec( - `bash -c "echo 'bash ../../src/backend/utils/delete.sh ${document.subdomain}' > /hostpipe/pipe"`, + `bash -c "echo 'bash ../../src/backend/shell_scripts/delete.sh ${document.subdomain}' > /hostpipe/pipe"`, ); } diff --git a/src/backend/utils/automate.sh b/src/backend/shell_scripts/automate.sh old mode 100755 new mode 100644 similarity index 100% rename from src/backend/utils/automate.sh rename to src/backend/shell_scripts/automate.sh diff --git a/src/backend/utils/container.sh b/src/backend/shell_scripts/container.sh old mode 100755 new mode 100644 similarity index 98% rename from src/backend/utils/container.sh rename to src/backend/shell_scripts/container.sh index 24c8dfc..ca86f83 --- a/src/backend/utils/container.sh +++ b/src/backend/shell_scripts/container.sh @@ -16,8 +16,6 @@ done echo "Available ports: ${available_ports[56]}" AVAILABLE=0 if [ $flag = "-g" ]; then - echo "idhar"; - echo 'hello' git clone $resource $name sudo cp Dockerfile $name/ sudo cp .env $name/ diff --git a/src/backend/utils/delete.sh b/src/backend/shell_scripts/delete.sh similarity index 100% rename from src/backend/utils/delete.sh rename to src/backend/shell_scripts/delete.sh diff --git a/src/backend/utils/container.ts b/src/backend/utils/container.ts index 9e73c4a..3a1118b 100644 --- a/src/backend/utils/container.ts +++ b/src/backend/utils/container.ts @@ -4,9 +4,9 @@ export default function dockerize( build_cmds: string, ) { let dockerfile = ""; - let run_cmd = build_cmds.split("\n"); - let execute_cmd = "CMD " + JSON.stringify(run_cmd.pop().split(" ")); - let build_cmds_mapped = run_cmd.map((elem) => { + const run_cmd = build_cmds.split("\n"); + const execute_cmd = "CMD " + JSON.stringify(run_cmd.pop()?.split(" ")); + const build_cmds_mapped = run_cmd.map((elem) => { return "RUN " + elem; }).join("\n"); if (stack == "Python") { @@ -17,16 +17,7 @@ export default function dockerize( dockerfile = "FROM node:latest \n WORKDIR /app \n COPY ./package*.json . \n RUN npm install \n COPY . ." + build_cmds_mapped + `\n EXPOSE ${port} \n` + execute_cmd; - console.log(port) + console.log(port); } - // dockerfile = btoa(dockerfile); return dockerfile.toString(); } - -// bash ./container.sh -g hack "https://github.com/angelmittal03/mdg-text.git" 'FROM node:latest -// WORKDIR /app -// COPY ./client/package*.json . -// RUN npm install -// COPY . . -// EXPOSE 3000 -// CMD ["npm","start"]' 3000