Skip to content

Commit

Permalink
fix: fix copy bug ; rfac: refactor code (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijna-Raghavendra authored Feb 16, 2024
2 parents 1515890 + 757a2a1 commit 157ea38
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 40 deletions.
3 changes: 0 additions & 3 deletions src/backend/db.ts
Original file line number Diff line number Diff line change
@@ -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")!;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 22 additions & 21 deletions src/backend/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"`,
);
}

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions src/backend/utils/container.sh → src/backend/shell_scripts/container.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
File renamed without changes.
17 changes: 4 additions & 13 deletions src/backend/utils/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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

0 comments on commit 157ea38

Please sign in to comment.