-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimages.py
More file actions
286 lines (260 loc) · 10.8 KB
/
Copy pathimages.py
File metadata and controls
286 lines (260 loc) · 10.8 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
"""
Docker image definitions for DevBox Launcher.
This module provides centralized image definitions with inheritance patterns
to eliminate code duplication and standardize base configurations.
Author: GoodieHART
"""
import modal
import os
from config import CORE_DEV_PACKAGES, EXTENDED_DEV_PACKAGES, LLAMACPP_VERSION, DOWNLOAD_APT_PACKAGES, DOWNLOAD_PIP_PACKAGES
# Absolute path to the directory containing this file (for add_local_file references)
_IMAGES_DIR = os.path.dirname(os.path.abspath(__file__))
def get_ssh_setup_commands():
"""
Get standardized SSH setup commands for all DevBox images.
Returns:
list: SSH configuration commands
"""
return [
"mkdir -p /root/.ssh",
"chmod 700 /root/.ssh",
"touch /root/.ssh/authorized_keys",
"chmod 600 /root/.ssh/authorized_keys",
"mkdir -p /var/run/sshd",
# Configure SSH to allow key-based auth and disable password auth
"echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config",
"echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config",
"echo 'PermitRootLogin prohibit-password' >> /etc/ssh/sshd_config",
"echo 'AuthorizedKeysFile .ssh/authorized_keys' >> /etc/ssh/sshd_config",
]
def create_base_devbox_image(python_version="3.10"):
"""
Create base DevBox image with common development tools and SSH setup.
Args:
python_version: Python version to install (default: "3.10")
Returns:
modal.Image: Base DevBox image with SSH and core tools
"""
return (
modal.Image.debian_slim(python_version=python_version)
.apt_install(*CORE_DEV_PACKAGES, *EXTENDED_DEV_PACKAGES, *DOWNLOAD_APT_PACKAGES)
.pip_install(*DOWNLOAD_PIP_PACKAGES)
.run_commands(
*get_ssh_setup_commands(),
# Install Starship prompt (pinned version)
"curl -sSLO https://github.com/starship/starship/releases/download/v1.22.1/starship-x86_64-unknown-linux-gnu.tar.gz",
"tar -xzf starship-x86_64-unknown-linux-gnu.tar.gz -C /usr/local/bin/",
"rm starship-x86_64-unknown-linux-gnu.tar.gz",
# Create starship init script (interactive only)
"printf '%s\\n' 'if command -v starship &> /dev/null && [ -t 0 ]; then' ' eval \"$(starship init bash)\"' 'fi' > /etc/profile.d/starship.sh",
# Create devbox-banner display script
"cat > /etc/profile.d/devbox-banner.sh << 'BANNER_EOF'\n"
"if [ -t 0 ] && [ -f /etc/devbox-banner ]; then\n"
" clear\n"
" cat /etc/devbox-banner\n"
" [ -d /data ] && cd /data\n"
"fi\n"
"BANNER_EOF",
)
)
def create_base_minimal_image(python_version="3.10"):
"""
Create minimal base image with SSH setup only.
Args:
python_version: Python version to install (default: "3.10")
Returns:
modal.Image: Minimal base image with SSH only
"""
return (
modal.Image.debian_slim(python_version=python_version)
.apt_install(*CORE_DEV_PACKAGES, *DOWNLOAD_APT_PACKAGES)
.pip_install(*DOWNLOAD_PIP_PACKAGES)
.run_commands(
*get_ssh_setup_commands(),
# Install Starship prompt (pinned version)
"curl -sSLO https://github.com/starship/starship/releases/download/v1.22.1/starship-x86_64-unknown-linux-gnu.tar.gz",
"tar -xzf starship-x86_64-unknown-linux-gnu.tar.gz -C /usr/local/bin/",
"rm starship-x86_64-unknown-linux-gnu.tar.gz",
# Create starship init script (interactive only)
"printf '%s\\n' 'if command -v starship &> /dev/null && [ -t 0 ]; then' ' eval \"$(starship init bash)\"' 'fi' > /etc/profile.d/starship.sh",
# Create devbox-banner display script
"cat > /etc/profile.d/devbox-banner.sh << 'BANNER_EOF'\n"
"if [ -t 0 ] && [ -f /etc/devbox-banner ]; then\n"
" clear\n"
" cat /etc/devbox-banner\n"
" [ -d /data ] && cd /data\n"
"fi\n"
"BANNER_EOF",
)
)
# Standard DevBox images using inheritance
standard_devbox_image = (
create_base_devbox_image()
.add_local_python_source(
"images", "shared_runtime", "utils", "config",
"persistence_utils", "backup_utils", "quotes_loader"
)
.add_local_file(os.path.join(_IMAGES_DIR, "quotes.json"), "/etc/quotes.json")
)
cuda_devbox_image = (
modal.Image.from_registry(
"nvidia/cuda:12.1.1-devel-ubuntu22.04",
add_python="3.11"
)
.apt_install(
*CORE_DEV_PACKAGES,
"nano",
"libcudnn9-cuda-12",
"libcudnn9-dev-cuda-12",
)
.run_commands(*get_ssh_setup_commands())
.pip_install(*DOWNLOAD_PIP_PACKAGES)
.add_local_python_source(
"images", "shared_runtime", "utils", "config",
"persistence_utils", "backup_utils", "quotes_loader"
)
.add_local_file(os.path.join(_IMAGES_DIR, "quotes.json"), "/etc/quotes.json")
)
doc_processing_image = (
create_base_minimal_image()
.apt_install("pandoc", "texlive-full")
.add_local_python_source(
"images", "shared_runtime", "utils", "config",
"persistence_utils", "backup_utils", "quotes_loader"
)
.add_local_file(os.path.join(_IMAGES_DIR, "quotes.json"), "/etc/quotes.json")
)
assisted_coding_image = (
create_base_minimal_image()
.run_commands(
# Install Node.js 20.x
"curl -fsSL https://deb.nodesource.com/setup_20.x | bash -",
"apt-get install -y nodejs",
# Install OpenCode and Gemini CLI
"npm install -g @google/gemini-cli",
"curl -fsSL https://opencode.ai/install | bash",
*get_ssh_setup_commands()
)
.add_local_python_source(
"images", "shared_runtime", "utils", "config",
"persistence_utils", "backup_utils", "quotes_loader"
)
.add_local_file(os.path.join(_IMAGES_DIR, "quotes.json"), "/etc/quotes.json")
)
llm_playroom_image = (
create_base_minimal_image()
.apt_install(
"pciutils",
"lshw",
"zstd",
)
.run_commands(
# Install Ollama
"curl -fsSL https://ollama.com/install.sh | bash",
*get_ssh_setup_commands()
)
.add_local_python_source(
"images", "shared_runtime", "utils", "config",
"persistence_utils", "backup_utils", "quotes_loader"
)
.add_local_file(os.path.join(_IMAGES_DIR, "quotes.json"), "/etc/quotes.json")
)
llamacpp_cpu_image = (
create_base_minimal_image()
.apt_install(
"libssl3",
"libcurl4",
"zlib1g",
)
.pip_install(
"exa-py",
"openai",
"httpx",
"hf",
"huggingface_hub",
"hf_transfer",
)
.run_commands(
# Download and extract prebuilt llama.cpp binaries
f"curl -L -o /tmp/llama.tar.gz https://github.com/ggml-org/llama.cpp/releases/download/{LLAMACPP_VERSION}/llama-{LLAMACPP_VERSION}-bin-ubuntu-x64.tar.gz",
"mkdir -p /opt/llama.cpp",
"tar -xzf /tmp/llama.tar.gz -C /opt/llama.cpp --strip-components=1",
"rm /tmp/llama.tar.gz",
# symlinks for easy access
"ln -sf /opt/llama.cpp/llama-cli /usr/local/bin/llama-cli",
"ln -sf /opt/llama.cpp/llama-server /usr/local/bin/llama-server",
"ln -sf /opt/llama.cpp/llama-bench /usr/local/bin/llama-bench",
"ln -sf /opt/llama.cpp/llama-mtmd-cli /usr/local/bin/llama-mtmd-cli",
*get_ssh_setup_commands()
)
.add_local_python_source(
"images", "shared_runtime", "utils", "config",
"persistence_utils", "backup_utils", "exa_helper", "exa_proxy", "quotes_loader"
)
.add_local_file(os.path.join(_IMAGES_DIR, "quotes.json"), "/etc/quotes.json")
)
rdp_devbox_image = (
create_base_devbox_image()
.apt_install(
"xrdp",
"xfce4",
"xfce4-goodies",
"xorgxrdp",
"dbus-x11",
"xorg",
"tightvncserver",
)
.run_commands(
"mkdir -p /var/run/xrdp",
"chmod 755 /etc/xrdp",
# Create XFCE environment wrapper for proper XDG setup
"echo '#!/bin/bash' > /usr/local/bin/startxfce4-wrapper",
"echo '# XFCE RDP Wrapper with proper environment' >> /usr/local/bin/startxfce4-wrapper",
"echo '' >> /usr/local/bin/startxfce4-wrapper",
"echo 'export XDG_CONFIG_DIRS=/etc/xdg' >> /usr/local/bin/startxfce4-wrapper",
"echo 'export XDG_DATA_DIRS=/usr/local/share:/usr/share' >> /usr/local/bin/startxfce4-wrapper",
"echo 'export XDG_RUNTIME_DIR=/tmp/xdg-runtime' >> /usr/local/bin/startxfce4-wrapper",
"echo '' >> /usr/local/bin/startxfce4-wrapper",
"echo '# Ensure runtime directory exists' >> /usr/local/bin/startxfce4-wrapper",
"echo 'mkdir -p /tmp/xdg-runtime' >> /usr/local/bin/startxfce4-wrapper",
"echo 'chmod 700 /tmp/xdg-runtime' >> /usr/local/bin/startxfce4-wrapper",
"echo '' >> /usr/local/bin/startxfce4-wrapper",
"echo '# Start XFCE with proper environment' >> /usr/local/bin/startxfce4-wrapper",
"echo 'exec startxfce4' >> /usr/local/bin/startxfce4-wrapper",
"chmod +x /usr/local/bin/startxfce4-wrapper",
# Configure XFCE session using wrapper
"printf '#!/bin/sh\\n/usr/local/bin/startxfce4-wrapper\\n' > /etc/skel/.xsession",
"chmod +x /etc/skel/.xsession",
# Create basic XFCE config directory structure
"mkdir -p /etc/skel/.config/xfce4",
"mkdir -p /etc/skel/.cache/sessions",
# Set root password for RDP (needed for desktop)
'echo "root:devbox123" | chpasswd',
*get_ssh_setup_commands()
)
.add_local_python_source(
"images", "shared_runtime", "utils", "config",
"persistence_utils", "backup_utils"
)
)
forensic_analysis_image = (
create_base_minimal_image()
.pip_install(*DOWNLOAD_PIP_PACKAGES, "volatility3")
.run_commands(
"mkdir -p /opt/forensic_analysis",
"mkdir -p /opt/forensic_analysis/volatility3/symbols",
"curl https://downloads.volatilityfoundation.org/volatility3/symbols/windows.zip -o /tmp/windows.zip",
"curl https://downloads.volatilityfoundation.org/volatility3/symbols/linux.zip -o /tmp/linux.zip",
"curl https://downloads.volatilityfoundation.org/volatility3/symbols/mac.zip -o /tmp/mac.zip",
"unzip /tmp/windows.zip -d /opt/forensic_analysis/volatility3/symbols",
"unzip /tmp/linux.zip -d /opt/forensic_analysis/volatility3/symbols",
"unzip /tmp/mac.zip -d /opt/forensic_analysis/volatility3/symbols",
# symbols ought to be moved to volatility's execution directory
*get_ssh_setup_commands()
)
.add_local_python_source(
"images", "shared_runtime", "utils", "config",
"persistence_utils", "backup_utils", "quotes_loader"
)
.add_local_file(os.path.join(_IMAGES_DIR, "quotes.json"), "/etc/quotes.json")
)