-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuild.py
67 lines (54 loc) · 2.4 KB
/
Build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
from constructor.constructor import Constructor
class DockerBuilder:
def __init__(self):
self.Constructor = Constructor()
self.conf = self.Constructor.conf
self.docker_file_path = os.path.join(os.path.dirname(__file__), "Dockerfile")
self.docker_builder_path = os.path.join(os.path.dirname(__file__), "DockerBuilder.py")
self.run_file_path = os.path.join(os.path.dirname(__file__), "start.sh")
def exposePort(self) -> str:
expose = ""
for port in self.conf["PORT_MAPPING"]:
expose += f"EXPOSE {port[0]}\n"
return expose
def exposeExtraPort(self) -> str:
expose = ""
for port in self.conf["EXTRA_PORT"]:
expose += f"EXPOSE {port[0]}\n"
return expose
def buildDockerfile(self) -> None:
text = "FROM debian:latest\nLABEL Creator: "
text += r"https://github.com/LittleAtariXE"
text += "\nWORKDIR /app\n"
text += "COPY . /app\n"
text += "RUN apt update && \\\n\tapt install -y python3 python3-flask python3-requests python3-socks tor\n"
text += "# Control Port:\n"
text += f"EXPOSE {self.conf['CONTROL_PORT'][0]}\n"
text += "# TOR Socks:\n"
text += self.exposePort()
text += "# Extra Opening Ports\n"
text += self.exposeExtraPort()
text += 'CMD ["python3", "app.py"]\n'
with open(self.docker_file_path, "w") as f:
f.write(text)
def buildDockerImage(self) -> None:
os.system(f"docker build -t {self.conf['IMAGE_NAME'].lower()} .")
def buildDockerStartSh(self) -> None:
text = "#!/bin/bash\n"
ports = f"-p {self.conf['CONTROL_PORT'][0]}:{self.conf['CONTROL_PORT'][1]}"
for port in self.conf["PORT_MAPPING"]:
ports += f" -p {port[0]}:{port[1]}"
for port in self.conf["EXTRA_PORT"]:
ports += f" -p {port[0]}:{port[1]}"
text += f"docker run --name {self.conf['CONTAINER_NAME']} {ports} {self.conf['IMAGE_NAME'].lower()}\n"
with open(os.path.join(os.getcwd(), "start_portal.sh"), "w") as f:
f.write(text)
print("Docker Start File Ready")
if __name__ == "__main__":
builder = DockerBuilder()
builder.buildDockerfile()
builder.buildDockerImage()
builder.buildDockerStartSh()
print("\nDONE")
print("\n\nNow you can run images: 'sh start_portal.sh")