Skip to content

Commit ab14bc4

Browse files
feat: took care of merge conflicts
1 parent 7261fac commit ab14bc4

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

src/backend/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ async function addSubdomain(ctx: Context) {
132132
copy.env_content,
133133
copy.static_content,
134134
copy.dockerfile_present,
135+
copy.volume_needed,
135136
copy.stack,
136137
copy.port,
137138
copy.build_cmds,
@@ -145,7 +146,7 @@ async function addSubdomain(ctx: Context) {
145146
ctx.response.body = { "status": "failed" };
146147
}
147148
}
148-
149+
//!add volume removal logic on deleting the subdomain
149150
async function deleteSubdomain(ctx: Context) {
150151
if (!ctx.request.hasBody) {
151152
ctx.throw(415);

src/backend/scripts.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ async function safeExec(command: string): Promise<void> {
2626
throw error;
2727
}
2828
}
29-
29+
//! what if it is url or port
3030
async function addScript(
3131
document: DfContentMap,
3232
env_content: string,
3333
static_content: string,
3434
dockerfile_present: string,
35+
volume_needed:string,
3536
stack: string,
3637
port: string,
3738
build_cmds: string,
@@ -40,7 +41,9 @@ async function addScript(
4041
const resource = shellEscape(document.resource, "resource");
4142
const safePort = shellEscape(port, "port");
4243
const memLimit = shellEscape(MEMORY_LIMIT || "512m", "MEMORY_LIMIT");
43-
44+
volume_needed=(volume_needed=="Yes").toString();
45+
const volumeNeeded=shellEscape(volume_needed,"false");
46+
4447
if (document.resource_type === "URL") {
4548
await safeExec(
4649
`bash -c "echo 'bash ../../src/backend/shell_scripts/automate.sh -u ${resource} ${subdomain}' > /hostpipe/pipe"`,
@@ -52,19 +55,19 @@ async function addScript(
5255
} else if (document.resource_type === "GITHUB" && static_content == "Yes") {
5356
await Deno.writeTextFile(`/hostpipe/.env`, env_content || "");
5457
await safeExec(
55-
`bash -c "echo 'bash ../../src/backend/shell_scripts/container.sh -s ${subdomain} ${resource} 80 ${memLimit}' > /hostpipe/pipe"`,
58+
`bash -c "echo 'bash ../../src/backend/shell_scripts/container.sh -s ${subdomain} ${resource} 80 ${memLimit} ${volumeNeeded}' > /hostpipe/pipe"`,
5659
);
5760
} else if (document.resource_type === "GITHUB" && static_content == "No") {
5861
if (dockerfile_present === 'No') {
5962
await Deno.writeTextFile(`/hostpipe/Dockerfile`, dockerize(stack || "", safePort, build_cmds || ""));
6063
await Deno.writeTextFile(`/hostpipe/.dockerignore`, dockerignore(stack || ""));
6164
await Deno.writeTextFile(`/hostpipe/.env`, env_content || "");
6265
await safeExec(
63-
`bash -c "echo 'bash ../../src/backend/shell_scripts/container.sh -g ${subdomain} ${resource} ${safePort} ${memLimit}' > /hostpipe/pipe"`,
66+
`bash -c "echo 'bash ../../src/backend/shell_scripts/container.sh -g ${subdomain} ${resource} ${safePort} ${memLimit} ${volumeNeeded}' > /hostpipe/pipe"`,
6467
);
6568
} else if (dockerfile_present === 'Yes') {
6669
await safeExec(
67-
`bash -c "echo 'bash ../../src/backend/shell_scripts/container.sh -d ${subdomain} ${resource} ${safePort} ${memLimit}' > /hostpipe/pipe"`,
70+
`bash -c "echo 'bash ../../src/backend/shell_scripts/container.sh -d ${subdomain} ${resource} ${safePort} ${memLimit} ${volumeNeeded}' > /hostpipe/pipe"`,
6871
);
6972
}
7073
}

src/backend/shell_scripts/container.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ name=$2
55
resource=$3
66
exp_port=$4
77
max_mem=$5
8+
enable_voume=$6
89

910
available_ports=()
10-
11+
STORAGE_ROOT="/mnt/storage"
12+
PROJECT_STORAGE="$STORAGE_ROOT/$name"
1113
for ((port=PORT_MIN; port<=PORT_MAX; port++)); do
1214
if ! ss -ln src :$port | grep -q "\<$port\>"; then
1315
available_ports+=($port)
@@ -30,13 +32,33 @@ elif [ $flag = "-s" ]; then
3032
COPY . /usr/share/nginx/html
3133
" > Dockerfile
3234
fi
33-
35+
if [ "$enable_volume" = "true" ]; then
36+
echo "Creating persistent storage at $PROJECT_STORAGE"
37+
sudo mkdir -p $PROJECT_STORAGE
38+
sudo chmod 777 $PROJECT_STORAGE # tighten later
39+
fi
3440
sudo docker build -t $name .
3541

3642
# Safety net: If the frontend sends double requests from spam-clicking, forcefully remove any zombie container holding the name
3743
sudo docker rm -f $name 2>/dev/null || true
3844

39-
sudo docker run --memory=$max_mem --name=$name -d -p ${available_ports[$AVAILABLE]}:$exp_port $name
45+
if [ "$enable_volume" = "true" ]; then
46+
sudo docker run \
47+
--memory=$max_mem \
48+
--name=$name \
49+
-d \
50+
-p ${available_ports[$AVAILABLE]}:$exp_port \
51+
-v $PROJECT_STORAGE:/app/data \
52+
-e DATA_DIR=/app/data \
53+
$name
54+
else
55+
sudo docker run \
56+
--memory=$max_mem \
57+
--name=$name \
58+
-d \
59+
-p ${available_ports[$AVAILABLE]}:$exp_port \
60+
$name
61+
fi
4062
cd ..
4163
sudo rm -rf $name
4264
sudo rm Dockerfile

src/frontend/src/components/modal.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ const domain = import.meta.env.VITE_APP_DOMAIN
3535
<option v-for="option in stacks" :key="option">{{ option }}</option>
3636
</select>
3737
</div>
38+
<div class="volume-needed">
39+
<label for="volume">Do you need persistent storage (Volume)?</label><br>
40+
<input name="radio" type="radio" value="Yes" v-model="volume_needed"> Yes
41+
<input name="radio" type="radio" value="No" v-model="volume_needed"> No
42+
</div>
3843
<p>Port:<br><input class="input-field" v-model="port" /></p>
3944
<div v-if="dockerfile_present === 'No'" class="dockerfile-section">
4045
<p>Build Commands:<br><textarea class="textarea-field" cols="50" rows="10" v-model="build_cmds"></textarea></p>
@@ -67,6 +72,7 @@ export default {
6772
env_content: 'key1 = value1', // Default prompt text
6873
static_content: 'No',
6974
dockerfile_present :'No',
75+
volume_needed: 'No',
7076
port: '',
7177
stack: '',
7278
build_cmds: '',
@@ -78,7 +84,7 @@ export default {
7884
methods: {
7985
submitForm() {
8086
console.log(this.subdomain, this.resource_type, this.resource);
81-
create(this.subdomain, this.resource_type, this.resource, this.env_content, this.static_content,this.dockerfile_present,this.port, this.stack, this.build_cmds, this.enable_ci)
87+
create(this.subdomain, this.resource_type, this.resource, this.env_content, this.static_content,this.dockerfile_present, this.volume_needed, this.port, this.stack, this.build_cmds,this.enable_ci)
8288
.then((res) => {
8389
console.log(res);
8490
if (res === 'Submitted') {

src/frontend/src/utils/create.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export async function create(
6161
env_content: string,
6262
static_content: string,
6363
dockerfile_present:string,
64+
volume_needed:string,
6465
port: string,
6566
stack: string,
6667
build_cmds: string,
@@ -89,6 +90,7 @@ export async function create(
8990
"env_content": env_content,
9091
"static_content": static_content,
9192
"dockerfile_present":dockerfile_present,
93+
"volume_needed":volume_needed,
9294
"port": port,
9395
"build_cmds": build_cmds,
9496
"stack": stack,

0 commit comments

Comments
 (0)