-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstarter.py
More file actions
83 lines (68 loc) · 2.23 KB
/
Copy pathstarter.py
File metadata and controls
83 lines (68 loc) · 2.23 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright (C) 2025 EXANTE
from core.configuration.starter import StarterConfig
from core.logger import Logger
from core.utils.script import Script
CONFIG = StarterConfig('cranberrypy.ini')
LOGGER = Logger(config=CONFIG, name=__name__)
LOGGER.setup_logger()
DOCKERFILE_PATH = 'Dockerfile'
def create_dockerfile():
installer_command = 'pip install'
if CONFIG.package_installer == 'uv':
installer_command = 'uv pip install --system'
docker_file_content = f'''
FROM python:{CONFIG.python_version}
WORKDIR /app
COPY . .
RUN pip install --upgrade pip
{'RUN pip install uv' if CONFIG.package_installer == 'uv' else ''}
RUN {installer_command} -r requirements.txt
RUN {installer_command} -r ./temp/requirements.txt {CONFIG.install_kwargs}
CMD ["python", "main.py"]
'''
with open(DOCKERFILE_PATH, 'w') as file:
file.write(docker_file_content)
LOGGER.info("Dockerfile created")
def start():
script = Script(logger=LOGGER)
script.add(create_dockerfile)
script.add(
command=f"cp {CONFIG.requirements_path} ./temp/requirements.txt",
description="copy project requirements.txt"
)
script.add(
command="docker build -t temporary-image .",
description="docker build image",
)
script.add(
command=(
"docker run --name temporary-container"
f" --mount type=bind,src={CONFIG.root_directory_path},dst={CONFIG.root_image_path}"
" --mount type=bind,src=./temp/,dst=/app/temp/ temporary-image"
),
description="docker run container",
exception_break=False
)
script.add(
command="docker rm temporary-container",
description="docker remove container",
exception_break=False
)
script.add(
command="docker rmi temporary-image",
description="docker remove image",
exception_break=False
)
script.add(
command=f"rm {DOCKERFILE_PATH}",
description="remove Dockerfile",
exception_break=False
)
script.add(
command="rm ./temp/requirements.txt",
description="remove project requirements.txt",
exception_break=False
)
script.run()
if __name__ == "__main__":
start()